Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
still not our
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / blockindexed-zero-count.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 "mpitestconf.h"
10 #ifdef HAVE_STRING_H
11 #include <string.h>
12 #endif
13
14 static int verbose = 0;
15
16 /* tests */
17 int blockindexed_test(void);
18
19 /* helper functions */
20 int parse_args(int argc, char **argv);
21
22 int main(int argc, char **argv)
23 {
24     int err, errs = 0;
25
26     MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
27     parse_args(argc, argv);
28
29     /* To improve reporting of problems about operations, we
30        change the error handler to errors return */
31     MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
32
33     /* perform some tests */
34     err = blockindexed_test();
35     if (err && verbose) fprintf(stderr, "%d errors in blockindexed test.\n",
36                                 err);
37     errs += err;
38
39     /* print message and exit */
40     if (errs) {
41         fprintf(stderr, "Found %d errors\n", errs);
42     }
43     else {
44         printf(" No Errors\n");
45     }
46     MPI_Finalize();
47     return 0;
48 }
49
50 /* blockindexed_test()
51  *
52  * Tests behavior with a zero-count blockindexed.
53  *
54  * Returns the number of errors encountered.
55  */
56 int blockindexed_test(void)
57 {
58     int err, errs = 0;
59
60     int count = 0;
61     MPI_Datatype newtype;
62
63     int size;
64     MPI_Aint extent;
65
66     err = MPI_Type_create_indexed_block(count,
67                                         0,
68                                         (int *) 0,
69                                         MPI_INT,
70                                         &newtype);
71     if (err != MPI_SUCCESS) {
72         if (verbose) {
73             fprintf(stderr,
74                     "error creating struct type in blockindexed_test()\n");
75         }
76         errs++;
77     }
78
79     err = MPI_Type_size(newtype, &size);
80     if (err != MPI_SUCCESS) {
81         if (verbose) {
82             fprintf(stderr,
83                     "error obtaining type size in blockindexed_test()\n");
84         }
85         errs++;
86     }
87     
88     if (size != 0) {
89         if (verbose) {
90             fprintf(stderr,
91                     "error: size != 0 in blockindexed_test()\n");
92         }
93         errs++;
94     }    
95
96     err = MPI_Type_extent(newtype, &extent);
97     if (err != MPI_SUCCESS) {
98         if (verbose) {
99             fprintf(stderr,
100                     "error obtaining type extent in blockindexed_test()\n");
101         }
102         errs++;
103     }
104     
105     if (extent != 0) {
106         if (verbose) {
107             fprintf(stderr,
108                     "error: extent != 0 in blockindexed_test()\n");
109         }
110         errs++;
111     }    
112
113     MPI_Type_free( &newtype );
114
115     return errs;
116 }
117
118
119 int parse_args(int argc, char **argv)
120 {
121     /*
122     int ret;
123
124     while ((ret = getopt(argc, argv, "v")) >= 0)
125     {
126         switch (ret) {
127             case 'v':
128                 verbose = 1;
129                 break;
130         }
131     }
132     */
133     if (argc > 1 && strcmp(argv[1], "-v") == 0)
134         verbose = 1;
135     return 0;
136 }
137