10 typedef struct _table {
16 /* Prototypes for picky compilers */
17 int copy_table ( MPI_Comm, int, void *, void *, void *, int * );
18 void create_table ( int, int *, Table ** );
19 int delete_table ( MPI_Comm, int, void *, void * );
21 /* These are incorrect...*/
22 int copy_table ( MPI_Comm oldcomm, int keyval, void *extra_state,
23 void *attr_in, void *attr_out, int *flag)
25 Table *table = (Table *)attr_in;;
28 (*(void **)attr_out) = attr_in;
30 (*(int *)extra_state)++;
34 void create_table ( int num, int *values, Table **table_out )
37 (*table_out) = (Table *)malloc(sizeof(Table));
38 (*table_out)->references = 1;
39 (*table_out)->length = num;
40 (*table_out)->value = (int *)malloc(sizeof(int)*num);
42 (*table_out)->value[i] = values[i];
45 int delete_table ( MPI_Comm comm, int keyval,
46 void *attr_val, void *extra_state)
48 Table *table = (Table *)attr_val;
50 if ( table->references == 1 )
54 (*(int *)extra_state)--;
58 int main ( int argc, char **argv )
69 MPI_Init ( &argc, &argv );
70 MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
71 MPI_Comm_size ( MPI_COMM_WORLD, &size );
73 values[0] = 1; values[1] = 2; values[2] = 3;
74 create_table(3,values,&table);
76 MPI_Keyval_create ( copy_table, delete_table, &table_key,
77 (void *)&table_copies );
78 MPI_Attr_put ( MPI_COMM_WORLD, table_key, (void *)table );
79 MPI_Comm_dup ( MPI_COMM_WORLD, &new_comm );
80 MPI_Attr_get ( new_comm, table_key, (void **)&table, &found );
83 printf( "did not find attribute on new comm\n" );
87 if ((table_copies != 2) && (table->references != 2)) {
88 printf( "table_copies != 2 (=%d) and table->references != 2 (=%d)\n",
89 table_copies, table->references );
93 MPI_Comm_free ( &new_comm );
95 if ((table_copies != 1) && (table->references != 1)) {
96 printf( "table_copies != 1 (=%d) and table->references != 1 (=%d)\n",
97 table_copies, table->references );
101 MPI_Attr_delete ( MPI_COMM_WORLD, table_key );
103 if ( table_copies != 0 ) {
104 printf( "table_copies != 0 (=%d)\n", table_copies );
108 printf("[%d] OOPS. %d errors!\n",rank,errors);
110 MPI_Keyval_free ( &table_key );