Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix HAVE_FOOBAR flags handling
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / contig-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 contig_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 = contig_test();
35     if (err && verbose) fprintf(stderr, "%d errors in contig 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 /* contig_test()
51  *
52  * Tests behavior with a zero-count contig.
53  *
54  * Returns the number of errors encountered.
55  */
56 int contig_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_contiguous(count,
67                              MPI_INT,
68                              &newtype);
69     if (err != MPI_SUCCESS) {
70         if (verbose) {
71             fprintf(stderr,
72                     "error creating type in contig_test()\n");
73         }
74         errs++;
75     }
76
77     err = MPI_Type_size(newtype, &size);
78     if (err != MPI_SUCCESS) {
79         if (verbose) {
80             fprintf(stderr,
81                     "error obtaining type size in contig_test()\n");
82         }
83         errs++;
84     }
85     
86     if (size != 0) {
87         if (verbose) {
88             fprintf(stderr,
89                     "error: size != 0 in contig_test()\n");
90         }
91         errs++;
92     }    
93
94     err = MPI_Type_extent(newtype, &extent);
95     if (err != MPI_SUCCESS) {
96         if (verbose) {
97             fprintf(stderr,
98                     "error obtaining type extent in contig_test()\n");
99         }
100         errs++;
101     }
102     
103     if (extent != 0) {
104         if (verbose) {
105             fprintf(stderr,
106                     "error: extent != 0 in contig_test()\n");
107         }
108         errs++;
109     }    
110
111     MPI_Type_free( &newtype );
112
113     return errs;
114 }
115
116
117 int parse_args(int argc, char **argv)
118 {
119     /*
120     int ret;
121
122     while ((ret = getopt(argc, argv, "v")) >= 0)
123     {
124         switch (ret) {
125             case 'v':
126                 verbose = 1;
127                 break;
128         }
129     }
130     */
131     if (argc > 1 && strcmp(argv[1], "-v") == 0)
132         verbose = 1;
133     return 0;
134 }
135