Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the compilation of MPICH3 tests with the absolute paranoid flags (enable_maintainer)
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / anyall.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2009 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 #define MAX_MSGS 30
12
13 /*
14 static char MTEST_Descrip[] = "One implementation delivered incorrect data when an MPI recieve uses both ANY_SOURCE and ANY_TAG";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int wrank, wsize, master, worker, i, j, idx, count;
20     int errs = 0;
21     MPI_Request r[MAX_MSGS];
22     int buf[MAX_MSGS][MAX_MSGS];
23     MPI_Comm comm;
24     MPI_Status status;
25
26     MTest_Init(&argc, &argv);
27
28     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
29     MPI_Comm_size(MPI_COMM_WORLD, &wsize);
30
31     comm = MPI_COMM_WORLD;
32     master = 0;
33     worker = 1;
34
35     /* The test takes advantage of the ordering rules for messages */
36
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;
42             }
43         }
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);
47         }
48     }
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++) {
53                 buf[i][j] = -1;
54             }
55         }
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]);
58         }
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) {
65                 errs++;
66             }
67             else {
68                 /* Check for the correct answers */
69                 for (j = 0; j < MAX_MSGS - idx; j++) {
70                     if (buf[idx][j] != idx * MAX_MSGS + j) {
71                         errs++;
72                         printf("Message %d [%d] is %d, should be %d\n",
73                                idx, j, buf[idx][j], idx * MAX_MSGS + j);
74                     }
75                 }
76             }
77         }
78     }
79     else {
80         MPI_Barrier(MPI_COMM_WORLD);
81     }
82
83     MTest_Finalize(errs);
84     MPI_Finalize();
85
86     return 0;
87 }