2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar 17 2000 */
3 /* no-error.c -- do some MPI calls without any errors */
13 main (int argc, char **argv)
17 char processor_name[128];
23 MPI_Group world_group, dgroup;
25 int dims[TWOD], periods[TWOD], remain_dims[TWOD];
29 MPI_Init (&argc, &argv);
30 MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
31 MPI_Comm_rank (MPI_COMM_WORLD, &rank);
32 MPI_Get_processor_name (processor_name, &namelen);
33 printf ("(%d) is alive on %s\n", rank, processor_name);
36 MPI_Barrier (MPI_COMM_WORLD);
39 printf ("not enough tasks\n");
42 /* need to make cartesian communicator temporarily... */
43 /* create a 2 X nprocs/2 torus topology, allow reordering */
46 periods[0] = periods[1] = 1;
47 MPI_Cart_create (MPI_COMM_WORLD, TWOD, dims, periods, 1, &temp);
49 if (temp != MPI_COMM_NULL) {
50 /* create 2 1 X nprocs/2 topologies... */
53 MPI_Cart_sub (temp, remain_dims, &comm);
54 /* free up temporarily created cartesian communicator... */
55 MPI_Comm_free (&temp);
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 MPI_Barrier (MPI_COMM_WORLD);
96 printf ("(%d) Finished normally\n", rank);