Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free memory.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / inactivereq.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2005 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /* This test program checks that the point-to-point completion routines
12    can be applied to an inactive persistent request, as required by the
13    MPI-1 standard. See section 3.7.3, for example,
14
15    One is allowed to call MPI TEST with a null or inactive request argument.
16    In such a case the operation returns with flag = true and empty status.
17
18 */
19
20 int StatusEmpty(MPI_Status * s);
21 int StatusEmpty(MPI_Status * s)
22 {
23     int errs = 0;
24     int count = 10;
25
26     if (s->MPI_TAG != MPI_ANY_TAG) {
27         errs++;
28         printf("MPI_TAG not MPI_ANY_TAG in status\n");
29     }
30     if (s->MPI_SOURCE != MPI_ANY_SOURCE) {
31         errs++;
32         printf("MPI_SOURCE not MPI_ANY_SOURCE in status\n");
33     }
34     MPI_Get_count(s, MPI_INT, &count);
35     if (count != 0) {
36         errs++;
37         printf("count in status is not 0\n");
38     }
39     /* Return true only if status passed all tests */
40     return errs ? 0 : 1;
41 }
42
43 int main(int argc, char *argv[])
44 {
45     MPI_Request r;
46     MPI_Status s;
47     int errs = 0;
48     int flag;
49     int buf[10];
50     int rbuf[10];
51     int tag = 27;
52     int dest = 0;
53     int rank, size;
54
55     MTest_Init(&argc, &argv);
56
57     MPI_Comm_size(MPI_COMM_WORLD, &size);
58     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
59
60     /* Create a persistent send request */
61     MPI_Send_init(buf, 10, MPI_INT, dest, tag, MPI_COMM_WORLD, &r);
62
63     flag = 0;
64     s.MPI_TAG = 10;
65     s.MPI_SOURCE = 10;
66     MPI_Test(&r, &flag, &s);
67     if (!flag) {
68         errs++;
69         printf("Flag not true after MPI_Test (send)\n");
70         printf("Aborting further tests to avoid hanging in MPI_Wait\n");
71         MTest_Finalize(errs);
72         MPI_Finalize();
73         return 0;
74     }
75     if (!StatusEmpty(&s)) {
76         errs++;
77         printf("Status not empty after MPI_Test (send)\n");
78     }
79
80     s.MPI_TAG = 10;
81     s.MPI_SOURCE = 10;
82     MPI_Wait(&r, &s);
83     if (!StatusEmpty(&s)) {
84         errs++;
85         printf("Status not empty after MPI_Wait (send)\n");
86     }
87
88     /* Now try to use that request, then check again */
89     if (rank == 0) {
90         int i;
91         MPI_Request *rr = (MPI_Request *) malloc(size * sizeof(MPI_Request));
92         for (i = 0; i < size; i++) {
93             MPI_Irecv(rbuf, 10, MPI_INT, i, tag, MPI_COMM_WORLD, &rr[i]);
94         }
95         MPI_Start(&r);
96         MPI_Wait(&r, &s);
97         MPI_Waitall(size, rr, MPI_STATUSES_IGNORE);
98         free(rr);
99     }
100     else {
101         MPI_Start(&r);
102         MPI_Wait(&r, &s);
103     }
104
105     flag = 0;
106     s.MPI_TAG = 10;
107     s.MPI_SOURCE = 10;
108     MPI_Test(&r, &flag, &s);
109     if (!flag) {
110         errs++;
111         printf("Flag not true after MPI_Test (send)\n");
112         printf("Aborting further tests to avoid hanging in MPI_Wait\n");
113         MTest_Finalize(errs);
114         MPI_Finalize();
115         return 0;
116     }
117     if (!StatusEmpty(&s)) {
118         errs++;
119         printf("Status not empty after MPI_Test (send)\n");
120     }
121
122     s.MPI_TAG = 10;
123     s.MPI_SOURCE = 10;
124     MPI_Wait(&r, &s);
125     if (!StatusEmpty(&s)) {
126         errs++;
127         printf("Status not empty after MPI_Wait (send)\n");
128     }
129
130
131
132     MPI_Request_free(&r);
133
134     /* Create a persistent receive request */
135     MPI_Recv_init(buf, 10, MPI_INT, dest, tag, MPI_COMM_WORLD, &r);
136
137     flag = 0;
138     s.MPI_TAG = 10;
139     s.MPI_SOURCE = 10;
140     MPI_Test(&r, &flag, &s);
141     if (!flag) {
142         errs++;
143         printf("Flag not true after MPI_Test (recv)\n");
144         printf("Aborting further tests to avoid hanging in MPI_Wait\n");
145         MTest_Finalize(errs);
146         MPI_Finalize();
147         return 0;
148     }
149     if (!StatusEmpty(&s)) {
150         errs++;
151         printf("Status not empty after MPI_Test (recv)\n");
152     }
153
154     s.MPI_TAG = 10;
155     s.MPI_SOURCE = 10;
156     MPI_Wait(&r, &s);
157     if (!StatusEmpty(&s)) {
158         errs++;
159         printf("Status not empty after MPI_Wait (recv)\n");
160     }
161
162     MPI_Request_free(&r);
163
164     MTest_Finalize(errs);
165     MPI_Finalize();
166     return 0;
167 }