7 #if defined(NEEDS_STDLIB_PROTOTYPES)
15 This is similar to a test in allpair.f, but with an expanded range of
16 datatypes and communicators.
19 int main( int argc, char **argv )
22 void **inbufs, **outbufs;
24 int *counts, *bytesize, ntype;
26 int ncomm = 20, rank, np, partner, tag;
27 int i, j, k, err, toterr, world_rank;
28 MPI_Status status, statuses[2];
31 MPI_Request requests[2];
34 MPI_Init( &argc, &argv );
36 AllocateForData( &types, &inbufs, &outbufs, &counts, &bytesize,
38 GenerateData( types, inbufs, outbufs, counts, bytesize, names, &ntype );
40 MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
41 MakeComms( comms, 20, &ncomm, 0 );
43 /* Test over a wide range of datatypes and communicators */
45 for (i=0; i<ncomm; i++) {
46 MPI_Comm_rank( comms[i], &rank );
47 MPI_Comm_size( comms[i], &np );
60 testall (should succeed)
62 for (j=0; j<ntype; j++) {
63 if (world_rank == 0 && verbose)
64 fprintf( stdout, "Testing type %s\n", names[j] );
69 MPIR_PrintDatatypePack( stdout, counts[j], types[j], 0, 0 );
72 for (k=0; k<bytesize[j]; k++)
75 MPI_Irecv(outbufs[j], counts[j], types[j], partner, tag,
76 comms[i], &requests[0] );
78 /* Use issend to ensure that the test cannot complete */
79 MPI_Isend( inbufs[j], counts[j], types[j], partner, tag,
80 comms[i], &requests[1] );
82 /* Note that the send may have completed */
83 MPI_Testall( 2, &requests[0], &flag, statuses );
86 fprintf( stderr, "MPI_Testall returned flag == true!\n" );
88 if (requests[1] == MPI_REQUEST_NULL) {
90 fprintf( stderr, "MPI_Testall freed a request\n" );
92 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
93 MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
95 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
96 MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
98 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
99 MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
101 /* This should succeed, but may fail if the wait below is
103 MPI_Testall( 2, requests, &flag, statuses );
106 fprintf( stderr, "MPI_Testall returned flag == false!\n" );
108 if (requests[0] != MPI_REQUEST_NULL ||
109 requests[1] != MPI_REQUEST_NULL) {
111 fprintf( stderr, "MPI_Testall failed to free requests (test %d)\n", j );
112 if (requests[0] != MPI_REQUEST_NULL) {
113 fprintf( stderr, "Failed to free Irecv request\n" );
115 if (requests[1] != MPI_REQUEST_NULL) {
116 fprintf( stderr, "Failed to free Isend request\n" );
119 /* Check the received data */
120 if (CheckDataAndPrint( inbufs[j], outbufs[j], bytesize[j],
125 else if (rank == np - 1) {
129 for (k=0; k<bytesize[j]; k++)
132 MPI_Send( inbufs[j], counts[j], types[j], partner, tag,
135 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
136 MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
139 MPI_Irecv(outbufs[j], counts[j], types[j], partner, tag,
140 comms[i], &requests[0] );
142 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
143 MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
146 MPI_Wait( requests, statuses );
147 if (CheckDataAndPrint( inbufs[j], outbufs[j], bytesize[j],
151 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
152 MPI_BOTTOM, 0, MPI_INT, partner, ncomm+i,
159 fprintf( stderr, "%d errors on %d\n", err, rank );
161 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
162 if (world_rank == 0) {
164 printf( " No Errors\n" );
167 printf (" Found %d errors\n", toterr );
170 FreeDatatypes( types, inbufs, outbufs, counts, bytesize, names, ntype );
171 FreeComms( comms, ncomm );