Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_INFO_ENV ... Still does nothing for now
[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     };
25     char value[MPI_MAX_INFO_VAL];
26     int i, flag, nkeys;
27
28     MTest_Init(&argc, &argv);
29
30     MPI_Info_create(&info);
31     /* Use only named keys incase the info implementation only supports
32      * the predefined keys (e.g., IBM) */
33     for (i = 0; i < NKEYS; i++) {
34         MPI_Info_set(info, keys[i], values[i]);
35     }
36
37     /* Check that all values are present */
38     for (i = 0; i < NKEYS; i++) {
39         MPI_Info_get(info, keys[i], MPI_MAX_INFO_VAL, value, &flag);
40         if (!flag) {
41             errs++;
42             printf("No value for key %s\n", keys[i]);
43         }
44         if (strcmp(value, values[i])) {
45             errs++;
46             printf("Incorrect value for key %s, got %s expected %s\n", 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 }