Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge msg_vm.c - adrien (please note that there is one line (destruction of the tx_pr...
[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         { int nkeys;
57         MPI_Info_get_nkeys( infos[0], &nkeys );
58         if (nkeys != info_list) {
59             printf( "infos[0] changed at %d info\n", i );}
60         }
61 #endif
62     }
63
64     /* Delete the middle set */
65     for (i=MAX_INFOS/3; i<(2*MAX_INFOS/3); i++) {
66         MPI_Info_free( &infos[i] );
67     }
68     
69     /* Recreate the middle set */
70     for (i=MAX_INFOS/3; i<(2*MAX_INFOS/3); i++) {
71         MPI_Info_create( &infos[i] );
72         DBGPRINTF( ( "Info handle is %x\n", infos[i] ) );
73         for (j=0; j<info_list; j++) {
74             sprintf( key, "key%d-%d", i, j );
75             sprintf( value, "value%d-%d", i, j );
76             DBGPRINTF( ( "Creating key/value %s=%s\n", key, value ));
77             MPI_Info_set( infos[i], key, value );
78         }
79     }
80
81     /* Now, check that they are still valid */
82     for (i=0; i<MAX_INFOS; i++) {
83         int nkeys;
84         /*printf( "info = %x\n", infos[i] );
85           print_handle( infos[i] ); printf( "\n" );*/
86         MPI_Info_get_nkeys( infos[i], &nkeys );
87         if (nkeys != info_list) {
88             errs++;
89             if (errs < MAX_ERRORS) {
90                 printf( "Wrong number of keys for info %d; got %d, should be %d\n",
91                         i, nkeys, info_list );
92             }
93         }
94         for (j=0; j<nkeys; j++) {
95             char keystr[64];
96             char valstr[64];
97             int  flag;
98             MPI_Info_get_nthkey( infos[i], j, key );
99             sprintf( keystr, "key%d-%d", i, j );
100             if (strcmp( keystr, key ) != 0) {
101                 errs++;
102                 if (errs < MAX_ERRORS) {
103                     printf( "Wrong key for info %d; got %s expected %s\n", 
104                             i, key, keystr );
105                 }
106                 continue;
107             }
108             MPI_Info_get( infos[i], key, 64, value, &flag );
109             if (!flag) {
110                 errs++;
111                 if (errs < MAX_ERRORS) {
112                     printf( "Get failed to return value for info %d\n", i );
113                 }
114                 continue;
115             }
116             sprintf( valstr, "value%d-%d", i, j );
117             if (strcmp( valstr, value ) != 0) {
118                 errs++;
119                 if (errs < MAX_ERRORS) {
120                     printf( "Wrong value for info %d; got %s expected %s\n",
121                             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 }