Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / info / infomany.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 */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11 #include "mpitestconf.h"
12 #ifdef HAVE_STRING_H
13 #include <string.h>
14 #endif
15
16 #ifndef MAX_INFOS
17 #define MAX_INFOS 4000
18 #endif
19 #define MAX_ERRORS 10
20 #define info_list 16
21 /* #define DBG  */
22
23 int main(int argc, char *argv[])
24 {
25     MPI_Info infos[MAX_INFOS];
26     char key[64], value[64];
27     int errs = 0;
28     int i, j;
29
30     MTest_Init(&argc, &argv);
31
32     for (i = 0; i < MAX_INFOS; i++) {
33         MPI_Info_create(&infos[i]);
34 #ifdef DBG
35         printf("Info handle is %x\n", infos[i]);
36 #endif
37         for (j = 0; j < info_list; j++) {
38             sprintf(key, "key%d-%d", i, j);
39             sprintf(value, "value%d-%d", i, j);
40 #ifdef DBG
41             printf("Creating key/value %s=%s\n", key, value);
42 #endif
43             MPI_Info_set(infos[i], key, value);
44         }
45 #ifdef DBG
46         {
47             int nkeys;
48             MPI_Info_get_nkeys(infos[0], &nkeys);
49             if (nkeys != info_list) {
50                 printf("infos[0] changed at %d info\n", i);
51             }
52         }
53 #endif
54     }
55
56     for (i = 0; i < MAX_INFOS; i++) {
57         int nkeys;
58         /*printf("info = %x\n", infos[i]);
59          * print_handle(infos[i]); printf("\n"); */
60         MPI_Info_get_nkeys(infos[i], &nkeys);
61         if (nkeys != info_list) {
62             errs++;
63             if (errs < MAX_ERRORS) {
64                 printf("Wrong number of keys for info %d; got %d, should be %d\n",
65                        i, nkeys, info_list);
66             }
67         }
68         for (j = 0; j < nkeys; j++) {
69             char keystr[64];
70             char valstr[64];
71             int flag;
72             MPI_Info_get_nthkey(infos[i], j, key);
73             sprintf(keystr, "key%d-%d", i, j);
74             if (strcmp(keystr, key) != 0) {
75                 errs++;
76                 if (errs < MAX_ERRORS) {
77                     printf("Wrong key for info %d; got %s expected %s\n", i, key, keystr);
78                 }
79                 continue;
80             }
81             MPI_Info_get(infos[i], key, sizeof(value), value, &flag);
82             if (!flag) {
83                 errs++;
84                 if (errs < MAX_ERRORS) {
85                     printf("Get failed to return value for info %d\n", i);
86                 }
87                 continue;
88             }
89             sprintf(valstr, "value%d-%d", i, j);
90             if (strcmp(valstr, value) != 0) {
91                 errs++;
92                 if (errs < MAX_ERRORS) {
93                     printf("Wrong value for info %d; got %s expected %s\n", i, value, valstr);
94                 }
95             }
96         }
97     }
98     for (i = 0; i < MAX_INFOS; i++) {
99         MPI_Info_free(&infos[i]);
100     }
101
102     MTest_Finalize(errs);
103     MPI_Finalize();
104     return 0;
105 }