Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] ISP tests integration
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-persistent.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.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   int 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_Wait */
73         for (j = 0; j < 2; j++)
74           MPI_Wait (&aReq[j], &aStatus[j]);
75       else 
76         /* use MPI_Waitall */
77         MPI_Waitall (2, aReq, aStatus);
78     }
79     else if (rank == 1) {
80       /* set up receives for all of the sends */
81       for (j = 0; j < 2; j++) {
82         MPI_Irecv (&buf[j * BUF_SIZE], BUF_SIZE, 
83                    MPI_INT, 0, j, comm, &aReq[j]);
84       }
85       /* complete all of the receives... */
86       MPI_Waitall (2, aReq, aStatus);
87     }
88   }
89
90   MPI_Barrier(MPI_COMM_WORLD);
91
92   if (rank == 0) {
93     /* free the persistent requests */
94     for (i = 0 ; i < 2; i++) {
95       MPI_Request_free (&aReq[i]);
96     }
97   }
98
99   MPI_Finalize ();
100   printf ("(%d) Finished normally\n", rank);
101 }
102
103 /* EOF */