Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[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     }
43     source = 0;
44     dest = 1;
45
46     /* To improve reporting of problems about operations, we
47      * change the error handler to errors return */
48     MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
49
50     if (rank == source) {
51         ii = 2;
52         err = MPI_Send(MPI_BOTTOM, 1, newtype, dest, 0, comm);
53         if (err) {
54             errs++;
55             MTestPrintError(err);
56             printf("MPI_Send did not return MPI_SUCCESS\n");
57         }
58     }
59     else if (rank == dest) {
60         ii = -1;
61         err = MPI_Recv(MPI_BOTTOM, 1, newtype, source, 0, comm, &status);
62         if (err) {
63             MTestPrintError(err);
64             errs++;
65             printf("MPI_Recv did not return MPI_SUCCESS\n");
66         }
67         if (ii != 2) {
68             errs++;
69             printf("Received %d but expected %d\n", ii, 2);
70         }
71     }
72
73     MPI_Comm_set_errhandler(comm, MPI_ERRORS_ARE_FATAL);
74
75     MPI_Type_free(&newtype);
76
77     MTest_Finalize(errs);
78     MPI_Finalize();
79     return 0;
80 }