Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename some symbols around Link::isShared to make their purpose clear
[simgrid.git] / teshsuite / smpi / mpich3-test / info / infodup.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
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 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     MPI_Info info1, infodup;
20     int nkeys, nkeysdup, i, vallen, flag, flagdup;
21     char key[MPI_MAX_INFO_KEY], keydup[MPI_MAX_INFO_KEY];
22     char value[MPI_MAX_INFO_VAL], valdup[MPI_MAX_INFO_VAL];
23
24     MTest_Init( &argc, &argv );
25
26     MPI_Info_create( &info1 );
27     /* Use only named keys incase the info implementation only supports
28        the predefined keys (e.g., IBM) */
29     MPI_Info_set( info1, (char*)"host", (char*)"myhost.myorg.org" );
30     MPI_Info_set( info1, (char*)"file", (char*)"runfile.txt" );
31     MPI_Info_set( info1, (char*)"soft", (char*)"2:1000:4,3:1000:7" );
32
33     MPI_Info_dup( info1, &infodup );
34
35     MPI_Info_get_nkeys( infodup, &nkeysdup );
36     MPI_Info_get_nkeys( info1, &nkeys );
37     if (nkeys != nkeysdup) {
38         errs++;
39         printf( "Dup'ed info has a different number of keys; is %d should be %d\n",
40                 nkeysdup, nkeys );
41     }
42     vallen = MPI_MAX_INFO_VAL;
43     for (i=0; i<nkeys; i++) {
44         /* MPI requires that the keys are in the same order after the dup */
45         MPI_Info_get_nthkey( info1, i, key );
46         MPI_Info_get_nthkey( infodup, i, keydup );
47         if (strcmp(key, keydup)) {
48             errs++;
49             printf( "keys do not match: %s should be %s\n", keydup, key );
50         }
51
52         vallen = MPI_MAX_INFO_VAL;
53         MPI_Info_get( info1, key, vallen, value, &flag );
54         MPI_Info_get( infodup, keydup, vallen, valdup, &flagdup );
55         if (!flag || !flagdup) {
56             errs++;
57             printf( "Info get failed for key %s\n", key );
58         }
59         else if (strcmp( value, valdup )) {
60             errs++;
61             printf( "Info values for key %s not the same after dup\n", key );
62         }
63     }
64
65     /* Change info and check that infodup does NOT have the new value 
66        (ensure that lazy dups are still duped) */
67     MPI_Info_set( info1, (char*)"path", (char*)"/a:/b:/c/d" );
68
69     MPI_Info_get( infodup, (char*)"path", vallen, value, &flag );
70     if (flag) {
71         errs++;
72         printf( "inserting path into info changed infodup\n" );
73     }
74     
75     MPI_Info_free( &info1 );
76     MPI_Info_free( &infodup );
77     
78     MTest_Finalize( errs );
79     MPI_Finalize();
80     return 0;
81   
82 }