Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / sendrecv1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
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 "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Send-Recv";
13 */
14
15 int main( int argc, char *argv[] )
16 {
17     int errs = 0, err;
18     int rank, size, source, dest;
19     int minsize = 2, count; 
20     MPI_Comm      comm;
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
32         /* Determine the sender and receiver */
33         MPI_Comm_rank( comm, &rank );
34         MPI_Comm_size( comm, &size );
35         source = 0;
36         dest   = size - 1;
37
38         /* To improve reporting of problems about operations, we
39            change the error handler to errors return */
40         MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
41
42         for (count = 1; count < 65000; count = count * 2) {
43             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
44                 /* Make sure that everyone has a recv buffer */
45                 recvtype.InitBuf( &recvtype );
46
47                 if (rank == source) {
48                     sendtype.InitBuf( &sendtype );
49                     
50                     err = MPI_Send( sendtype.buf, sendtype.count, 
51                                     sendtype.datatype, dest, 0, comm);
52                     if (err) {
53                         errs++;
54                         if (errs < 10) {
55                             MTestPrintError( err );
56                         }
57                     }
58                 }
59                 else if (rank == dest) {
60                     err = MPI_Recv( recvtype.buf, recvtype.count, 
61                                     recvtype.datatype, source, 0, comm, MPI_STATUS_IGNORE);
62                     if (err) {
63                         errs++;
64                         if (errs < 10) {
65                             MTestPrintError( err );
66                         }
67                     }
68
69                     err = MTestCheckRecv( 0, &recvtype );
70                     if (err) {
71                         if (errs < 10) {
72                             printf( "Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n", 
73                                     MTestGetDatatypeName( &recvtype ),
74                                     MTestGetDatatypeName( &sendtype ),
75                                     count );
76                             recvtype.printErrors = 1;
77                             (void)MTestCheckRecv( 0, &recvtype );
78                         }
79                         errs += err;
80                     }
81                 }
82                 MTestFreeDatatype( &sendtype );
83                 MTestFreeDatatype( &recvtype );
84             }
85         }
86         MTestFreeComm( &comm );
87     }
88
89     MTest_Finalize( errs );
90     MPI_Finalize();
91     return 0;
92 }