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 temp, intercomm, intercomm2, comm, comm2;
24 int drank, dnprocs, rleader;
27 MPI_Init (&argc, &argv);
28 MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
29 MPI_Comm_rank (MPI_COMM_WORLD, &rank);
30 MPI_Get_processor_name (processor_name, &namelen);
31 printf ("(%d) is alive on %s\n", rank, processor_name);
34 MPI_Barrier (MPI_COMM_WORLD);
37 printf ("not enough tasks\n");
40 /* need to make split communicator temporarily... */
41 MPI_Comm_split (MPI_COMM_WORLD, rank % 2, nprocs - rank, &temp);
43 if (temp != MPI_COMM_NULL) {
44 /* create an intercommunicator temporarily so can merge it... */
45 rleader = ((rank + nprocs) % 2) ? nprocs - 2 : nprocs - 1;
46 MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD, rleader,
47 INTERCOMM_CREATE_TAG, &intercomm);
48 MPI_Comm_free (&temp);
50 if (intercomm != MPI_COMM_NULL) {
51 /* need to make a different split communicator temporarily... */
52 MPI_Comm_split (MPI_COMM_WORLD,
53 rank < nprocs/2, nprocs - rank, &temp);
55 if (temp != MPI_COMM_NULL) {
56 /* create another intercommunicator temporarily to merge... */
57 rleader = (rank < nprocs/2) ? nprocs - 1 : nprocs/2 - 1;
58 MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD, rleader,
59 INTERCOMM_CREATE_TAG, &intercomm2);
60 MPI_Comm_free (&temp);
62 if (intercomm2 != MPI_COMM_NULL) {
63 if (rank < nprocs/2) {
64 MPI_Intercomm_merge (intercomm2, rank < nprocs/2, &comm2);
65 MPI_Comm_free (&intercomm2);
66 MPI_Intercomm_merge (intercomm, rank % 2, &comm);
67 MPI_Comm_free (&intercomm);
70 MPI_Intercomm_merge (intercomm, rank % 2, &comm);
71 MPI_Comm_free (&intercomm);
72 MPI_Intercomm_merge (intercomm2, rank < nprocs/2, &comm2);
73 MPI_Comm_free (&intercomm2);
76 if ((comm != MPI_COMM_NULL) && (comm2 != MPI_COMM_NULL)) {
77 MPI_Comm_size (comm, &dnprocs);
78 MPI_Comm_rank (comm, &drank);
82 memset (buf1, 1, buf_size*sizeof(int));
84 MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
86 MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
88 else if (drank == 0) {
89 memset (buf0, 0, buf_size*sizeof(int));
91 MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
93 MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
97 printf ("(%d) comm too small\n", rank);
100 MPI_Comm_size (comm2, &dnprocs);
101 MPI_Comm_rank (comm2, &drank);
105 memset (buf1, 1, buf_size*sizeof(int));
107 MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm2, &status);
109 MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm2);
111 else if (drank == 0) {
112 memset (buf0, 0, buf_size*sizeof(int));
114 MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm2);
116 MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm2, &status);
120 printf ("(%d) comm2 too small\n", rank);
124 printf ("(%d) Got MPI_COMM_NULL\n", rank);
128 printf ("(%d) Got MPI_COMM_NULL for intercomm2\n", rank);
132 printf ("(%d) Second MPI_Comm_split got MPI_COMM_NULL\n", rank);
136 printf ("(%d) Got MPI_COMM_NULL for intercomm1\n", rank);
140 printf ("(%d) First MPI_Comm_split got MPI_COMM_NULL\n", rank);
144 MPI_Barrier (MPI_COMM_WORLD);
147 printf ("(%d) Finished normally\n", rank);