Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Multiply memset size by size of element in umpire.
[simgrid.git] / teshsuite / smpi / isp / umpire / persistent4.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Thu Nov 30 2000 */
3 /* persistent3.c -- do some MPI persistent calls */
4 /* including freeing an active request - the effect of which */
5 /* is implementation dependent - usually a detected error */
6 /* in this test, the error is made in only task rank 1... */
7
8 #include <stdio.h>
9 #include "mpi.h"
10
11 #define buf_size 128
12
13 int
14 main (int argc, char **argv)
15 {
16   int nprocs = -1;
17   int rank = -1;
18   char processor_name[128];
19   int namelen = 128;
20   int buf0[buf_size];
21   int buf1[buf_size];
22   MPI_Request aReq[2], free_req;
23   MPI_Status aStatus[2];
24
25   MPI_Status status;
26
27   /* init */
28   MPI_Init (&argc, &argv);
29   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
30   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
31   MPI_Get_processor_name (processor_name, &namelen);
32   printf ("(%d) is alive on %s\n", rank, processor_name);
33   fflush (stdout);
34
35   MPI_Barrier (MPI_COMM_WORLD);
36
37   if (nprocs < 3) {
38     /* use at least 3 tasks so there is one non-mgr without error... */
39     printf ("not enough tasks\n");
40   }
41   else {
42     if (rank == 0) {
43       memset (buf0, 0, buf_size*sizeof(int));
44
45       MPI_Send_init (buf0, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &aReq[0]);
46       MPI_Recv_init (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &aReq[1]);
47
48       MPI_Start (&aReq[0]);
49       MPI_Start (&aReq[1]);
50
51       MPI_Waitall (2, aReq, aStatus);
52
53       memset (buf0, 1, buf_size*sizeof(int));
54
55       MPI_Startall (2, aReq);
56
57       MPI_Waitall (2, aReq, aStatus);
58     }
59     else if (rank == 1) {
60       memset (buf1, 1, buf_size*sizeof(int));
61
62       MPI_Recv_init (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &aReq[0]);
63       MPI_Send_init (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &aReq[1]);
64
65       MPI_Start (&aReq[0]);
66       MPI_Start (&aReq[1]);
67
68       MPI_Waitall (2, aReq, aStatus);
69
70       memset (buf1, 0, buf_size*sizeof(int));
71
72       MPI_Startall (2, aReq);
73
74       /* free an active request... */
75       free_req = aReq[1];
76       MPI_Request_free (&free_req);
77
78       MPI_Waitall (2, aReq, aStatus);
79     }
80   }
81
82   MPI_Barrier (MPI_COMM_WORLD);
83
84   MPI_Request_free (&aReq[0]);
85
86   MPI_Finalize ();
87   printf ("(%d) Finished normally\n", rank);
88 }
89
90 /* EOF */