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.
13 static char MTestDescrip[] = "Test freeing keyvals while still attached to \
14 a datatype, then make sure that the keyval delete and copy code are still \
18 /* Copy increments the attribute value */
19 int copy_fn( MPI_Datatype oldtype, int keyval, void *extra_state,
20 void *attribute_val_in, void *attribute_val_out,
22 int copy_fn( MPI_Datatype oldtype, int keyval, void *extra_state,
23 void *attribute_val_in, void *attribute_val_out,
26 /* Copy the address of the attribute */
27 *(void **)attribute_val_out = attribute_val_in;
28 /* Change the value */
29 *(int *)attribute_val_in = *(int *)attribute_val_in + 1;
30 /* set flag to 1 to tell comm dup to insert this attribute
31 into the new communicator */
36 /* Delete decrements the attribute value */
37 int delete_fn( MPI_Datatype type, int keyval, void *attribute_val,
39 int delete_fn( MPI_Datatype type, int keyval, void *attribute_val,
42 *(int *)attribute_val = *(int *)attribute_val - 1;
46 int main( int argc, char *argv[] )
50 int i, key[32], keyval, saveKeyval;
51 MPI_Datatype type, duptype;
52 MTestDatatype mstype, mrtype;
53 char typename[MPI_MAX_OBJECT_NAME];
56 MTest_Init( &argc, &argv );
58 while (MTestGetDatatypes( &mstype, &mrtype, 1 )) {
59 type = mstype.datatype;
60 MPI_Type_create_keyval( copy_fn, delete_fn, &keyval, (void *)0 );
61 saveKeyval = keyval; /* in case we need to free explicitly */
63 MPI_Type_set_attr( type, 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_Type_free_keyval( &keyval );
68 /* We create some dummy keyvals here in case the same keyval
70 for (i=0; i<32; i++) {
71 MPI_Type_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN,
77 MPI_Type_get_name( type, typename, &tnlen );
78 printf( "attrval is %d, should be 1, before dup in type %s\n",
81 MPI_Type_dup( type, &duptype );
82 /* Check that the attribute was copied */
85 MPI_Type_get_name( type, typename, &tnlen );
86 printf( "Attribute not incremented when type dup'ed (%s)\n",
89 MPI_Type_free( &duptype );
92 MPI_Type_get_name( type, typename, &tnlen );
93 printf( "Attribute not decremented when duptype %s freed\n",
96 /* Check that the attribute was freed in the duptype */
98 if (!mstype.isBasic) {
99 MPI_Type_get_name( type, typename, &tnlen );
100 MTestFreeDatatype(&mstype);
101 /* Check that the original attribute was freed */
104 printf( "Attribute not decremented when type %s freed\n",
109 /* Explicitly delete the attributes from world and self */
110 MPI_Type_delete_attr( type, saveKeyval );
116 /* Free those other keyvals */
117 for (i=0; i<32; i++) {
118 MPI_Type_free_keyval( &key[i] );
120 MTestFreeDatatype(&mrtype);
122 MTest_Finalize( errs );