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,
27 int copy_fn( MPI_Win oldwin, int keyval, void *extra_state,
28 void *attribute_val_in, void *attribute_val_out,
31 /* Copy the address of the attribute */
32 *(void **)attribute_val_out = attribute_val_in;
33 /* Change the value */
34 *(int *)attribute_val_in = *(int *)attribute_val_in + 1;
39 /* Delete decrements the attribute value */
40 int delete_fn( MPI_Win win, int keyval, void *attribute_val,
42 int delete_fn( MPI_Win win, int keyval, void *attribute_val,
45 *(int *)attribute_val = *(int *)attribute_val - 1;
49 int main( int argc, char *argv[] )
53 int i, key[32], keyval, saveKeyval;
55 MTest_Init( &argc, &argv );
57 while (MTestGetWin( &win, 0 )) {
58 if (win == MPI_WIN_NULL) continue;
60 MPI_Win_create_keyval( copy_fn, delete_fn, &keyval, (void *)0 );
61 saveKeyval = keyval; /* in case we need to free explicitly */
63 MPI_Win_set_attr( win, keyval, (void*)&attrval );
64 /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it
65 is in use in an attribute */
66 MPI_Win_free_keyval( &keyval );
68 /* We create some dummy keyvals here in case the same keyval
70 for (i=0; i<32; i++) {
71 MPI_Win_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN,
77 /* Check that the original attribute was freed */
80 printf( "Attribute not decremented when win %s freed\n",
83 /* Free those other keyvals */
84 for (i=0; i<32; i++) {
85 MPI_Win_free_keyval( &key[i] );
89 MTest_Finalize( errs );