6 #if defined(NEEDS_STDLIB_PROTOTYPES)
12 This program is from mpich/tsuite/pt2pt and should be changed there only.
13 It needs gcomm and dtype from mpich/tsuite, and can be run with
14 any number of processes > 1.
16 This version uses sendrecv and sendrecv_replace (but only in the
19 int main( int argc, char **argv )
22 void **inbufs, **outbufs;
24 int *counts, *bytesize, ntype;
26 int ncomm = 20, rank, np, partner=0, tag, count;
27 int i, j, k, err, toterr, world_rank, errloc;
31 MPI_Init( &argc, &argv );
33 AllocateForData( &types, &inbufs, &outbufs, &counts, &bytesize,
35 GenerateData( types, inbufs, outbufs, counts, bytesize, names, &ntype );
37 MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
38 MakeComms( comms, 20, &ncomm, 0 );
40 /* Test over a wide range of datatypes and communicators */
42 for (i=0; i<ncomm; i++) {
43 MPI_Comm_rank( comms[i], &rank );
44 MPI_Comm_size( comms[i], &np );
51 for (j=0; j<ntype; j++) {
52 if (world_rank == 0 && verbose)
53 fprintf( stdout, "Testing type %s\n", names[j] );
54 if (rank == 0 || rank == np - 1) {
56 for (k=0; k<bytesize[j]; k++)
58 MPI_Sendrecv( inbufs[j], counts[j], types[j], partner, tag,
59 outbufs[j], counts[j], types[j], partner, tag,
62 MPI_Get_count( &status, types[j], &count );
63 if (count != counts[j]) {
65 "Error in counts (got %d expected %d) with type %s\n",
66 count, counts[j], names[j] );
69 if (status.MPI_SOURCE != partner) {
71 "Error in source (got %d expected %d) with type %s\n",
72 status.MPI_SOURCE, partner, names[j] );
75 if ((errloc = CheckData( inbufs[j], outbufs[j], bytesize[j] ))) {
78 "Error in data with type %s (type %d on %d) at byte %d\n",
79 names[j], j, world_rank, errloc - 1 );
80 p1 = (char *)inbufs[j];
81 p2 = (char *)outbufs[j];
83 "Got %x expected %x\n", p1[errloc-1], p2[errloc-1] );
86 /* Now do sendrecv_replace */
89 for (k=0; k<bytesize[j]; k++)
91 /* This would be a better test if the data was different... */
92 MPI_Sendrecv_replace( obuf, counts[j], types[j], partner, tag,
93 partner, tag, comms[i], &status );
95 MPI_Get_count( &status, types[j], &count );
96 if (count != counts[j]) {
98 "Error in counts (got %d expected %d) with type %s\n",
99 count, counts[j], names[j] );
102 if (status.MPI_SOURCE != partner) {
104 "Error in source (got %d expected %d) with type %s\n",
105 status.MPI_SOURCE, partner, names[j] );
108 if ((errloc = CheckData( inbufs[j], outbufs[j], bytesize[j] ))) {
111 "Error in data with type %s (type %d on %d) at byte %d\n",
112 names[j], j, world_rank, errloc - 1 );
113 p1 = (char *)inbufs[j];
114 p2 = (char *)outbufs[j];
116 "Got %x expected %x\n", p1[errloc-1], p2[errloc-1] );
123 fprintf( stderr, "%d errors on %d\n", err, rank );
125 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
126 if (world_rank == 0) {
128 printf( " No Errors\n" );
131 printf (" Found %d errors\n", toterr );
134 FreeDatatypes( types, inbufs, outbufs, counts, bytesize, names, ntype );
135 FreeComms( comms, ncomm );