Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
145f900cdbac9de2e72bc8e78d91de325ed1a710
[simgrid.git] / teshsuite / smpi / isp / umpire / basic-deadlock-cart_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 #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 comm;
23   MPI_Group world_group, dgroup;
24   int *granks;
25   int dims[TWOD], periods[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     /* create a 2 X nprocs/2 torus topology, allow reordering */
43     dims[0] = 2;
44     dims[1] = nprocs/2;
45     periods[0] = periods[1] = 1;
46     MPI_Cart_create (MPI_COMM_WORLD, TWOD, dims, periods, 1, &comm);
47
48     if (comm != MPI_COMM_NULL) {
49       MPI_Comm_size (comm, &dnprocs);
50       MPI_Comm_rank (comm, &drank);
51
52       if (dnprocs > 1) {
53         if (drank == 0) {
54           memset (buf0, 0, buf_size);
55
56           MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
57         
58           MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
59         }
60         else if (drank == 1) {
61           memset (buf1, 1, buf_size);
62
63           MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
64
65           MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
66         }
67       }
68       else {
69         printf ("(%d) Derived communicator too small (size = %d)\n",
70                 rank, dnprocs);
71       }
72
73       MPI_Comm_free (&comm);
74     }
75     else {
76       printf ("(%d) Got MPI_COMM_NULL\n", rank);
77     }
78   }
79
80   MPI_Barrier (MPI_COMM_WORLD);
81
82   MPI_Finalize ();
83   printf ("(%d) Finished normally\n", rank);
84 }
85
86 /* EOF */