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,
45 &key[nkeys], (void *)0 );
46 attrval[nkeys] = 1024 * nkeys;
49 /* Insert attribute in several orders. Test after put with get,
50 then delete, then confirm delete with get. */
52 MPI_Comm_set_attr( comm, key[3], &attrval[3] ); keyorder[0] = 3;
53 MPI_Comm_set_attr( comm, key[2], &attrval[2] ); keyorder[1] = 2;
54 MPI_Comm_set_attr( comm, key[0], &attrval[0] ); keyorder[2] = 0;
55 MPI_Comm_set_attr( comm, key[1], &attrval[1] ); keyorder[3] = 1;
56 MPI_Comm_set_attr( comm, key[4], &attrval[4] ); keyorder[4] = 4;
58 errs += checkAttrs( comm, NKEYS, key, attrval );
60 for (i=0; i<NKEYS; i++) {
61 /* Save the key value so that we can compare it in the
64 MPI_Comm_free_keyval( &keyval );
71 printf( "Deleted %d keys but should have deleted %d\n",
75 if (errs == 0) printf( " No Errors\n" );
76 else printf( " Found %d errors\n", errs );
82 int checkAttrs( MPI_Comm comm, int n, int lkey[], int attrval[] )
88 MPI_Comm_get_attr( comm, lkey[i], &val_p, &flag );
91 fprintf( stderr, "Attribute for key %d not set\n", i );
93 else if (val_p != &attrval[i]) {
95 fprintf( stderr, "Attribute value for key %d not correct\n",
103 /* We *should* be deleting key[keyorder[nkeys-ncall]] */
104 int delete_fn( MPI_Comm comm, int keyval, void *attribute_val,
107 if (ncall >= nkeys) {
108 printf( "delete function called too many times!\n" );
112 /* As of MPI 2.2, the order of deletion of attributes on
113 MPI_COMM_SELF is defined */
114 if (MPI_VERSION > 2 || (MPI_VERSION == 2 && MPI_SUBVERSION >= 2)) {
115 if (keyval != key[keyorder[nkeys-1-ncall]]) {
116 printf( "Expected key # %d but found key with value %d\n",
117 keyorder[nkeys-1-ncall], keyval );
126 int checkNoAttrs( MPI_Comm comm, int n, int lkey[] )
131 for (i=0; i<n; i++) {
132 MPI_Comm_get_attr( comm, lkey[i], &val_p, &flag );
135 fprintf( stderr, "Attribute for key %d set but should be deleted\n", i );