Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reactivate an umpire test, once disabled in 56fefe1bf81ca.
[simgrid.git] / teshsuite / smpi / isp / umpire / basic-deadlock-comm_create.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar  17 2000 */
3 /* no-error.c -- do some MPI calls without any errors */
4
5 #include <stdio.h>
6 #include "mpi.h"
7
8 #define buf_size 128
9
10 int
11 main (int argc, char **argv)
12 {
13   int nprocs = -1;
14   int rank = -1;
15   char processor_name[128];
16   int namelen = 128;
17   int buf0[buf_size];
18   int buf1[buf_size];
19   MPI_Status status;
20   MPI_Comm comm;
21   MPI_Group world_group, dgroup;
22   int *granks;
23   int i, drank, dnprocs, newsize;
24
25   /* init */
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);
31   fflush (stdout);
32
33   MPI_Barrier (MPI_COMM_WORLD);
34
35   if (nprocs < 3) {
36     printf ("not enough tasks\n");
37   }
38   else {
39     MPI_Comm_group (MPI_COMM_WORLD, &world_group);
40     if (nprocs % 2)
41       newsize = (nprocs/2) + 1;
42     else
43       newsize = nprocs/2;
44     granks = (int *) malloc (sizeof(int) * (newsize));
45     for (i = 0; i < newsize; i++)
46       granks [i] = 2 * 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);
51     free (granks);
52
53     if (comm != MPI_COMM_NULL) {
54       MPI_Comm_size (comm, &dnprocs);
55       MPI_Comm_rank (comm, &drank);
56
57       if (dnprocs > 1) {
58         if (drank == 0) {
59           memset (buf0, 0, buf_size*sizeof(int));
60
61           MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
62         
63           MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
64         }
65         else if (drank == 1) {
66           memset (buf1, 1, buf_size*sizeof(int));
67
68           MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
69
70           MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
71         }
72       }
73       else {
74         printf ("(%d) Derived communicator too small (size = %d)\n",
75                 rank, dnprocs);
76       }
77
78       MPI_Comm_free (&comm);
79     }
80     else {
81       printf ("(%d) Got MPI_COMM_NULL\n", rank);
82     }
83   }
84
85   MPI_Barrier (MPI_COMM_WORLD);
86
87   MPI_Finalize ();
88   printf ("(%d) Finished normally\n", rank);
89 }
90
91 /* EOF */