1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2001 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
10 #include "mpitestconf.h"
17 static char MTestDescrip[] = "Test freeing keyvals while still attached to \
18 a win, then make sure that the keyval delete code are still \
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)
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;
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)
41 *(int *) attribute_val = *(int *) attribute_val - 1;
45 int main(int argc, char *argv[])
49 int i, key[32], keyval;
51 MTest_Init(&argc, &argv);
53 while (MTestGetWin(&win, 0)) {
54 if (win == MPI_WIN_NULL)
57 MPI_Win_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0);
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);
64 /* We create some dummy keyvals here in case the same keyval
66 for (i = 0; i < 32; i++) {
67 MPI_Win_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
72 /* Check that the original attribute was freed */
75 printf("Attribute not decremented when win %s freed\n", MTestGetWinName());
77 /* Free those other keyvals */
78 for (i = 0; i < 32; i++) {
79 MPI_Win_free_keyval(&key[i]);