Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] ISP tests integration
[simgrid.git] / teshsuite / smpi / isp / umpire / partial-recv-persistent2.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-persistent2.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   int 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, index;
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_Waitany */
78         for (j = 0; j < 2; j++) {
79           MPI_Waitany (2, aReq, &index, aStatus);
80         }
81       }
82       else {
83         /* use MPI_Testany */
84         for (j = 0; j < 2; j++) {
85           flag = 0;
86           while (!flag) {
87             MPI_Testany (2, aReq, &index, &flag, aStatus);
88           }
89         }
90       }
91     }  
92     else {
93       /* Barrier to ensure receives are posted for rsends... */
94       MPI_Barrier(MPI_COMM_WORLD);
95     }
96   }
97
98   MPI_Barrier(MPI_COMM_WORLD);
99
100   if (rank < 2) {
101     /* free the persistent requests */
102     MPI_Request_free (&aReq[0]);
103     MPI_Request_free (&aReq[1]);
104   }
105
106   MPI_Finalize ();
107   printf ("(%d) Finished normally\n", rank);
108 }
109
110 /* EOF */