Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 tests for MPI_Info calls.
[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         { int nkeys;
47         MPI_Info_get_nkeys( infos[0], &nkeys );
48         if (nkeys != info_list) {
49             printf( "infos[0] changed at %d info\n", i );}
50         }
51 #endif
52     }
53     
54     for (i=0; i<MAX_INFOS; i++) {
55         int nkeys;
56         /*printf( "info = %x\n", infos[i] );
57           print_handle( infos[i] ); printf( "\n" );*/
58         MPI_Info_get_nkeys( infos[i], &nkeys );
59         if (nkeys != info_list) {
60             errs++;
61             if (errs < MAX_ERRORS) {
62                 printf( "Wrong number of keys for info %d; got %d, should be %d\n",
63                         i, nkeys, info_list );
64             }
65         }
66         for (j=0; j<nkeys; j++) {
67             char keystr[64];
68             char valstr[64];
69             int  flag;
70             MPI_Info_get_nthkey( infos[i], j, key );
71             sprintf( keystr, "key%d-%d", i, j );
72             if (strcmp( keystr, key ) != 0) {
73                 errs++;
74                 if (errs < MAX_ERRORS) {
75                     printf( "Wrong key for info %d; got %s expected %s\n", 
76                             i, key, keystr );
77                 }
78                 continue;
79             }
80             MPI_Info_get( infos[i], key, sizeof(value), value, &flag );
81             if (!flag) {
82                 errs++;
83                 if (errs < MAX_ERRORS) {
84                     printf( "Get failed to return value for info %d\n", i );
85                 }
86                 continue;
87             }
88             sprintf( valstr, "value%d-%d", i, j );
89             if (strcmp( valstr, value ) != 0) {
90                 errs++;
91                 if (errs < MAX_ERRORS) {
92                     printf( "Wrong value for info %d; got %s expected %s\n",
93                             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 }