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, int *flag);
21 int copy_fn(MPI_Datatype oldtype, int keyval, void *extra_state,
22 void *attribute_val_in, void *attribute_val_out, int *flag)
24 /* Copy the address of the attribute */
25 *(void **) attribute_val_out = attribute_val_in;
26 /* Change the value */
27 *(int *) attribute_val_in = *(int *) attribute_val_in + 1;
28 /* set flag to 1 to tell comm dup to insert this attribute
29 * into the new communicator */
34 /* Delete decrements the attribute value */
35 int delete_fn(MPI_Datatype type, int keyval, void *attribute_val, void *extra_state);
36 int delete_fn(MPI_Datatype type, int keyval, void *attribute_val, void *extra_state)
38 *(int *) attribute_val = *(int *) attribute_val - 1;
42 int main(int argc, char *argv[])
46 int i, key[32], keyval, saveKeyval;
47 MPI_Datatype type, duptype;
48 MTestDatatype mstype, mrtype;
49 char typename[MPI_MAX_OBJECT_NAME];
52 MTest_Init(&argc, &argv);
54 while (MTestGetDatatypes(&mstype, &mrtype, 1)) {
55 type = mstype.datatype;
56 MPI_Type_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0);
57 saveKeyval = keyval; /* in case we need to free explicitly */
59 MPI_Type_set_attr(type, 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_Type_free_keyval(&keyval);
64 /* We create some dummy keyvals here in case the same keyval
66 for (i = 0; i < 32; i++) {
67 MPI_Type_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
72 MPI_Type_get_name(type, typename, &tnlen);
73 printf("attrval is %d, should be 1, before dup in type %s\n", attrval, typename);
75 MPI_Type_dup(type, &duptype);
76 /* Check that the attribute was copied */
79 MPI_Type_get_name(type, typename, &tnlen);
80 printf("Attribute not incremented when type dup'ed (%s)\n", typename);
82 MPI_Type_free(&duptype);
85 MPI_Type_get_name(type, typename, &tnlen);
86 printf("Attribute not decremented when duptype %s freed\n", typename);
88 /* Check that the attribute was freed in the duptype */
90 if (!mstype.isBasic) {
91 MPI_Type_get_name(type, typename, &tnlen);
92 MTestFreeDatatype(&mstype);
93 /* Check that the original attribute was freed */
96 printf("Attribute not decremented when type %s freed\n", typename);
100 /* Explicitly delete the attributes from world and self */
101 MPI_Type_delete_attr(type, saveKeyval);
107 /* Free those other keyvals */
108 for (i = 0; i < 32; i++) {
109 MPI_Type_free_keyval(&key[i]);
111 MTestFreeDatatype(&mrtype);
113 MTest_Finalize(errs);