Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
this tests actually does not conform to the standard and crashed now, but it's OK...
[simgrid.git] / teshsuite / smpi / mpich3-test / attr / baseattr2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2001 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <stdio.h>
8 #include "mpi.h"
9 #include "mpitest.h"
10
11 void MissingKeyval(int rc, const char keyname[]);
12
13 int main(int argc, char **argv)
14 {
15     int errs = 0;
16     int rc;
17     void *v;
18     int flag;
19     int vval;
20     int rank, size;
21
22     MTest_Init(&argc, &argv);
23     MPI_Comm_size(MPI_COMM_WORLD, &size);
24     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25
26     /* Set errors return so that we can provide better information
27      * should a routine reject one of the attribute values */
28     MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
29
30     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &v, &flag);
31     if (rc) {
32         MissingKeyval(rc, "MPI_TAG_UB");
33         errs++;
34     }
35     else {
36         if (!flag) {
37             errs++;
38             fprintf(stderr, "Could not get TAG_UB\n");
39         }
40         else {
41             vval = *(int *) v;
42             if (vval < 32767) {
43                 errs++;
44                 fprintf(stderr, "Got too-small value (%d) for TAG_UB\n", vval);
45             }
46         }
47     }
48
49     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_HOST, &v, &flag);
50     if (rc) {
51         MissingKeyval(rc, "MPI_HOST");
52         errs++;
53     }
54     else {
55         if (!flag) {
56             errs++;
57             fprintf(stderr, "Could not get HOST\n");
58         }
59         else {
60             vval = *(int *) v;
61             if ((vval < 0 || vval >= size) && vval != MPI_PROC_NULL) {
62                 errs++;
63                 fprintf(stderr, "Got invalid value %d for HOST\n", vval);
64             }
65         }
66     }
67
68     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_IO, &v, &flag);
69     if (rc) {
70         MissingKeyval(rc, "MPI_IO");
71         errs++;
72     }
73     else {
74         if (!flag) {
75             errs++;
76             fprintf(stderr, "Could not get IO\n");
77         }
78         else {
79             vval = *(int *) v;
80             if ((vval < 0 || vval >= size) && vval != MPI_ANY_SOURCE && vval != MPI_PROC_NULL) {
81                 errs++;
82                 fprintf(stderr, "Got invalid value %d for IO\n", vval);
83             }
84         }
85     }
86
87     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag);
88     if (rc) {
89         MissingKeyval(rc, "MPI_WTIME_IS_GLOBAL");
90         errs++;
91     }
92     else {
93         if (flag) {
94             /* Wtime need not be set */
95             vval = *(int *) v;
96             if (vval < 0 || vval > 1) {
97                 errs++;
98                 fprintf(stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n", vval);
99             }
100         }
101     }
102
103     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_APPNUM, &v, &flag);
104     if (rc) {
105         MissingKeyval(rc, "MPI_APPNUM");
106         errs++;
107     }
108     else {
109         /* appnum need not be set */
110         if (flag) {
111             vval = *(int *) v;
112             if (vval < 0) {
113                 errs++;
114                 fprintf(stderr, "MPI_APPNUM is defined as %d but must be nonnegative\n", vval);
115             }
116         }
117     }
118
119     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &v, &flag);
120     if (rc) {
121         MissingKeyval(rc, "MPI_UNIVERSE_SIZE");
122         errs++;
123     }
124     else {
125         /* MPI_UNIVERSE_SIZE need not be set */
126         if (flag) {
127             vval = *(int *) v;
128             if (vval < size) {
129                 errs++;
130                 fprintf(stderr, "MPI_UNIVERSE_SIZE = %d, less than comm world (%d)\n", vval, size);
131             }
132         }
133     }
134
135     rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_LASTUSEDCODE, &v, &flag);
136     if (rc) {
137         MissingKeyval(rc, "MPI_LASTUSEDCODE");
138         errs++;
139     }
140     else {
141         /* Last used code must be defined and >= MPI_ERR_LASTCODE */
142         if (flag) {
143             vval = *(int *) v;
144             if (vval < MPI_ERR_LASTCODE) {
145                 errs++;
146                 fprintf(stderr,
147                         "MPI_LASTUSEDCODE points to an integer (%d) smaller than MPI_ERR_LASTCODE (%d)\n",
148                         vval, MPI_ERR_LASTCODE);
149             }
150         }
151         else {
152             errs++;
153             fprintf(stderr, "MPI_LASTUSECODE is not defined\n");
154         }
155     }
156
157     MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
158
159     MTest_Finalize(errs);
160     MPI_Finalize();
161
162     return 0;
163 }
164
165 void MissingKeyval(int errcode, const char keyname[])
166 {
167     int errclass, slen;
168     char string[MPI_MAX_ERROR_STRING];
169
170     MPI_Error_class(errcode, &errclass);
171     MPI_Error_string(errcode, string, &slen);
172     printf("For key %s: Error class %d (%s)\n", keyname, errclass, string);
173     fflush(stdout);
174 }