Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #181 from bcamus/master
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-persistent-test.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-test.c,v 1.1 2002/01/14 18:58:07 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_Test */
73         for (j = 0; j < 2; j++) {
74           flag = 0;
75           while (!flag) {
76             MPI_Test (&aReq[j], &flag, &aStatus[j]);
77           }
78         }
79       }
80       else {
81         /* use MPI_Testall */
82         flag = 0;
83         while (!flag) {
84           MPI_Testall (2, aReq, &flag, aStatus);
85         }
86       }
87     }
88     else if (rank == 1) {
89       /* set up receives for all of the sends */
90       for (j = 0; j < 2; j++) {
91         MPI_Irecv (&buf[j * BUF_SIZE], BUF_SIZE,
92                    MPI_INT, 0, j, comm, &aReq[j]);
93       }
94       /* complete all of the receives... */
95       MPI_Waitall (2, aReq, aStatus);
96     }
97   }
98
99   MPI_Barrier(MPI_COMM_WORLD);
100
101   if (rank == 0) {
102     /* free the persistent requests */
103     for (i = 0 ; i < 2; i++) {
104       MPI_Request_free (&aReq[i]);
105     }
106   }
107
108   MPI_Finalize ();
109   printf ("(%d) Finished normally\n", rank);
110 }
111
112 /* EOF */