Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some tests to avoid useless global variables
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / fkeyvalwin.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2001 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 "mpitestconf.h"
11 #include "mpitest.h"
12 #ifdef HAVE_STRING_H
13 #include <string.h>
14 #endif
15
16 /*
17 static char MTestDescrip[] = "Test freeing keyvals while still attached to \
18 a win, then make sure that the keyval delete code are still \
19 executed";
20 */
21
22 /* Copy increments the attribute value */
23 /* Note that we can really ignore this because there is no win dup */
24 int copy_fn(MPI_Win oldwin, int keyval, void *extra_state,
25             void *attribute_val_in, void *attribute_val_out, int *flag);
26 int copy_fn(MPI_Win oldwin, int keyval, void *extra_state,
27             void *attribute_val_in, void *attribute_val_out, int *flag)
28 {
29     /* Copy the address of the attribute */
30     *(void **) attribute_val_out = attribute_val_in;
31     /* Change the value */
32     *(int *) attribute_val_in = *(int *) attribute_val_in + 1;
33     *flag = 1;
34     return MPI_SUCCESS;
35 }
36
37 /* Delete decrements the attribute value */
38 int delete_fn(MPI_Win win, int keyval, void *attribute_val, void *extra_state);
39 int delete_fn(MPI_Win win, int keyval, void *attribute_val, void *extra_state)
40 {
41     *(int *) attribute_val = *(int *) attribute_val - 1;
42     return MPI_SUCCESS;
43 }
44
45 int main(int argc, char *argv[])
46 {
47     int errs = 0;
48     int attrval;
49     int i, key[32], keyval;
50     MPI_Win win;
51     MTest_Init(&argc, &argv);
52
53     while (MTestGetWin(&win, 0)) {
54         if (win == MPI_WIN_NULL)
55             continue;
56
57         MPI_Win_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0);
58         attrval = 1;
59         MPI_Win_set_attr(win, keyval, (void *) &attrval);
60         /* See MPI-1, 5.7.1.  Freeing the keyval does not remove it if it
61          * is in use in an attribute */
62         MPI_Win_free_keyval(&keyval);
63
64         /* We create some dummy keyvals here in case the same keyval
65          * is reused */
66         for (i = 0; i < 32; i++) {
67             MPI_Win_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
68         }
69
70         MTestFreeWin(&win);
71
72         /* Check that the original attribute was freed */
73         if (attrval != 0) {
74             errs++;
75             printf("Attribute not decremented when win %s freed\n", MTestGetWinName());
76         }
77         /* Free those other keyvals */
78         for (i = 0; i < 32; i++) {
79             MPI_Win_free_keyval(&key[i]);
80         }
81
82     }
83     MTest_Finalize(errs);
84     MPI_Finalize();
85
86     return 0;
87 }