Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
still not our
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / struct-no-real-types.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 "mpitest.h"
10 #include "mpitestconf.h"
11 #ifdef HAVE_STRING_H
12 #include <string.h>
13 #endif
14
15 /* 
16    The default behavior of the test routines should be to briefly indicate
17    the cause of any errors - in this test, that means that verbose needs
18    to be set. Verbose should turn on output that is independent of error
19    levels.
20 */
21 static int verbose = 1;
22
23 /* tests */
24 int no_real_types_test(void);
25
26 /* helper functions */
27 int parse_args(int argc, char **argv);
28
29 int main(int argc, char **argv)
30 {
31     int err, errs = 0;
32
33     MTest_Init(&argc, &argv);
34     parse_args(argc, argv);
35
36     /* To improve reporting of problems about operations, we
37        change the error handler to errors return */
38     MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
39
40     /* perform some tests */
41     err = no_real_types_test();
42     if (err && verbose) fprintf(stderr, "%d errors in blockindexed test.\n",
43                                 err);
44     errs += err;
45
46     MTest_Finalize( errs );
47     MPI_Finalize();
48     return 0;
49 }
50
51 /* no_real_types_test()
52  *
53  * Tests behavior with an empty struct type
54  *
55  * Returns the number of errors encountered.
56  */
57 int no_real_types_test(void)
58 {
59     int err, errs = 0;
60
61     int count = 1;
62     int len = 1;
63     MPI_Aint disp = 10;
64     MPI_Datatype type = MPI_LB;
65     MPI_Datatype newtype;
66
67     int size;
68     MPI_Aint extent;
69
70     err = MPI_Type_create_struct(count,
71                                  &len,
72                                  &disp,
73                                  &type,
74                                  &newtype);
75     if (err != MPI_SUCCESS) {
76         if (verbose) {
77             fprintf(stderr,
78                     "error creating struct type no_real_types_test()\n");
79         }
80         MTestPrintError( err );
81         errs++;
82     }
83
84     err = MPI_Type_size(newtype, &size);
85     if (err != MPI_SUCCESS) {
86         if (verbose) {
87             fprintf(stderr,
88                     "error obtaining type size in no_real_types_test()\n");
89         }
90         MTestPrintError( err );
91         errs++;
92     }
93     
94     if (size != 0) {
95         if (verbose) {
96             fprintf(stderr,
97                     "error: size != 0 in no_real_types_test()\n");
98         }
99         errs++;
100     }    
101
102     err = MPI_Type_extent(newtype, &extent);
103     if (err != MPI_SUCCESS) {
104         if (verbose) {
105             fprintf(stderr,
106                     "error obtaining type extent in no_real_types_test()\n");
107         }
108         MTestPrintError( err );
109         errs++;
110     }
111     
112     if (extent != -10) {
113         if (verbose) {
114             fprintf(stderr,
115                     "error: extent is %ld but should be -10 in no_real_types_test()\n", 
116                     (long) extent );
117             fprintf( stderr, 
118              "type map is { (LB,10) }, so UB is 0 and extent is ub-lb\n" );
119         }
120         errs++;
121     }    
122
123     MPI_Type_free( &newtype );
124
125     return errs;
126 }
127
128
129 int parse_args(int argc, char **argv)
130 {
131     /*
132     int ret;
133
134     while ((ret = getopt(argc, argv, "v")) >= 0)
135     {
136         switch (ret) {
137             case 'v':
138                 verbose = 1;
139                 break;
140         }
141     }
142     */
143     if (argc > 1 && strcmp(argv[1], "-v") == 0)
144         verbose = 1;
145     return 0;
146 }
147