2 Test ordering of messages that differ only in data
4 sendorder [ -n number-of-sends ] [ -m length-of-long-sends ]
14 void CheckStatus( MPI_Status *, int, int, int, int * );
17 This is a delay to make sure that several messages are in the queue when
18 the MPI_Recv is called
24 double deltat = ms * 0.001;
26 //while (MPI_Wtime() - t < deltat) ;
30 void CheckStatus( MPI_Status *status, int tag, int src, int cnt, int *err )
34 if (status->MPI_TAG != tag && status->MPI_SOURCE != src) {
37 "Error in message status! tag = %d and source = %d\n", status->MPI_TAG,
42 MPI_Get_count( status, MPI_INT, &n );
46 "Error in message status! length is %d and should be %d\n", n, cnt );
52 int main( int argc, char *argv[] )
54 int i, n, m, val, *buf;
56 int src, dest, tag, err = 0, toterr;
60 MPI_Init( &argc, &argv );
62 n = 1000; /* Number of tests */
63 comm = MPI_COMM_WORLD;
65 m = 1000; /* Size in ints of longer buffer */
71 if (argv[0] && strcmp( argv[0], "-n" ) == 0) {
75 else if (argv[0] && strcmp( argv[0], "-m" ) == 0) {
81 /* Ensure that everyone has the values */
82 MPI_Bcast( &n, 1, MPI_INT, 0, MPI_COMM_WORLD );
83 MPI_Bcast( &m, 1, MPI_INT, 0, MPI_COMM_WORLD );
85 MPI_Comm_rank( comm, &rank );
86 MPI_Comm_size( comm, &size );
88 fprintf( stderr, "This program requires at least 2 processes\n" );
89 MPI_Abort( MPI_COMM_WORLD, 1 );
98 MPI_Send( &i, 1, MPI_INT, dest, tag, comm );
101 else if (rank == dest) {
102 for (i=0; i<n; i++) {
104 MPI_Recv( &val, 1, MPI_INT, src, tag, comm, &status );
105 /* The messages are sent in order that matches the value of i;
106 if they are not received in order, this will show up in the
111 "Error in message order (single int): message %d received when %d expected\n", val, i );
115 CheckStatus( &status, tag, src, 1, &err );
119 /* Alternating message sizes */
120 buf = (int *)malloc( m * sizeof(int) );
122 fprintf( stdout, "Could not allocate %d ints\n", m );
123 MPI_Abort( MPI_COMM_WORLD, 1 );
125 for (i=0; i<m; i++) buf[i] = - i;
129 for (i=0; i<n; i++) {
131 MPI_Send( &i, 1, MPI_INT, dest, tag, comm );
132 MPI_Send( buf, m, MPI_INT, dest, tag, comm );
135 else if (rank == dest) {
136 for (i=0; i<n; i++) {
138 MPI_Recv( &val, 1, MPI_INT, src, tag, comm, &status );
142 "Error in message order: message %d received when %d expected\n", val, i );
146 CheckStatus( &status, tag, src, 1, &err );
148 MPI_Recv( buf, m, MPI_INT, src, tag, comm, &status );
152 "Error in message order: message buf[] %d received when %d expected\n",
157 CheckStatus( &status, tag, src, m, &err );
161 /* Finally error reporting: make sure that rank 0 reports the message */
162 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
163 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
165 if (toterr) printf( "Found %d errors\n", toterr );
166 else printf( " No Errors\n" );
169 MPI_Barrier( MPI_COMM_WORLD );