Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / win_info.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2012 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <mpi.h>
10 #include <string.h>
11 #include "mpitest.h"
12
13 #define VERBOSE 0
14
15 int main(int argc, char **argv)
16 {
17     int rank, nproc;
18     MPI_Info info_in, info_out;
19     int errors = 0, all_errors = 0;
20     MPI_Win win;
21     void *base;
22     char invalid_key[] = "invalid_test_key";
23     char buf[MPI_MAX_INFO_VAL];
24     int flag;
25
26     MPI_Init(&argc, &argv);
27
28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
30
31     /* Test#1: setting a valid key at window-create time */
32
33     MPI_Info_create(&info_in);
34     MPI_Info_set(info_in, (char *)"no_locks", (char *)"true");
35
36     MPI_Win_allocate(sizeof(int), sizeof(int), info_in, MPI_COMM_WORLD, &base, &win);
37
38     MPI_Win_get_info(win, &info_out);
39
40     MPI_Info_get(info_out, (char *)"no_locks", MPI_MAX_INFO_VAL, buf, &flag);
41     if (!flag || strncmp(buf, "true", strlen("true")) != 0) {
42         if (!flag)
43             printf("%d: no_locks is not defined\n", rank);
44         else
45             printf("%d: no_locks = %s, expected true\n", rank, buf);
46         errors++;
47     }
48
49     MPI_Info_free(&info_in);
50     MPI_Info_free(&info_out);
51
52     /* We create a new window with no info argument for the next text to ensure that we have the
53      * default settings */
54
55     MPI_Win_free(&win);
56     MPI_Win_allocate(sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &base, &win);
57
58     /* Test#2: setting and getting invalid key */
59
60     MPI_Info_create(&info_in);
61     MPI_Info_set(info_in, invalid_key, (char *)"true");
62
63     MPI_Win_set_info(win, info_in);
64     MPI_Win_get_info(win, &info_out);
65
66     MPI_Info_get(info_out, invalid_key, MPI_MAX_INFO_VAL, buf, &flag);
67 #ifdef USE_STRICT_MPI
68     /* Check if our invalid key was ignored.  Note, this check's MPICH's
69      * behavior, but this behavior may not be required for a standard
70      * conforming MPI implementation. */
71     if (flag) {
72         printf("%d: %s was not ignored\n", rank, invalid_key);
73         errors++;
74     }
75 #endif
76
77     MPI_Info_free(&info_in);
78     MPI_Info_free(&info_out);
79
80     /* Test#3: setting info key "no_lock" to false and getting the key */
81
82     MPI_Info_create(&info_in);
83     MPI_Info_set(info_in, (char *)"no_locks", (char *)"false");
84
85     MPI_Win_set_info(win, info_in);
86     MPI_Win_get_info(win, &info_out);
87
88     MPI_Info_get(info_out, (char *)"no_locks", MPI_MAX_INFO_VAL, buf, &flag);
89     if (!flag || strncmp(buf, "false", strlen("false")) != 0) {
90         if (!flag)
91             printf("%d: no_locks is not defined\n", rank);
92         else
93             printf("%d: no_locks = %s, expected false\n", rank, buf);
94         errors++;
95     }
96     if (flag && VERBOSE)
97         printf("%d: no_locks = %s\n", rank, buf);
98
99     MPI_Info_free(&info_in);
100     MPI_Info_free(&info_out);
101
102     /* Test#4: setting info key "no_lock" to true and getting the key */
103
104     MPI_Info_create(&info_in);
105     MPI_Info_set(info_in, (char *)"no_locks", (char *)"true");
106
107     MPI_Win_set_info(win, info_in);
108     MPI_Win_get_info(win, &info_out);
109
110     MPI_Info_get(info_out, (char *)"no_locks", MPI_MAX_INFO_VAL, buf, &flag);
111     if (!flag || strncmp(buf, "true", strlen("true")) != 0) {
112         if (!flag)
113             printf("%d: no_locks is not defined\n", rank);
114         else
115             printf("%d: no_locks = %s, expected true\n", rank, buf);
116         errors++;
117     }
118     if (flag && VERBOSE)
119         printf("%d: no_locks = %s\n", rank, buf);
120
121     MPI_Info_free(&info_in);
122     MPI_Info_free(&info_out);
123
124     /* Test#4: getting other info keys */
125
126     MPI_Win_get_info(win, &info_out);
127
128     MPI_Info_get(info_out, (char *)"accumulate_ordering", MPI_MAX_INFO_VAL, buf, &flag);
129     if (flag && VERBOSE)
130         printf("%d: accumulate_ordering = %s\n", rank, buf);
131
132     MPI_Info_get(info_out, (char *)"accumulate_ops", MPI_MAX_INFO_VAL, buf, &flag);
133     if (flag && VERBOSE)
134         printf("%d: accumulate_ops = %s\n", rank, buf);
135
136     MPI_Info_get(info_out, (char *)"same_size", MPI_MAX_INFO_VAL, buf, &flag);
137     if (flag && VERBOSE)
138         printf("%d: same_size = %s\n", rank, buf);
139
140     MPI_Info_get(info_out, (char *)"alloc_shm", MPI_MAX_INFO_VAL, buf, &flag);
141     if (flag && VERBOSE)
142         printf("%d: alloc_shm = %s\n", rank, buf);
143
144     MPI_Info_free(&info_out);
145     MPI_Win_free(&win);
146
147     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
148
149     if (rank == 0 && all_errors == 0)
150         printf(" No Errors\n");
151
152     MPI_Finalize();
153
154     return 0;
155 }