Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_Abort can theorically fail. Add a call to exit() to ensure that the program...
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / bottom.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[] = "Use of MPI_BOTTOM in communication";
13 */
14
15 int main( int argc, char *argv[] )
16 {
17     int errs = 0, err;
18     int rank, size, source, dest, len, ii;
19     MPI_Comm      comm;
20     MPI_Status    status;
21     MPI_Datatype  newtype, oldtype;
22     MPI_Aint      disp;
23
24     MTest_Init( &argc, &argv );
25
26     MPI_Get_address( &ii, &disp );
27
28     len     = 1;
29     oldtype = MPI_INT;
30     MPI_Type_create_struct( 1, &len, &disp, &oldtype, &newtype );
31     MPI_Type_commit( &newtype );
32
33     comm = MPI_COMM_WORLD;
34
35     MPI_Comm_size( comm, &size );
36     MPI_Comm_rank( comm, &rank );
37
38     if (size < 2) {
39         errs++;
40         fprintf( stderr, "This test requires at least two processes\n" );
41         MPI_Abort( MPI_COMM_WORLD, 1 );
42         exit(1);
43     }
44     source = 0;
45     dest = 1;
46
47     /* To improve reporting of problems about operations, we
48        change the error handler to errors return */
49     MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
50
51     if (rank == source) {
52         ii = 2;
53         err = MPI_Send( MPI_BOTTOM, 1, newtype, dest, 0, comm );
54         if (err) {
55             errs++;
56             MTestPrintError( err );
57             printf( "MPI_Send did not return MPI_SUCCESS\n" );
58         }
59     }
60     else if (rank == dest) {
61         ii = -1;
62         err = MPI_Recv( MPI_BOTTOM, 1, newtype, source, 0, comm, &status );
63         if (err) {
64             MTestPrintError( err );
65             errs++;
66             printf( "MPI_Recv did not return MPI_SUCCESS\n" );
67         }
68         if (ii != 2) {
69             errs++;
70             printf( "Received %d but expected %d\n", ii, 2 );
71         }
72     }
73
74     MPI_Comm_set_errhandler( comm, MPI_ERRORS_ARE_FATAL );
75
76     MPI_Type_free( &newtype );
77
78     MTest_Finalize( errs );
79     MPI_Finalize();
80     return 0;
81 }