Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
support MPI_Op_commutative call, as it was already implemented internally
[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", nkeysdup, nkeys);
40     }
41     vallen = MPI_MAX_INFO_VAL;
42     for (i = 0; i < nkeys; i++) {
43         /* MPI requires that the keys are in the same order after the dup */
44         MPI_Info_get_nthkey(info1, i, key);
45         MPI_Info_get_nthkey(infodup, i, keydup);
46         if (strcmp(key, keydup)) {
47             errs++;
48             printf("keys do not match: %s should be %s\n", keydup, key);
49         }
50
51         vallen = MPI_MAX_INFO_VAL;
52         MPI_Info_get(info1, key, vallen, value, &flag);
53         MPI_Info_get(infodup, keydup, vallen, valdup, &flagdup);
54         if (!flag || !flagdup) {
55             errs++;
56             printf("Info get failed for key %s\n", key);
57         }
58         else if (strcmp(value, valdup)) {
59             errs++;
60             printf("Info values for key %s not the same after dup\n", key);
61         }
62     }
63
64     /* Change info and check that infodup does NOT have the new value
65      * (ensure that lazy dups are still duped) */
66     MPI_Info_set(info1, (char *) "path", (char *) "/a:/b:/c/d");
67
68     MPI_Info_get(infodup, (char *) "path", vallen, value, &flag);
69     if (flag) {
70         errs++;
71         printf("inserting path into info changed infodup\n");
72     }
73
74     MPI_Info_free(&info1);
75     MPI_Info_free(&infodup);
76
77     MTest_Finalize(errs);
78     MPI_Finalize();
79     return 0;
80
81 }