Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-persistent-all-completions.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Jeffrey Vetter (j-vetter@llnl.gov) Mon Nov  1 1999 */
3 /* lost-request.c -- overwrite a request and essentially lose a synch point */
4
5 #ifndef lint
6 static char *rcsid =
7   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/no-error-persistent-all-completions.c,v 1.1 2002/01/14 18:58:06 bronis Exp $";
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <assert.h>
13 #include "mpi.h"
14
15 #define BUF_SIZE 128
16 #define NUM_COMPLETION_MECHANISMS 8
17
18 int
19 main (int argc, char **argv)
20 {
21   int nprocs = -1;
22   int rank = -1;
23   MPI_Comm comm = MPI_COMM_WORLD;
24   char processor_name[128];
25   int namelen = 128;
26   int buf[BUF_SIZE * 2];
27   int i, j, k, index, outcount, flag;
28   int indices[2];
29   MPI_Request aReq[2];
30   MPI_Status aStatus[2];
31
32   /* init */
33   MPI_Init (&argc, &argv);
34   MPI_Comm_size (comm, &nprocs);
35   MPI_Comm_rank (comm, &rank);
36   MPI_Get_processor_name (processor_name, &namelen);
37   printf ("(%d) is alive on %s\n", rank, processor_name);
38   fflush (stdout);
39
40   if (rank == 0) {
41     /* set up persistent sends... */
42     MPI_Send_init (&buf[0], BUF_SIZE, MPI_INT, 1, 0, comm, &aReq[0]);
43     MPI_Send_init (&buf[BUF_SIZE], BUF_SIZE, MPI_INT, 1, 1, comm, &aReq[1]);
44
45     /* initialize the send buffers */
46     for (i = 0; i < BUF_SIZE; i++) {
47       buf[i] = i;
48       buf[BUF_SIZE + i] = BUF_SIZE - 1 - i;
49     }
50   }
51
52   for (k = 0; k < (NUM_COMPLETION_MECHANISMS * 2); k++) {
53     if (rank == 1) {
54       /* zero out the receive buffers */
55       bzero (buf, sizeof(int) * BUF_SIZE * 2);
56     }
57
58     MPI_Barrier(MPI_COMM_WORLD);
59
60     if (rank == 0) {
61       /* start the persistent sends... */
62       if (k % 2) {
63         MPI_Startall (2, &aReq[0]);
64       }
65       else {
66         for (j = 0; j < 2; j++) {
67           MPI_Start (&aReq[j]);
68         }
69       }
70     
71       /* complete the sends */
72       switch (k/2) {
73       case 0:
74         /* use MPI_Wait */
75         for (j = 0; j < 2; j++) {
76           MPI_Wait (&aReq[j], &aStatus[j]);
77         }
78         break;
79         
80       case 1:
81         /* use MPI_Waitall */
82         MPI_Waitall (2, aReq, aStatus);
83         break;
84
85       case 2:
86         /* use MPI_Waitany */
87         for (j = 0; j < 2; j++) {
88           MPI_Waitany (2, aReq, &index, aStatus);
89         }
90         break;
91         
92       case 3:
93         /* use MPI_Waitsome */
94         j = 0;
95         while (j < 2) {
96           MPI_Waitsome (2, aReq, &outcount, indices, aStatus);
97           j += outcount;
98         }
99         break;
100
101       case 4:
102         /* use MPI_Test */
103         for (j = 0; j < 2; j++) {
104           flag = 0;
105           while (!flag) {
106             MPI_Test (&aReq[j], &flag, &aStatus[j]);
107           }
108         }
109         break;
110         
111       case 5:
112         /* use MPI_Testall */
113         flag = 0;
114         while (!flag) {
115           MPI_Testall (2, aReq, &flag, aStatus);
116         }
117         break;
118
119       case 6:
120         /* use MPI_Testany */
121         for (j = 0; j < 2; j++) {
122           flag = 0;
123           while (!flag) {
124             MPI_Testany (2, aReq, &index, &flag, aStatus);
125           }
126         }
127         break;
128         
129       case 7:
130         /* use MPI_Testsome */
131         j = 0;
132         while (j < 2) {
133           outcount = 0;
134           while (!outcount) {
135             MPI_Testsome (2, aReq, &outcount, indices, aStatus);
136           }
137           j += outcount;
138         }
139         break;
140
141       default:
142         assert (0);
143         break;
144       }
145     }
146     else if (rank == 1) {
147       /* set up receives for all of the sends */
148       for (j = 0; j < 2; j++) {
149         MPI_Irecv (&buf[j * BUF_SIZE], BUF_SIZE, 
150                    MPI_INT, 0, j, comm, &aReq[j]);
151       }
152       /* complete all of the receives... */
153       MPI_Waitall (2, aReq, aStatus);
154     }
155   }
156
157   MPI_Barrier(MPI_COMM_WORLD);
158
159   if (rank == 0) {
160     /* free the persistent requests */
161     for (i = 0 ; i < 2; i++) {
162       MPI_Request_free (&aReq[i]);
163     }
164   }
165
166   MPI_Finalize ();
167   printf ("(%d) Finished normally\n", rank);
168 }
169
170 /* EOF */