Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #193 from Takishipp/signals
[simgrid.git] / teshsuite / smpi / isp / umpire / partial-recv-persistent3.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Jan 24, 2003 */
3 /* partial-recv-persistent2.c -- do persistent ops w/oversized recv bufs */
4
5 #ifndef lint
6 static char *rcsid =
7   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/partial-recv-persistent3.c,v 1.1 2003/05/17 11:05:31 bronis Exp $";
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "mpi.h"
13
14
15 #define BUF_SIZE 128
16 #define SLOP 128
17
18
19 int
20 main (int argc, char **argv)
21 {
22   int nprocs = -1;
23   int rank = -1;
24   MPI_Comm comm = MPI_COMM_WORLD;
25   char processor_name[128];
26   int namelen = 128;
27   int buf[BUF_SIZE * 2 + SLOP];
28   int j, k, flag, total, outcount, 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, 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 (k = 0; k < BUF_SIZE; k++) {
47       buf[k] = k;
48       buf[BUF_SIZE + k] = BUF_SIZE - 1 - k;
49     }
50   }
51   else {
52     /* set up the persistent receives... */
53     MPI_Recv_init (buf, BUF_SIZE, MPI_INT, 0, 0, comm, &aReq[0]);
54     MPI_Recv_init (&buf[BUF_SIZE],BUF_SIZE+SLOP,MPI_INT,0,1,comm,&aReq[1]);
55   }
56
57   for (k = 0; k < 4; k++) {
58     if (rank == 1) {
59       /* zero out all of the receive buffers */
60       bzero (buf, sizeof(int) * BUF_SIZE * 2 + SLOP);
61     }
62
63     /* start the persistent requests... */
64     if (rank < 2) {
65       if (k % 2) {
66         MPI_Startall (2, aReq);
67       }
68       else {
69         MPI_Start (&aReq[0]);
70         MPI_Start (&aReq[1]);
71       }
72
73       MPI_Barrier(MPI_COMM_WORLD);
74
75       /* complete the requests */
76       if (k/2) {
77         /* use MPI_Waitsome */
78         total = 0;
79         while (total < 2) {
80           MPI_Waitsome (2, aReq, &outcount, indices, aStatus);
81           total += outcount;
82         }
83       }
84       else {
85         /* use MPI_Testsome */
86         total = 0;
87         while (total < 2) {
88           outcount = 0;
89
90           while (!outcount) {
91             MPI_Testsome (2, aReq, &outcount, indices, aStatus);
92           }
93
94           total += outcount;
95         }
96       }
97     }
98     else {
99       /* Barrier to ensure receives are posted for rsends... */
100       MPI_Barrier(MPI_COMM_WORLD);
101     }
102   }
103
104   MPI_Barrier(MPI_COMM_WORLD);
105
106   if (rank < 2) {
107     /* free the persistent requests */
108     MPI_Request_free (&aReq[0]);
109     MPI_Request_free (&aReq[1]);
110   }
111
112   MPI_Finalize ();
113   printf ("(%d) Finished normally\n", rank);
114 }
115
116 /* EOF */