|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2007 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* This program tests that MPI_Comm_create applies to intercommunicators;
|
|
Packit Service |
c5cf8c |
* this is an extension added in MPI-2
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
int size, isLeft, wrank;
|
|
Packit Service |
c5cf8c |
MPI_Comm intercomm, newcomm;
|
|
Packit Service |
c5cf8c |
MPI_Group oldgroup, newgroup;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit Service |
c5cf8c |
if (size < 4) {
|
|
Packit Service |
c5cf8c |
printf("This test requires at least 4 processes\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
|
|
Packit Service |
c5cf8c |
int ranks[10], nranks, result;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (intercomm == MPI_COMM_NULL)
|
|
Packit Service |
c5cf8c |
continue;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_group(intercomm, &oldgroup);
|
|
Packit Service |
c5cf8c |
ranks[0] = 0;
|
|
Packit Service |
c5cf8c |
nranks = 1;
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(1, "Creating a new intercomm 0-0\n");
|
|
Packit Service |
c5cf8c |
MPI_Group_incl(oldgroup, nranks, ranks, &newgroup);
|
|
Packit Service |
c5cf8c |
MPI_Comm_create(intercomm, newgroup, &newcomm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Make sure that the new communicator has the appropriate pieces */
|
|
Packit Service |
c5cf8c |
if (newcomm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
int new_rsize, new_size, flag, commok = 1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_name(newcomm, (char *) "Single rank in each group");
|
|
Packit Service |
c5cf8c |
MPI_Comm_test_inter(intercomm, &flag;;
|
|
Packit Service |
c5cf8c |
if (!flag) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("[%d] Output communicator is not an intercomm\n", wrank);
|
|
Packit Service |
c5cf8c |
commok = 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_remote_size(newcomm, &new_rsize);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(newcomm, &new_size);
|
|
Packit Service |
c5cf8c |
/* The new communicator has 1 process in each group */
|
|
Packit Service |
c5cf8c |
if (new_rsize != 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("[%d] Remote size is %d, should be one\n", wrank, new_rsize);
|
|
Packit Service |
c5cf8c |
commok = 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (new_size != 1) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("[%d] Local size is %d, should be one\n", wrank, new_size);
|
|
Packit Service |
c5cf8c |
commok = 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* ... more to do */
|
|
Packit Service |
c5cf8c |
if (commok) {
|
|
Packit Service |
c5cf8c |
errs += MTestTestComm(newcomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Group_free(&newgroup);
|
|
Packit Service |
c5cf8c |
if (newcomm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&newcomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Now, do a sort of dup, using the original group */
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(1, "Creating a new intercomm (manual dup)\n");
|
|
Packit Service |
c5cf8c |
MPI_Comm_create(intercomm, oldgroup, &newcomm);
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_name(newcomm, (char *) "Dup of original");
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(1, "Creating a new intercomm (manual dup (done))\n");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_compare(intercomm, newcomm, &result);
|
|
Packit Service |
c5cf8c |
MTestPrintfMsg(1, "Result of comm/intercomm compare is %d\n", result);
|
|
Packit Service |
c5cf8c |
if (result != MPI_CONGRUENT) {
|
|
Packit Service |
c5cf8c |
const char *rname = 0;
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
switch (result) {
|
|
Packit Service |
c5cf8c |
case MPI_IDENT:
|
|
Packit Service |
c5cf8c |
rname = "IDENT";
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
case MPI_CONGRUENT:
|
|
Packit Service |
c5cf8c |
rname = "CONGRUENT";
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
case MPI_SIMILAR:
|
|
Packit Service |
c5cf8c |
rname = "SIMILAR";
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
case MPI_UNEQUAL:
|
|
Packit Service |
c5cf8c |
rname = "UNEQUAL";
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
printf("[%d] Expected MPI_CONGRUENT but saw %d (%s)", wrank, result, rname);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
/* Try to communication between each member of intercomm */
|
|
Packit Service |
c5cf8c |
errs += MTestTestComm(newcomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (newcomm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&newcomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* test that an empty group in either side of the intercomm results in
|
|
Packit Service |
c5cf8c |
* MPI_COMM_NULL for all members of the comm */
|
|
Packit Service |
c5cf8c |
if (isLeft) {
|
|
Packit Service |
c5cf8c |
/* left side reuses oldgroup, our local group in intercomm */
|
|
Packit Service |
c5cf8c |
MPI_Comm_create(intercomm, oldgroup, &newcomm);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
/* right side passes MPI_GROUP_EMPTY */
|
|
Packit Service |
c5cf8c |
MPI_Comm_create(intercomm, MPI_GROUP_EMPTY, &newcomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (newcomm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
printf("[%d] expected MPI_COMM_NULL, but got a different communicator\n", wrank);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (newcomm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&newcomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Group_free(&oldgroup);
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&intercomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|