Logo AND Algorithmique Numérique Distribuée

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