Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'clean_events' of github.com:Takishipp/simgrid into clean_events
[simgrid.git] / teshsuite / smpi / isp / umpire / lost-request2.c
1 /* -*- Mode: C; -*- */
2 /* Modifier: Bronis R. de Supinski (bronis@llnl.gov) Wed Nov 29 2000 */
3 /* lost-request2.c -- create requests that are never completed */
4 /* Derived directly from comm-split.c by John Gyllenhaal (see below) */
5 /* Written by John Gyllenhaal 10/25/02 to reproduce Gary Kerbel
6   * request leak that caused:
7   *   0:ERROR: 0032-160 Too many communicators  (2046) in
8   *            MPI_Comm_split, task 0
9   * when run for too many cycles.
10   *
11   * Compile with:
12   *   mpxlc comm_split.c -o comm_split
13   * Run with a multiple of two tasks, even tasks have the problem:
14   *  comm_split -nodes 1 -procs 4
15   */
16
17
18 #include "mpi.h"
19 #include <stdio.h>
20
21
22 #define CYCLE_COUNT 5
23
24 int main
25 (int argc, char **argv)
26 {
27   int  numtasks, rank, rc, split_rank, recv_int;
28   int cycle;
29   char processor_name[128];
30   int namelen = 128;
31   MPI_Comm split_comm;
32   MPI_Status status;
33   MPI_Request request;
34   int done;
35
36   rc = MPI_Init(&argc,&argv);
37   if (rc != MPI_SUCCESS)
38     {
39       printf ("Error starting MPI program. Terminating.\n");
40       MPI_Abort(MPI_COMM_WORLD, rc);
41     }
42
43   MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
44   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
45   MPI_Get_processor_name (processor_name, &namelen);
46   printf ("(%d) is alive on %s\n", rank, processor_name);
47   fflush (stdout);
48
49   /* Must be multiple of two for this test */
50   if ((numtasks & 1) != 0)
51     {
52       printf ("Tasks must be multiple of two for this test. Terminating.\n");
53       MPI_Abort(MPI_COMM_WORLD, rc);
54     }
55
56   MPI_Barrier (MPI_COMM_WORLD);
57
58   /* CYCLE_COUNT = 2500 causes IBM implementation to die from request leak */
59   /* Can see problem with only a few (5) cycles */
60   for (cycle = 0; cycle < CYCLE_COUNT; cycle ++)
61     {
62       /* Split adjacent pairs into their own communicator group */
63       rc = MPI_Comm_split (MPI_COMM_WORLD, rank/2, rank, &split_comm);
64       if (rc != MPI_SUCCESS)
65         {
66           printf ("Error (rc %i) cycle %i doing MPI_Comm_split!\n",
67                   rc, cycle);
68           MPI_Abort(MPI_COMM_WORLD, rc);
69         }
70
71       if (rank < 2)
72         printf ("Split_comm handle %i in cycle %i\n", split_comm, cycle);
73
74       MPI_Comm_rank(split_comm, &split_rank);
75
76       if (split_rank == 0)
77         {
78           rc = MPI_Issend (&cycle, 1, MPI_INT, 1, 0, split_comm, &request);
79           if (rc != MPI_SUCCESS)
80             {
81               printf ("Error (rc %i) cycle %i doing MPI_Isend!\n",
82                       rc, cycle);
83               MPI_Abort(MPI_COMM_WORLD, rc);
84             }
85           /* HERE IS THE PROBLEM! Request not waited on, memory leak! */
86         }
87       else if (split_rank == 1)
88         {
89           rc = MPI_Irecv (&recv_int, 1, MPI_INT, 0, 0, split_comm,
90                           &request);
91           if (rc != MPI_SUCCESS)
92             {
93               printf ("Error (rc %i) cycle %i doing MPI_Irecv!\n",
94                       rc, cycle);
95               MPI_Abort(MPI_COMM_WORLD, rc);
96             }
97           done = 0;
98           while (!done)
99             {
100               rc = MPI_Test (&request, &done, &status);
101               if (rc != MPI_SUCCESS)
102                 {
103                   printf ("Error (rc %i) cycle %i doing MPI_Test!\n",
104                           rc, cycle);
105                   MPI_Abort(MPI_COMM_WORLD, rc);
106                 }
107             }
108           if (rank == 1)
109             {
110               printf ("Received %i in recv_int\n", recv_int);
111             }
112         }
113
114       /* Free the communicator */
115       rc = MPI_Comm_free (&split_comm);
116       if (rc != MPI_SUCCESS)
117         {
118           printf ("Error (rc %i) cycle %i doing MPI_Comm_free!\n",
119                   rc, cycle);
120           MPI_Abort(MPI_COMM_WORLD, rc);
121         }
122     }
123
124   MPI_Barrier (MPI_COMM_WORLD);
125
126   MPI_Finalize();
127   printf ("(%d) Finished normally\n", rank);
128
129   return 0;
130 }
131