1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2007 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
11 static int foo_keyval = MPI_KEYVAL_INVALID;
13 int foo_initialize(void);
14 void foo_finalize(void);
16 int foo_copy_attr_function(MPI_Datatype type, int type_keyval,
17 void *extra_state, void *attribute_val_in,
18 void *attribute_val_out, int *flag);
19 int foo_delete_attr_function(MPI_Datatype type, int type_keyval,
20 void *attribute_val, void *extra_state);
21 static const char *my_func = 0;
22 static int verbose = 0;
23 static int delete_called = 0;
24 static int copy_called = 0;
26 int main(int argc, char *argv[])
29 MPI_Datatype type, duptype;
32 MPI_Init(&argc, &argv);
34 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
38 mpi_errno = MPI_Type_contiguous(2, MPI_INT, &type);
40 mpi_errno = MPI_Type_set_attr(type, foo_keyval, NULL);
42 mpi_errno = MPI_Type_dup(type, &duptype);
44 my_func = "Free of type";
45 mpi_errno = MPI_Type_free(&type);
47 my_func = "free of duptype";
48 mpi_errno = MPI_Type_free(&duptype);
54 if (copy_called != 1) {
55 printf( "Copy called %d times; expected once\n", copy_called );
58 if (delete_called != 2) {
59 printf( "Delete called %d times; expected twice\n", delete_called );
63 printf( " No Errors\n" );
64 }else if(mpi_errno!=MPI_SUCCESS){
65 printf( " Output fail - Found %d errors\n", errs );
67 printf( " Found %d errors\n", errs );
76 int foo_copy_attr_function(MPI_Datatype type,
79 void *attribute_val_in,
80 void *attribute_val_out,
83 if (verbose) printf("copy fn. called\n");
85 * (char **) attribute_val_out = NULL;
91 int foo_delete_attr_function(MPI_Datatype type,
96 if (verbose) printf("delete fn. called in %s\n", my_func );
102 int foo_initialize(void)
106 /* create keyval for use later */
107 mpi_errno = MPI_Type_create_keyval(foo_copy_attr_function,
108 foo_delete_attr_function,
111 if (mpi_errno==MPI_SUCCESS && verbose) printf("created keyval\n");
116 void foo_finalize(void)
121 mpi_errno = MPI_Type_free_keyval(&foo_keyval);
123 if (mpi_errno==MPI_SUCCESS && verbose) printf("freed keyval\n");