Logo AND Algorithmique Numérique Distribuée

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