1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2009 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
14 static char MTEST_Descrip[] = "One implementation delivered incorrect data when an MPI receive uses both ANY_SOURCE and ANY_TAG";
17 int main(int argc, char *argv[])
19 int wrank, wsize, master, worker, i, j, idx, count;
21 MPI_Request r[MAX_MSGS];
22 int buf[MAX_MSGS][MAX_MSGS];
26 MTest_Init(&argc, &argv);
28 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
29 MPI_Comm_size(MPI_COMM_WORLD, &wsize);
31 comm = MPI_COMM_WORLD;
35 /* The test takes advantage of the ordering rules for messages */
37 if (wrank == master) {
38 /* Initialize the send buffer */
39 for (i = 0; i < MAX_MSGS; i++) {
40 for (j = 0; j < MAX_MSGS; j++) {
41 buf[i][j] = i * MAX_MSGS + j;
44 MPI_Barrier(MPI_COMM_WORLD);
45 for (i = 0; i < MAX_MSGS; i++) {
46 MPI_Send(buf[i], MAX_MSGS - i, MPI_INT, worker, 3, comm);
49 else if (wrank == worker) {
50 /* Initialize the recv buffer */
51 for (i = 0; i < MAX_MSGS; i++) {
52 for (j = 0; j < MAX_MSGS; j++) {
56 for (i = 0; i < MAX_MSGS; i++) {
57 MPI_Irecv(buf[i], MAX_MSGS - i, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, &r[i]);
59 MPI_Barrier(MPI_COMM_WORLD);
60 for (i = 0; i < MAX_MSGS; i++) {
61 MPI_Waitany(MAX_MSGS, r, &idx, &status);
62 /* Message idx should have length MAX_MSGS-idx */
63 MPI_Get_count(&status, MPI_INT, &count);
64 if (count != MAX_MSGS - idx) {
68 /* Check for the correct answers */
69 for (j = 0; j < MAX_MSGS - idx; j++) {
70 if (buf[idx][j] != idx * MAX_MSGS + j) {
72 printf("Message %d [%d] is %d, should be %d\n",
73 idx, j, buf[idx][j], idx * MAX_MSGS + j);
80 MPI_Barrier(MPI_COMM_WORLD);