Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix f77 tests
[simgrid.git] / teshsuite / smpi / mpich3-test / info / infomany2.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 /* Test of info that makes use of the extended handles, including
7    inserts and deletes */
8 #include "mpi.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "mpitest.h"
12 #include "mpitestconf.h"
13 #ifdef HAVE_STRING_H
14 #include <string.h>
15 #endif
16
17 #ifndef MAX_INFOS
18 #define MAX_INFOS 4000
19 #endif
20 #define MAX_ERRORS 10
21 #define info_list 16
22 /* #define DBG  */
23
24 #ifdef DEBUG
25 #define DBGPRINTF(a) printf a; fflush(stdout)
26 #else
27 #define DBGPRINTF(a)
28 #endif
29
30 int main(int argc, char *argv[])
31 {
32     MPI_Info infos[MAX_INFOS];
33     char key[64], value[64];
34     int errs = 0;
35     int i, j;
36
37     MTest_Init(&argc, &argv);
38
39     /* We create max_info items, then delete the middle third of them,
40      * then recreate them, then check them, then
41      * delete them all.  This checks that the MPICH algorithm for
42      * handling large numbers of items works correctly; other MPI
43      * implementations should also be able to handle this */
44
45     /* Create them all */
46     for (i = 0; i < MAX_INFOS; i++) {
47         MPI_Info_create(&infos[i]);
48         DBGPRINTF(("Info handle is %x\n", infos[i]));
49         for (j = 0; j < info_list; j++) {
50             sprintf(key, "key%d-%d", i, j);
51             sprintf(value, "value%d-%d", i, j);
52             DBGPRINTF(("Creating key/value %s=%s\n", key, value));
53             MPI_Info_set(infos[i], key, value);
54         }
55 #ifdef DBG
56         {
57             int nkeys;
58             MPI_Info_get_nkeys(infos[0], &nkeys);
59             if (nkeys != info_list) {
60                 printf("infos[0] changed at %d info\n", i);
61             }
62         }
63 #endif
64     }
65
66     /* Delete the middle set */
67     for (i = MAX_INFOS / 3; i < (2 * MAX_INFOS / 3); i++) {
68         MPI_Info_free(&infos[i]);
69     }
70
71     /* Recreate the middle set */
72     for (i = MAX_INFOS / 3; i < (2 * MAX_INFOS / 3); i++) {
73         MPI_Info_create(&infos[i]);
74         DBGPRINTF(("Info handle is %x\n", infos[i]));
75         for (j = 0; j < info_list; j++) {
76             sprintf(key, "key%d-%d", i, j);
77             sprintf(value, "value%d-%d", i, j);
78             DBGPRINTF(("Creating key/value %s=%s\n", key, value));
79             MPI_Info_set(infos[i], key, value);
80         }
81     }
82
83     /* Now, check that they are still valid */
84     for (i = 0; i < MAX_INFOS; i++) {
85         int nkeys;
86         /*printf("info = %x\n", infos[i]);
87          * print_handle(infos[i]); printf("\n"); */
88         MPI_Info_get_nkeys(infos[i], &nkeys);
89         if (nkeys != info_list) {
90             errs++;
91             if (errs < MAX_ERRORS) {
92                 printf("Wrong number of keys for info %d; got %d, should be %d\n",
93                        i, nkeys, info_list);
94             }
95         }
96         for (j = 0; j < nkeys; j++) {
97             char keystr[64];
98             char valstr[64];
99             int flag;
100             MPI_Info_get_nthkey(infos[i], j, key);
101             sprintf(keystr, "key%d-%d", i, j);
102             if (strcmp(keystr, key) != 0) {
103                 errs++;
104                 if (errs < MAX_ERRORS) {
105                     printf("Wrong key for info %d; got %s expected %s\n", i, key, keystr);
106                 }
107                 continue;
108             }
109             MPI_Info_get(infos[i], key, 64, value, &flag);
110             if (!flag) {
111                 errs++;
112                 if (errs < MAX_ERRORS) {
113                     printf("Get failed to return value for info %d\n", i);
114                 }
115                 continue;
116             }
117             sprintf(valstr, "value%d-%d", i, j);
118             if (strcmp(valstr, value) != 0) {
119                 errs++;
120                 if (errs < MAX_ERRORS) {
121                     printf("Wrong value for info %d; got %s expected %s\n", i, value, valstr);
122                 }
123             }
124         }
125     }
126     for (i = 0; i < MAX_INFOS; i++) {
127         MPI_Info_free(&infos[i]);
128     }
129
130     MTest_Finalize(errs);
131     MPI_Finalize();
132     return 0;
133 }