2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar 17 2000 */
3 /* no-error.c -- do some MPI calls without any errors */
11 main (int argc, char **argv)
15 char processor_name[128];
21 MPI_Group world_group, dgroup;
23 int i, drank, dnprocs, newsize;
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 MPI_Comm_group (MPI_COMM_WORLD, &world_group);
41 newsize = (nprocs/2) + 1;
44 granks = (int *) malloc (sizeof(int) * (newsize));
45 for (i = 0; i < newsize; i++)
47 MPI_Group_incl (world_group, newsize, granks, &dgroup);
48 MPI_Comm_create (MPI_COMM_WORLD, dgroup, &comm);
49 MPI_Group_free (&world_group);
50 MPI_Group_free (&dgroup);
53 if (comm != MPI_COMM_NULL) {
54 MPI_Comm_size (comm, &dnprocs);
55 MPI_Comm_rank (comm, &drank);
59 memset (buf0, 0, buf_size*sizeof(int));
61 MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
63 MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
65 else if (drank == 1) {
66 memset (buf1, 1, buf_size*sizeof(int));
68 MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
70 MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
74 printf ("(%d) Derived communicator too small (size = %d)\n",
78 MPI_Comm_free (&comm);
81 printf ("(%d) Got MPI_COMM_NULL\n", rank);
85 MPI_Barrier (MPI_COMM_WORLD);
88 printf ("(%d) Finished normally\n", rank);