1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11 
12 static char MTEST_Descrip[] = "";
13 
main(int argc,char * argv[])14 int main( int argc, char *argv[] )
15 {
16     int errs = 0, err;
17     int rank, size, source, dest;
18     int minsize = 2, count;
19     MPI_Comm      comm;
20     MPI_Status    status;
21     MTestDatatype sendtype, recvtype;
22 
23     MTest_Init( &argc, &argv );
24 
25     /* The following illustrates the use of the routines to
26        run through a selection of communicators and datatypes.
27        Use subsets of these for tests that do not involve combinations
28        of communicators, datatypes, and counts of datatypes */
29     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
30 	if (comm == MPI_COMM_NULL) continue;
31 	/* Determine the sender and receiver */
32 	MPI_Comm_rank( comm, &rank );
33 	MPI_Comm_size( comm, &size );
34 	source = 0;
35 	dest   = size - 1;
36 
37 	/* To improve reporting of problems about operations, we
38 	   change the error handler to errors return */
39 	MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
40 
41 	for (count = 1; count < 65000; count = count * 2) {
42 	    while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
43 		if (rank == source) {
44 		    sendtype.InitBuf( &sendtype );
45 
46 		    err = MPI_Send( sendtype.buf, sendtype.count,
47 				    sendtype.datatype, dest, 0, comm );
48 		    if (err) {
49 			errs++;
50 			MTestPrintError( err );
51 		    }
52 		    MTestFreeDatatype( &sendtype );
53 		}
54 		else if (rank == dest) {
55 		    recvtype.InitBuf( &recvtype );
56 		    err = MPI_Recv( recvtype.buf, recvtype.count,
57 				    recvtype.datatype, source, 0, comm, &status );
58 		    if (err) {
59 			errs++;
60 			fprintf( stderr, "Error with communicator %s and datatype %s\n",
61 				 MTestGetIntracommName(),
62 				 MTestGetDatatypeName( &recvtype ) );
63 			MTestPrintError( err );
64 		    }
65 		    err = MTestCheckRecv( &status, &recvtype );
66 		    if (err) {
67 			errs += errs;
68 		    }
69 		    MTestFreeDatatype( &recvtype );
70 		}
71 	    }
72 	}
73 	MTestFreeComm( &comm );
74     }
75 
76     MTest_Finalize( errs );
77     MPI_Finalize();
78     return 0;
79 }
80