Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a62f362789c26182936721058b8451223adb5538
[simgrid.git] / teshsuite / smpi / mpich3-test / info / infodel.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 #define NKEYS 3
17 int main( int argc, char *argv[] )
18 {
19     int errs = 0;
20     MPI_Info info;
21     char *keys[NKEYS] = { (char*)"file", (char*)"soft", (char*)"host" };
22     char *values[NKEYS] = { (char*)"runfile.txt", (char*)"2:1000:4,3:1000:7", 
23                             (char*)"myhost.myorg.org" };
24     char value[MPI_MAX_INFO_VAL];
25     int i, flag, nkeys;
26
27     MTest_Init( &argc, &argv );
28
29     MPI_Info_create( &info );
30     /* Use only named keys incase the info implementation only supports
31        the predefined keys (e.g., IBM) */
32     for (i=0; i<NKEYS; i++) {
33         MPI_Info_set( info, keys[i], values[i] );
34     }
35
36     /* Check that all values are present */
37     for (i=0; i<NKEYS; i++) { 
38         MPI_Info_get( info, keys[i], MPI_MAX_INFO_VAL, value, &flag );
39         if (!flag) {
40             errs++;
41             printf( "No value for key %s\n", keys[i] );
42         }
43         if (strcmp( value, values[i] )) {
44             errs++;
45             printf( "Incorrect value for key %s, got %s expected %s\n", 
46                     keys[i], value, values[i] );
47         }
48     }
49
50     /* Now, change one value and remove another, then check again */
51     MPI_Info_delete( info, keys[NKEYS-1] );
52     MPI_Info_get_nkeys( info, &nkeys );
53     if (nkeys != NKEYS - 1) {
54         errs++;
55         printf( "Deleting a key did not change the number of keys\n" );
56     }
57
58     values[0] = (char*)"backfile.txt";
59     MPI_Info_set( info, keys[0], values[0] );
60     for (i=0; i<NKEYS-1; i++) {
61         MPI_Info_get( info, keys[i], MPI_MAX_INFO_VAL, value, &flag );
62         if (!flag) {
63             errs++;
64             printf( "(after reset) No value for key %s\n", keys[i] );
65         }
66         if (strcmp( value, values[i] )) {
67             errs++;
68             printf( "(after reset) Incorrect value for key %s, got %s expected %s\n", 
69                     keys[i], value, values[i] );
70         }
71     }
72
73     MPI_Info_free( &info );
74     if (info != MPI_INFO_NULL) {
75         errs++;
76         printf( "MPI_Info_free should set info to MPI_INFO_NULL\n" );
77     }
78
79     MTest_Finalize( errs );
80     MPI_Finalize();
81     return 0;
82   
83 }