Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c800ba65db382a2400a892d70709ea0c0ea9909f
[simgrid.git] / teshsuite / smpi / isp / umpire / basic-deadlock-graph_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 GRAPH_SZ 4
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   int drank, dnprocs;
24   int graph_index[] = { 2, 3, 4, 6 };
25   int graph_edges[] = { 1, 3, 0, 3, 0, 2 };
26
27   /* init */
28   MPI_Init (&argc, &argv);
29   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
30   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
31   MPI_Get_processor_name (processor_name, &namelen);
32   printf ("(%d) is alive on %s\n", rank, processor_name);
33   fflush (stdout);
34
35   MPI_Barrier (MPI_COMM_WORLD);
36
37   if (nprocs < 4) {
38     printf ("not enough tasks\n");
39   }
40   else {
41     /* create the graph on p.268 MPI: The Complete Reference... */
42     MPI_Graph_create (MPI_COMM_WORLD, GRAPH_SZ,
43                       graph_index, graph_edges, 1, &comm);
44
45     if (comm != MPI_COMM_NULL) {
46       MPI_Comm_size (comm, &dnprocs);
47       MPI_Comm_rank (comm, &drank);
48
49       if (dnprocs > 1) {
50         if (drank == 0) {
51           memset (buf0, 0, buf_size);
52
53           MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, comm, &status);
54         
55           MPI_Send (buf0, buf_size, MPI_INT, 1, 0, comm);
56         }
57         else if (drank == 1) {
58           memset (buf1, 1, buf_size);
59
60           MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, comm, &status);
61
62           MPI_Send (buf1, buf_size, MPI_INT, 0, 0, comm);
63         }
64       }
65       else {
66         printf ("(%d) Derived communicator too small (size = %d)\n",
67                 rank, dnprocs);
68       }
69
70       MPI_Comm_free (&comm);
71     }
72     else {
73       printf ("(%d) Got MPI_COMM_NULL\n", rank);
74     }
75   }
76
77   MPI_Barrier (MPI_COMM_WORLD);
78
79   MPI_Finalize ();
80   printf ("(%d) Finished normally\n", rank);
81 }
82
83 /* EOF */