1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2009 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 static char MTestDescrip[] = "Test creating and inserting attributes in \
13 different orders to ensure that the list management code handles all cases.";
16 int checkAttrs(MPI_Comm, int, int[], int[]);
17 int delete_fn(MPI_Comm, int, void *, void *);
20 static int key[NKEYS]; /* Keys in creation order */
21 static int keyorder[NKEYS]; /* Index (into key) of keys in order added to comm
22 * (key[keyorder[0]] is first set) */
27 * Test that attributes on comm self are deleted in LIFO order
30 int main(int argc, char *argv[])
36 MPI_Init(&argc, &argv);
38 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
42 /* Create key values */
43 for (nkeys = 0; nkeys < NKEYS; nkeys++) {
44 MPI_Comm_create_keyval(MPI_NULL_COPY_FN, delete_fn, &key[nkeys], (void *) 0);
45 attrval[nkeys] = 1024 * nkeys;
48 /* Insert attribute in several orders. Test after put with get,
49 * then delete, then confirm delete with get. */
51 MPI_Comm_set_attr(comm, key[3], &attrval[3]);
53 MPI_Comm_set_attr(comm, key[2], &attrval[2]);
55 MPI_Comm_set_attr(comm, key[0], &attrval[0]);
57 MPI_Comm_set_attr(comm, key[1], &attrval[1]);
59 MPI_Comm_set_attr(comm, key[4], &attrval[4]);
62 errs += checkAttrs(comm, NKEYS, key, attrval);
64 for (i = 0; i < NKEYS; i++) {
65 /* Save the key value so that we can compare it in the
68 MPI_Comm_free_keyval(&keyval);
75 printf("Deleted %d keys but should have deleted %d\n", ncall, nkeys);
79 printf(" No Errors\n");
81 printf(" Found %d errors\n", errs);
87 int checkAttrs(MPI_Comm comm, int n, int lkey[], int attrval[])
92 for (i = 0; i < n; i++) {
93 MPI_Comm_get_attr(comm, lkey[i], &val_p, &flag);
96 fprintf(stderr, "Attribute for key %d not set\n", i);
98 else if (val_p != &attrval[i]) {
100 fprintf(stderr, "Attribute value for key %d not correct\n", i);
107 /* We *should* be deleting key[keyorder[nkeys-ncall]] */
108 int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
110 if (ncall >= nkeys) {
111 printf("delete function called too many times!\n");
115 /* As of MPI 2.2, the order of deletion of attributes on
116 * MPI_COMM_SELF is defined */
117 if (MPI_VERSION > 2 || (MPI_VERSION == 2 && MPI_SUBVERSION >= 2)) {
118 if (keyval != key[keyorder[nkeys - 1 - ncall]]) {
119 printf("Expected key # %d but found key with value %d\n",
120 keyorder[nkeys - 1 - ncall], keyval);
129 int checkNoAttrs(MPI_Comm comm, int n, int lkey[])
134 for (i=0; i<n; i++) {
135 MPI_Comm_get_attr(comm, lkey[i], &val_p, &flag);
138 fprintf(stderr, "Attribute for key %d set but should be deleted\n", i);