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 recieve 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,
58 MPI_ANY_TAG, comm, &r[i] );
60 MPI_Barrier( MPI_COMM_WORLD );
61 for (i=0; i<MAX_MSGS; i++) {
62 MPI_Waitany( MAX_MSGS, r, &idx, &status );
63 /* Message idx should have length MAX_MSGS-idx */
64 MPI_Get_count( &status, MPI_INT, &count );
65 if (count != MAX_MSGS-idx) {
69 /* Check for the correct answers */
70 for (j=0; j < MAX_MSGS-idx; j++) {
71 if (buf[idx][j] != idx * MAX_MSGS + j) {
73 printf( "Message %d [%d] is %d, should be %d\n",
74 idx, j, buf[idx][j], idx * MAX_MSGS + j );
81 MPI_Barrier( MPI_COMM_WORLD );
84 MTest_Finalize( errs );