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-cart_sub.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 #define TWOD     2
11
12 int
13 main (int argc, char **argv)
14 {
15   int nprocs = -1;
16   int rank = -1;
17   char processor_name[128];
18   int namelen = 128;
19   int buf0[buf_size];
20   int buf1[buf_size];
21   MPI_Status status;
22   MPI_Comm temp, comm;
23   MPI_Group world_group, dgroup;
24   int *granks;
25   int dims[TWOD], periods[TWOD], remain_dims[TWOD];
26   int drank, dnprocs;
27
28   /* init */
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);
34   fflush (stdout);
35
36   MPI_Barrier (MPI_COMM_WORLD);
37
38   if (nprocs < 4) {
39     printf ("not enough tasks\n");
40   }
41   else {
42     /* need to make cartesian communicator temporarily... */
43     /* create a 2 X nprocs/2 torus topology, allow reordering */
44     dims[0] = 2;
45     dims[1] = nprocs/2;
46     periods[0] = periods[1] = 1;
47     MPI_Cart_create (MPI_COMM_WORLD, TWOD, dims, periods, 1, &temp);
48
49     if (temp != MPI_COMM_NULL) {
50       /* create 2 1 X nprocs/2 topologies... */
51       remain_dims[0] = 0;
52       remain_dims[1] = 1;
53       MPI_Cart_sub (temp, remain_dims, &comm);
54       /* free up temporarily created cartesian communicator... */
55       MPI_Comm_free (&temp);
56     }
57     else {
58       comm = MPI_COMM_NULL;
59     }
60
61     if (comm != MPI_COMM_NULL) {
62       MPI_Comm_size (comm, &dnprocs);
63       MPI_Comm_rank (comm, &drank);
64
65       if (dnprocs > 1) {
66         if (drank == 0) {
67           memset (buf0, 0, buf_size*sizeof(int));
68
69           MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
70         
71           MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
72         }
73         else if (drank == 1) {
74           memset (buf1, 1, buf_size*sizeof(int));
75
76           MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
77
78           MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
79         }
80       }
81       else {
82         printf ("(%d) Derived communicator too small (size = %d)\n",
83                 rank, dnprocs);
84       }
85
86       MPI_Comm_free (&comm);
87     }
88     else {
89       printf ("(%d) Got MPI_COMM_NULL\n", rank);
90     }
91   }
92
93   MPI_Barrier (MPI_COMM_WORLD);
94
95   MPI_Finalize ();
96   printf ("(%d) Finished normally\n", rank);
97 }
98
99 /* EOF */