Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reactivate an umpire test, once disabled in 56fefe1bf81ca.
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-persistent-waitpartial.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-waitpartial.c,v 1.1 2002/01/15 23:55:08 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
17 int
18 main (int argc, char **argv)
19 {
20   int nprocs = -1;
21   int rank = -1;
22   MPI_Comm comm = MPI_COMM_WORLD;
23   char processor_name[128];
24   int namelen = 128;
25   int buf[BUF_SIZE * 2];
26   int i, j, k, index, outcount, flag;
27   int indices[2];
28   MPI_Request aReq[2];
29   MPI_Status aStatus[2];
30
31   /* init */
32   MPI_Init (&argc, &argv);
33   MPI_Comm_size (comm, &nprocs);
34   MPI_Comm_rank (comm, &rank);
35   MPI_Get_processor_name (processor_name, &namelen);
36   printf ("(%d) is alive on %s\n", rank, processor_name);
37   fflush (stdout);
38
39   if (rank == 0) {
40     /* set up persistent sends... */
41     MPI_Send_init (&buf[0], BUF_SIZE, MPI_INT, 1, 0, comm, &aReq[0]);
42     MPI_Send_init (&buf[BUF_SIZE], BUF_SIZE, MPI_INT, 1, 1, comm, &aReq[1]);
43
44     /* initialize the send buffers */
45     for (i = 0; i < BUF_SIZE; i++) {
46       buf[i] = i;
47       buf[BUF_SIZE + i] = BUF_SIZE - 1 - i;
48     }
49   }
50
51   for (k = 0; k < 4; k++) {
52     if (rank == 1) {
53       /* zero out the receive buffers */
54       bzero (buf, sizeof(int) * BUF_SIZE * 2);
55     }
56
57     MPI_Barrier(MPI_COMM_WORLD);
58
59     if (rank == 0) {
60       /* start the persistent sends... */
61       if (k % 2) {
62         MPI_Startall (2, &aReq[0]);
63       }
64       else {
65         for (j = 0; j < 2; j++) {
66           MPI_Start (&aReq[j]);
67         }
68       }
69
70       /* complete the sends */
71       if (k < 2) {
72         /* use MPI_Waitany */
73         for (j = 0; j < 2; j++)
74           MPI_Waitany (2, aReq, &index, aStatus);
75       }
76       else {
77         /* use MPI_Waitsome */
78         j = 0;
79         while (j < 2) {
80           MPI_Waitsome (2, aReq, &outcount, indices, aStatus);
81           j += outcount;
82         }
83       }
84     }
85     else if (rank == 1) {
86       /* set up receives for all of the sends */
87       for (j = 0; j < 2; j++) {
88         MPI_Irecv (&buf[j * BUF_SIZE], BUF_SIZE,
89                    MPI_INT, 0, j, comm, &aReq[j]);
90       }
91       /* complete all of the receives... */
92       MPI_Waitall (2, aReq, aStatus);
93     }
94   }
95
96   MPI_Barrier(MPI_COMM_WORLD);
97
98   if (rank == 0) {
99     /* free the persistent requests */
100     for (i = 0 ; i < 2; i++) {
101       MPI_Request_free (&aReq[i]);
102     }
103   }
104
105   MPI_Finalize ();
106   printf ("(%d) Finished normally\n", rank);
107 }
108
109 /* EOF */