Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / get-elements-pairtype.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 static int verbose = 0;
12
13 /* tests */
14 int double_int_test(void);
15
16 /* helper functions */
17 int parse_args(int argc, char **argv);
18
19 int main(int argc, char **argv)
20 {
21     int err, errs = 0;
22
23     MPI_Init(&argc, &argv);     /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
24     parse_args(argc, argv);
25
26     /* To improve reporting of problems about operations, we
27      * change the error handler to errors return */
28     MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
29
30     /* perform some tests */
31     err = double_int_test();
32     if (err && verbose)
33         fprintf(stderr, "%d errors in double_int test.\n", err);
34     errs += err;
35
36     /* print message and exit */
37     if (errs) {
38         fprintf(stderr, "Found %d errors\n", errs);
39     }
40     else {
41         printf(" No Errors\n");
42     }
43     MPI_Finalize();
44     return 0;
45 }
46
47 /* send a { double, int, double} tuple and receive as a pair of
48  * MPI_DOUBLE_INTs. this should (a) be valid, and (b) result in an
49  * element count of 3.
50  */
51 int double_int_test(void)
52 {
53     int err, errs = 0, count;
54
55     struct {
56         double a;
57         int b;
58         double c;
59     } foo;
60     struct {
61         double a;
62         int b;
63         double c;
64         int d;
65     } bar;
66
67     int blks[3] = { 1, 1, 1 };
68     MPI_Aint disps[3] = { 0, 0, 0 };
69     MPI_Datatype types[3] = { MPI_DOUBLE, MPI_INT, MPI_DOUBLE };
70     MPI_Datatype stype;
71
72     MPI_Status recvstatus;
73
74     /* fill in disps[1..2] with appropriate offset */
75     disps[1] = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
76     disps[2] = (MPI_Aint) ((char *) &foo.c - (char *) &foo.a);
77
78     MPI_Type_create_struct(3, blks, disps, types, &stype);
79     MPI_Type_commit(&stype);
80
81     err = MPI_Sendrecv((const void *) &foo, 1, stype, 0, 0,
82                        (void *) &bar, 2, MPI_DOUBLE_INT, 0, 0, MPI_COMM_SELF, &recvstatus);
83     if (err != MPI_SUCCESS) {
84         errs++;
85         if (verbose)
86             fprintf(stderr, "MPI_Sendrecv returned error (%d)\n", err);
87         return errs;
88     }
89
90     err = MPI_Get_elements(&recvstatus, MPI_DOUBLE_INT, &count);
91     if (err != MPI_SUCCESS) {
92         errs++;
93         if (verbose)
94             fprintf(stderr, "MPI_Get_elements returned error (%d)\n", err);
95     }
96
97     if (count != 3) {
98         errs++;
99         if (verbose)
100             fprintf(stderr, "MPI_Get_elements returned count of %d, should be 3\n", count);
101     }
102
103     MPI_Type_free(&stype);
104
105     return errs;
106 }
107
108 int parse_args(int argc, char **argv)
109 {
110     if (argc > 1 && strcmp(argv[1], "-v") == 0)
111         verbose = 1;
112     return 0;
113 }