Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Multiply memset size by size of element in umpire.
[simgrid.git] / teshsuite / smpi / isp / umpire / basic-deadlock-intercomm_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 INTERCOMM_CREATE_TAG 666
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, intercomm;
23   int drank, dnprocs, rleader, rnprocs;
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     /* need to make split communicator temporarily... */
40     MPI_Comm_split (MPI_COMM_WORLD, rank % 2, nprocs - rank, &temp);
41
42     if (temp != MPI_COMM_NULL) {
43       /* create an intercommunicator temporarily so can merge it... */
44       rleader = ((rank + nprocs) % 2) ?  nprocs - 2 : nprocs - 1;
45       MPI_Intercomm_create (temp, 0, MPI_COMM_WORLD, rleader,
46                             INTERCOMM_CREATE_TAG, &intercomm);
47
48       MPI_Comm_free (&temp);
49
50       if (intercomm != MPI_COMM_NULL) {
51         MPI_Comm_size (intercomm, &dnprocs);
52         MPI_Comm_rank (intercomm, &drank);
53         MPI_Comm_remote_size (intercomm, &rnprocs);
54
55         if (rnprocs > drank) {
56           if (rank % 2) {
57             memset (buf1, 1, buf_size*sizeof(int));
58
59             MPI_Recv (buf0, buf_size, MPI_INT, drank, 0, intercomm, &status);
60
61             MPI_Send (buf1, buf_size, MPI_INT, drank, 0, intercomm);
62           }
63           else {
64             memset (buf0, 0, buf_size*sizeof(int));
65         
66             MPI_Recv (buf1, buf_size, MPI_INT, drank, 0, intercomm, &status);
67         
68             MPI_Send (buf0, buf_size, MPI_INT, drank, 0, intercomm);
69           }
70         }
71         else {
72           printf ("(%d) Intercomm too small (lrank = %d; remote size = %d)\n",
73                   rank, drank, rnprocs);
74         }
75
76         MPI_Comm_free (&intercomm);
77       }
78       else {
79         printf ("(%d) Got MPI_COMM_NULL\n", rank);
80       }
81     }
82     else {
83       printf ("(%d) MPI_Comm_split got MPI_COMM_NULL\n", rank);
84     }
85   }
86
87   MPI_Barrier (MPI_COMM_WORLD);
88
89   MPI_Finalize ();
90   printf ("(%d) Finished normally\n", rank);
91 }
92
93 /* EOF */