2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar 17 2000 */
3 /* no-error.c -- do some MPI calls without any errors */
10 #define INTERCOMM_CREATE_TAG 666
13 main (int argc, char **argv)
17 char processor_name[128];
22 MPI_Comm comm, temp, intercomm;
23 int drank, dnprocs, rleader;
26 MPI_Init (&argc, &argv);
27 MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
28 MPI_Comm_rank (MPI_COMM_WORLD, &rank);
29 MPI_Get_processor_name (processor_name, &namelen);
30 printf ("(%d) is alive on %s\n", rank, processor_name);
33 MPI_Barrier (MPI_COMM_WORLD);
36 printf ("not enough tasks\n");
39 /* need to make split communicator temporarily... */
40 MPI_Comm_split (MPI_COMM_WORLD, rank % 2, nprocs - rank, &temp);
42 if (temp != MPI_COMM_NULL) {
43 /* create an intercommunicator temporarily so can merge it... */
44 rleader = ((rank + nprocs) % 2) ? nprocs - 2 : nprocs - 1;
45 MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD, rleader,
46 INTERCOMM_CREATE_TAG, &intercomm);
48 MPI_Comm_free (&temp);
50 if (intercomm == MPI_COMM_NULL) {
51 printf ("(%d) MPI_Intercomm_Create returned MPI_COMM_NULL\n", rank);
52 printf ("(%d) Aborting...\n", rank);
53 MPI_Abort (MPI_COMM_WORLD, 666);
57 MPI_Intercomm_merge (intercomm, rank % 2, &comm);
59 MPI_Comm_free (&intercomm);
61 if (comm != MPI_COMM_NULL) {
62 MPI_Comm_size (comm, &dnprocs);
63 MPI_Comm_rank (comm, &drank);
67 memset (buf0, 0, buf_size);
69 MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
71 MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
73 else if (drank == 1) {
74 memset (buf1, 1, buf_size);
76 MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
78 MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
82 printf ("(%d) Derived communicator too small (size = %d)\n",
86 MPI_Comm_free (&comm);
89 printf ("(%d) Got MPI_COMM_NULL\n", rank);
93 printf ("(%d) MPI_Comm_split got MPI_COMM_NULL\n", rank);
97 MPI_Barrier (MPI_COMM_WORLD);
100 printf ("(%d) Finished normally\n", rank);