1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mpi.h"
#include <stdio.h>
#include "mpitest.h"
/*
static char MTEST_Descrip[] = "Use Spawn to create an intercomm, then create a new intercomm between processes from mixed worlds.";
*/
/*
* This test is a regression test for ticket#114 based on a bug reported by Brad
* Penoff. The specific bug only occurred when MPI_Intercomm_create was called
* with a local communicator argument that contained one or more processes from
* a different MPI_COMM_WORLD.
*/
int main(int argc, char *argv[])
{
int errs = 0;
int wrank, wsize, mrank, msize, inter_rank;
int np = 2;
int errcodes[2];
int rrank = -1;
MPI_Comm parentcomm, intercomm, intercomm2, even_odd_comm, merged_world;
int can_spawn;
MTest_Init(&argc, &argv);
errs += MTestSpawnPossible(&can_spawn);
if (can_spawn) {
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
if (wsize != 2) {
printf("world size != 2, this test will not work correctly\n");
errs++;
}
MPI_Comm_get_parent(&parentcomm);
if (parentcomm == MPI_COMM_NULL) {
MPI_Comm_spawn((char *) "./spaiccreate2", MPI_ARGV_NULL, np,
MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, errcodes);
} else {
intercomm = parentcomm;
}
MPI_Intercomm_merge(intercomm, (parentcomm == MPI_COMM_NULL ? 0 : 1), &merged_world);
MPI_Comm_rank(merged_world, &mrank);
MPI_Comm_size(merged_world, &msize);
MPI_Comm_split(merged_world, mrank % 2, wrank, &even_odd_comm);
MPI_Intercomm_create(even_odd_comm, 0, merged_world, (mrank + 1) % 2, 123, &intercomm2);
MPI_Comm_rank(intercomm2, &inter_rank);
/* odds receive from evens */
MPI_Sendrecv(&inter_rank, 1, MPI_INT, inter_rank, 456,
&rrank, 1, MPI_INT, inter_rank, 456, intercomm2, MPI_STATUS_IGNORE);
if (rrank != inter_rank) {
printf("Received %d from %d; expected %d\n", rrank, inter_rank, inter_rank);
errs++;
}
MPI_Barrier(intercomm2);
MPI_Comm_free(&intercomm);
MPI_Comm_free(&intercomm2);
MPI_Comm_free(&merged_world);
MPI_Comm_free(&even_odd_comm);
/* Note that the MTest_Finalize get errs only over COMM_WORLD */
/* Note also that both the parent and child will generate "No Errors"
* if both call MTest_Finalize */
if (parentcomm == MPI_COMM_NULL) {
MTest_Finalize(errs);
} else {
MPI_Finalize();
}
} else {
MTest_Finalize(errs);
}
return MTestReturnValue(errs);
}
|