Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add some new pt2pt tests from mpich
[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 test_recv_init(int src_rank, const char *test_name)
44 {
45     MPI_Request r;
46     MPI_Status s;
47     int errs = 0;
48     int flag;
49     int buf[10];
50     int tag = 27;
51
52     MPI_Recv_init(buf, 10, MPI_INT, src_rank, tag, MPI_COMM_WORLD, &r);
53
54     flag = 0;
55     s.MPI_TAG = 10;
56     s.MPI_SOURCE = 10;
57     MPI_Test(&r, &flag, &s);
58     if (!flag) {
59         errs++;
60         printf("Flag not true after MPI_Test (%s)\n", test_name);
61         printf("Aborting further tests to avoid hanging in MPI_Wait\n");
62         return errs;
63     }
64     if (!StatusEmpty(&s)) {
65         errs++;
66         printf("Status not empty after MPI_Test (%s)\n", test_name);
67     }
68
69     s.MPI_TAG = 10;
70     s.MPI_SOURCE = 10;
71     MPI_Wait(&r, &s);
72     if (!StatusEmpty(&s)) {
73         errs++;
74         printf("Status not empty after MPI_Wait (%s)\n", test_name);
75     }
76
77     MPI_Request_free(&r);
78
79     return errs;
80 }
81
82 int main(int argc, char *argv[])
83 {
84     MPI_Request r;
85     MPI_Status s;
86     int errs = 0, e;
87     int flag;
88     int buf[10];
89     int rbuf[10];
90     int tag = 27;
91     int dest = 0;
92     int rank, size;
93
94     MTest_Init(&argc, &argv);
95
96     MPI_Comm_size(MPI_COMM_WORLD, &size);
97     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
98
99     if (rank == 0)
100         MTestPrintfMsg(1, "Create a persistent send request\n");
101
102     MPI_Send_init(buf, 10, MPI_INT, dest, tag, MPI_COMM_WORLD, &r);
103
104     flag = 0;
105     s.MPI_TAG = 10;
106     s.MPI_SOURCE = 10;
107     MPI_Test(&r, &flag, &s);
108     if (!flag) {
109         errs++;
110         printf("Flag not true after MPI_Test (send)\n");
111         printf("Aborting further tests to avoid hanging in MPI_Wait\n");
112         MTest_Finalize(errs);
113         return MTestReturnValue(errs);
114     }
115     if (!StatusEmpty(&s)) {
116         errs++;
117         printf("Status not empty after MPI_Test (send)\n");
118     }
119
120     s.MPI_TAG = 10;
121     s.MPI_SOURCE = 10;
122     MPI_Wait(&r, &s);
123     if (!StatusEmpty(&s)) {
124         errs++;
125         printf("Status not empty after MPI_Wait (send)\n");
126     }
127
128     /* Now try to use that request, then check again */
129     if (rank == 0) {
130         int i;
131         MPI_Request *rr = (MPI_Request *) malloc(size * sizeof(MPI_Request));
132         for (i = 0; i < size; i++) {
133             MPI_Irecv(rbuf, 10, MPI_INT, i, tag, MPI_COMM_WORLD, &rr[i]);
134         }
135         MPI_Start(&r);
136         MPI_Wait(&r, &s);
137         MPI_Waitall(size, rr, MPI_STATUSES_IGNORE);
138         free(rr);
139     } else {
140         MPI_Start(&r);
141         MPI_Wait(&r, &s);
142     }
143
144     flag = 0;
145     s.MPI_TAG = 10;
146     s.MPI_SOURCE = 10;
147     MPI_Test(&r, &flag, &s);
148     if (!flag) {
149         errs++;
150         printf("Flag not true after MPI_Test (send)\n");
151         printf("Aborting further tests to avoid hanging in MPI_Wait\n");
152         MTest_Finalize(errs);
153         return MTestReturnValue(errs);
154     }
155     if (!StatusEmpty(&s)) {
156         errs++;
157         printf("Status not empty after MPI_Test (send)\n");
158     }
159
160     s.MPI_TAG = 10;
161     s.MPI_SOURCE = 10;
162     MPI_Wait(&r, &s);
163     if (!StatusEmpty(&s)) {
164         errs++;
165         printf("Status not empty after MPI_Wait (send)\n");
166     }
167
168
169
170     MPI_Request_free(&r);
171
172     if (rank == 0)
173         MTestPrintfMsg(1, "Create a persistent receive request\n");
174
175     e = test_recv_init(dest, "recv");
176     errs += e;
177     if (e)
178         goto fn_exit;
179
180     if (rank == 0)
181         MTestPrintfMsg(1, "Create a persistent receive (ANY_SOURCE) request\n");
182
183     errs += test_recv_init(MPI_ANY_SOURCE, "recv-anysource");
184
185   fn_exit:
186     MTest_Finalize(errs);
187     return MTestReturnValue(errs);
188 }