7 #if defined(NEEDS_STDLIB_PROTOTYPES)
13 This program is from mpich/tsuite/pt2pt and should be changed there only.
14 It needs gcomm and dtype from mpich/tsuite, and can be run with
15 any number of processes > 1.
17 This version uses Pack to send a message and Unpack OR the datatype
20 int main( int argc, char **argv )
23 void **inbufs, **outbufs;
25 char *packbuf, *unpackbuf;
26 int packsize, unpacksize, position;
27 int *counts, *bytesize, ntype;
29 int ncomm = 20, rank, np, partner, tag, count;
30 int i, j, k, err, toterr, world_rank;
35 MPI_Init( &argc, &argv );
37 AllocateForData( &types, &inbufs, &outbufs, &counts, &bytesize,
39 GenerateData( types, inbufs, outbufs, counts, bytesize, names, &ntype );
41 MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
42 MakeComms( comms, 20, &ncomm, 0 );
44 /* Test over a wide range of datatypes and communicators */
46 for (i=0; i<ncomm; i++) {
47 MPI_Comm_rank( comms[i], &rank );
48 MPI_Comm_size( comms[i], &np );
50 if (world_rank == 0 && verbose) {
51 fprintf( stdout, "Testing with communicator with %d members\n", np );
54 for (j=0; j<ntype; j++) {
55 if (world_rank == 0 && verbose)
56 fprintf( stdout, "Testing type %s\n", names[j] );
59 MPI_Pack_size( counts[j], types[j], comms[i], &packsize );
60 packbuf = (char *)malloc( packsize );
62 MPI_Abort( MPI_COMM_WORLD, 1 );
64 MPI_Pack( inbufs[j], counts[j], types[j], packbuf, packsize,
65 &position, comms[i] );
67 MPI_Send( packbuf, position, MPI_PACKED, partner, tag, comms[i] );
68 MPI_Send( packbuf, position, MPI_PACKED, partner, tag, comms[i] );
71 else if (rank == np-1) {
74 for (k=0; k<bytesize[j]; k++)
76 /* Receive directly */
77 MPI_Recv( outbufs[j], counts[j], types[j], partner, tag, comms[i],
80 MPI_Get_count( &status, types[j], &count );
81 if (count != counts[j]) {
83 "Error in counts (got %d expected %d) with type %s\n",
84 count, counts[j], names[j] );
87 if (status.MPI_SOURCE != partner) {
89 "Error in source (got %d expected %d) with type %s\n",
90 status.MPI_SOURCE, partner, names[j] );
93 if ((errloc = CheckData( inbufs[j], outbufs[j], bytesize[j] ))) {
95 "Error in data at byte %d with type %s (type %d on %d)\n",
96 errloc - 1, names[j], j, world_rank );
99 /* Receive packed, then unpack */
100 MPI_Pack_size( counts[j], types[j], comms[i], &unpacksize );
101 unpackbuf = (char *)malloc( unpacksize );
103 MPI_Abort( MPI_COMM_WORLD, 1 );
104 MPI_Recv( unpackbuf, unpacksize, MPI_PACKED, partner, tag,
107 for (k=0; k<bytesize[j]; k++)
110 MPI_Get_count( &status, MPI_PACKED, &unpacksize );
111 MPI_Unpack( unpackbuf, unpacksize, &position,
112 outbufs[j], counts[j], types[j], comms[i] );
116 /* Length is tricky; a correct code will have signaled an error
119 if (count != counts[j]) {
121 "Error in counts (got %d expected %d) with type %s (Unpack)\n",
122 count, counts[j], names[j] );
126 if (status.MPI_SOURCE != partner) {
128 "Error in source (got %d expected %d) with type %s (Unpack)\n",
129 status.MPI_SOURCE, partner, names[j] );
132 if ((errloc = CheckData( inbufs[j], outbufs[j], bytesize[j] ))) {
134 "Error in data at byte %d with type %s (type %d on %d, Unpack)\n",
135 errloc - 1, names[j], j, world_rank );
142 fprintf( stderr, "%d errors on %d\n", err, rank );
144 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
145 if (world_rank == 0) {
147 printf( " No Errors\n" );
150 printf (" Found %d errors\n", toterr );
153 FreeDatatypes( types, inbufs, outbufs, counts, bytesize, names, ntype );
154 FreeComms( comms, ncomm );
155 MPI_Barrier( MPI_COMM_WORLD );