From 839ca861fcbfe4230637ffc30766445cc7b4918f Mon Sep 17 00:00:00 2001 From: degomme Date: Sat, 11 Feb 2017 19:46:48 +0100 Subject: [PATCH] Update attr tests --- .../smpi/mpich3-test/attr/CMakeLists.txt | 6 +- teshsuite/smpi/mpich3-test/attr/attr2type.c | 96 ++--- .../smpi/mpich3-test/attr/attrdeleteget.c | 54 +++ teshsuite/smpi/mpich3-test/attr/attrend.c | 63 ++- teshsuite/smpi/mpich3-test/attr/attrend2.c | 25 +- teshsuite/smpi/mpich3-test/attr/attrerr.c | 99 +++-- teshsuite/smpi/mpich3-test/attr/attrerrcomm.c | 112 +++--- teshsuite/smpi/mpich3-test/attr/attrerrtype.c | 109 +++-- teshsuite/smpi/mpich3-test/attr/attric.c | 164 ++++---- teshsuite/smpi/mpich3-test/attr/attrorder.c | 151 ++++--- .../smpi/mpich3-test/attr/attrordercomm.c | 151 ++++--- .../smpi/mpich3-test/attr/attrordertype.c | 151 ++++--- teshsuite/smpi/mpich3-test/attr/attrt.c | 376 +++++++++--------- teshsuite/smpi/mpich3-test/attr/baseattr2.c | 230 +++++------ .../smpi/mpich3-test/attr/baseattrcomm.c | 140 +++---- teshsuite/smpi/mpich3-test/attr/fkeyval.c | 127 +++--- teshsuite/smpi/mpich3-test/attr/fkeyvalcomm.c | 129 +++--- teshsuite/smpi/mpich3-test/attr/fkeyvaltype.c | 137 +++---- .../mpich3-test/attr/keyval_double_free.c | 21 +- .../attr/keyval_double_free_comm.c | 43 ++ .../attr/keyval_double_free_type.c | 45 +++ .../mpich3-test/attr/keyval_double_free_win.c | 54 +++ teshsuite/smpi/mpich3-test/attr/testlist | 1 + 23 files changed, 1312 insertions(+), 1172 deletions(-) create mode 100644 teshsuite/smpi/mpich3-test/attr/attrdeleteget.c create mode 100644 teshsuite/smpi/mpich3-test/attr/keyval_double_free_comm.c create mode 100644 teshsuite/smpi/mpich3-test/attr/keyval_double_free_type.c create mode 100644 teshsuite/smpi/mpich3-test/attr/keyval_double_free_win.c diff --git a/teshsuite/smpi/mpich3-test/attr/CMakeLists.txt b/teshsuite/smpi/mpich3-test/attr/CMakeLists.txt index 7f31856d14..55db578c9d 100644 --- a/teshsuite/smpi/mpich3-test/attr/CMakeLists.txt +++ b/teshsuite/smpi/mpich3-test/attr/CMakeLists.txt @@ -9,7 +9,7 @@ if(enable_smpi AND enable_smpi_MPICH3_testsuite) include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include/") - foreach(file attr2type attrend2 attrend attrerr attrerrcomm attrerrtype attrorder attrordercomm attrordertype attrt + foreach(file attr2type attrdeleteget attrend2 attrend attrerr attrerrcomm attrerrtype attrorder attrordercomm attrordertype attrt baseattr2 baseattrcomm fkeyval) #attric fkeyvalcomm fkeyvaltype keyval_double_free add_executable(${file} ${file}.c) target_link_libraries(${file} simgrid mtest_c) @@ -21,8 +21,8 @@ if (enable_smpi_MPICH3_testsuite AND HAVE_RAW_CONTEXTS) SET_TESTS_PROPERTIES(test-smpi-mpich3-attr-raw PROPERTIES PASS_REGULAR_EXPRESSION "tests passed!") endif() -foreach(file attr2type attrend2 attrend attrerr attrerrcomm attrerrtype attrorder attrordercomm attrordertype attrt - baseattr2 baseattrcomm fkeyval attric fkeyvalcomm fkeyvaltype keyval_double_free) +foreach(file attr2type attrdeleteget attrend2 attrend attrerr attrerrcomm attrerrtype attrorder attrordercomm attrordertype attrt + baseattr2 baseattrcomm fkeyval attric fkeyvalcomm fkeyvaltype keyval_double_free keyval_double_free_comm keyval_double_free_type keyval_double_free_win) set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${file}.c) endforeach() set(examples_src ${examples_src} PARENT_SCOPE) diff --git a/teshsuite/smpi/mpich3-test/attr/attr2type.c b/teshsuite/smpi/mpich3-test/attr/attr2type.c index 69706cf596..90e9f1f120 100644 --- a/teshsuite/smpi/mpich3-test/attr/attr2type.c +++ b/teshsuite/smpi/mpich3-test/attr/attr2type.c @@ -14,10 +14,10 @@ int foo_initialize(void); void foo_finalize(void); int foo_copy_attr_function(MPI_Datatype type, int type_keyval, - void *extra_state, void *attribute_val_in, - void *attribute_val_out, int *flag); + void *extra_state, void *attribute_val_in, + void *attribute_val_out, int *flag); int foo_delete_attr_function(MPI_Datatype type, int type_keyval, - void *attribute_val, void *extra_state); + void *attribute_val, void *extra_state); static const char *my_func = 0; static int verbose = 0; static int delete_called = 0; @@ -25,48 +25,46 @@ static int copy_called = 0; int main(int argc, char *argv[]) { - int mpi_errno; MPI_Datatype type, duptype; int rank; MPI_Init(&argc, &argv); - - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); foo_initialize(); - mpi_errno = MPI_Type_contiguous(2, MPI_INT, &type); + MPI_Type_contiguous(2, MPI_INT, &type); - mpi_errno = MPI_Type_set_attr(type, foo_keyval, NULL); + MPI_Type_set_attr(type, foo_keyval, NULL); - mpi_errno = MPI_Type_dup(type, &duptype); + MPI_Type_dup(type, &duptype); my_func = "Free of type"; - mpi_errno = MPI_Type_free(&type); + MPI_Type_free(&type); my_func = "free of duptype"; - mpi_errno = MPI_Type_free(&duptype); + MPI_Type_free(&duptype); foo_finalize(); if (rank == 0) { - int errs = 0; - if (copy_called != 1) { - printf( "Copy called %d times; expected once\n", copy_called ); - errs++; - } - if (delete_called != 2) { - printf( "Delete called %d times; expected twice\n", delete_called ); - errs++; - } - if (errs == 0) { - printf( " No Errors\n" ); - }else if(mpi_errno!=MPI_SUCCESS){ - printf( " Output fail - Found %d errors\n", errs ); - }else { - printf( " Found %d errors\n", errs ); - } - fflush(stdout); + int errs = 0; + if (copy_called != 1) { + printf("Copy called %d times; expected once\n", copy_called); + errs++; + } + if (delete_called != 2) { + printf("Delete called %d times; expected twice\n", delete_called); + errs++; + } + if (errs == 0) { + printf(" No Errors\n"); + } + else { + printf(" Found %d errors\n", errs); + } + fflush(stdout); } MPI_Finalize(); @@ -74,53 +72,47 @@ int main(int argc, char *argv[]) } int foo_copy_attr_function(MPI_Datatype type, - int type_keyval, - void *extra_state, - void *attribute_val_in, - void *attribute_val_out, - int *flag) + int type_keyval, + void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { - if (verbose) printf("copy fn. called\n"); - copy_called ++; - * (char **) attribute_val_out = NULL; + if (verbose) + printf("copy fn. called\n"); + copy_called++; + *(char **) attribute_val_out = NULL; *flag = 1; return MPI_SUCCESS; } int foo_delete_attr_function(MPI_Datatype type, - int type_keyval, - void *attribute_val, - void *extra_state) + int type_keyval, void *attribute_val, void *extra_state) { - if (verbose) printf("delete fn. called in %s\n", my_func ); - delete_called ++; + if (verbose) + printf("delete fn. called in %s\n", my_func); + delete_called++; return MPI_SUCCESS; } int foo_initialize(void) { - int mpi_errno; - /* create keyval for use later */ - mpi_errno = MPI_Type_create_keyval(foo_copy_attr_function, - foo_delete_attr_function, - &foo_keyval, - NULL); - if (mpi_errno==MPI_SUCCESS && verbose) printf("created keyval\n"); + MPI_Type_create_keyval(foo_copy_attr_function, + foo_delete_attr_function, &foo_keyval, NULL); + if (verbose) + printf("created keyval\n"); return 0; } void foo_finalize(void) { - int mpi_errno; - /* remove keyval */ - mpi_errno = MPI_Type_free_keyval(&foo_keyval); + MPI_Type_free_keyval(&foo_keyval); - if (mpi_errno==MPI_SUCCESS && verbose) printf("freed keyval\n"); + if (verbose) + printf("freed keyval\n"); return; } diff --git a/teshsuite/smpi/mpich3-test/attr/attrdeleteget.c b/teshsuite/smpi/mpich3-test/attr/attrdeleteget.c new file mode 100644 index 0000000000..fdfea46e2a --- /dev/null +++ b/teshsuite/smpi/mpich3-test/attr/attrdeleteget.c @@ -0,0 +1,54 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2013 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +#include +#include "mpi.h" +#include "mpitest.h" + +int key = MPI_KEYVAL_INVALID; +char a[100]; + +int delete_fn(MPI_Comm, int, void *, void *); + +int main(int argc, char **argv) +{ + MPI_Comm scomm; + int errs = 0; + + MTest_Init(&argc, &argv); + MPI_Comm_split(MPI_COMM_WORLD, 1, 0, &scomm); + MPI_Comm_create_keyval(MPI_NULL_COPY_FN, delete_fn, &key, &errs); + MPI_Comm_set_attr(scomm, key, a); + MPI_Comm_free(&scomm); + MPI_Comm_free_keyval(&key); + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} + +int delete_fn(MPI_Comm comm, int keyval, void *attr_val, void *extra_state) +{ + /* The standard is not explicit that the 'comm' argument of + * delete_fn must be valid, so this test is only in effect when + * !USE_STRICT_MPI. */ +#ifndef USE_STRICT_MPI + int err, flg, *errs = extra_state; + void *ptr; + + if (comm == MPI_COMM_NULL) { + printf("MPI_COMM_NULL passed to delete_fn\n"); + (*errs)++; + } + err = MPI_Comm_get_attr(comm, key, &ptr, &flg); + if (err != MPI_SUCCESS) { + printf("MPI_Comm_get_attr returned error %d, presumably due to invalid communicator\n", + err); + (*errs)++; + } +#endif + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/attr/attrend.c b/teshsuite/smpi/mpich3-test/attr/attrend.c index 37c4a1b76b..4e897c43cf 100644 --- a/teshsuite/smpi/mpich3-test/attr/attrend.c +++ b/teshsuite/smpi/mpich3-test/attr/attrend.c @@ -5,9 +5,9 @@ * See COPYRIGHT in top-level directory. */ /* - The MPI-2 specification makes it clear that delect attributes are + The MPI-2 specification makes it clear that delect attributes are called on MPI_COMM_WORLD and MPI_COMM_SELF at the very beginning of - MPI_Finalize. This is useful for tools that want to perform the MPI + MPI_Finalize. This is useful for tools that want to perform the MPI equivalent of an "at_exit" action. */ #include @@ -18,65 +18,64 @@ int exit_key = MPI_KEYVAL_INVALID; int wasCalled = 0; int foundError = 0; /* #define DEBUG */ -int delete_fn ( MPI_Comm, int, void *, void * ); +int delete_fn(MPI_Comm, int, void *, void *); #ifdef DEBUG #define FFLUSH fflush(stdout); #else #define FFLUSH #endif -int main( int argc, char **argv ) +int main(int argc, char **argv) { int errs = 0, wrank; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &wrank); - MPI_Comm_rank( MPI_COMM_WORLD, &wrank ); - /* create the keyval for the exit handler */ - MPI_Keyval_create( MPI_NULL_COPY_FN, delete_fn, &exit_key, (void *)0 ); + MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &exit_key, (void *) 0); /* Attach to comm_self */ - MPI_Attr_put( MPI_COMM_SELF, exit_key, (void*)0 ); + MPI_Attr_put(MPI_COMM_SELF, exit_key, (void *) 0); /* We can free the key now */ - MPI_Keyval_free( &exit_key ); + MPI_Keyval_free(&exit_key); /* Now, exit MPI */ - /* MTest_Finalize( errs ); */ + /* MTest_Finalize(errs); */ MPI_Finalize(); /* Check that the exit handler was called, and without error */ if (wrank == 0) { - /* In case more than one process exits MPI_Finalize */ - if (wasCalled != 1) { - errs++; - printf( "Attribute delete function on MPI_COMM_SELF was not called\n" ); - } - if (foundError != 0) { - errs++; - printf( "Found %d errors while executing delete function in MPI_COMM_SELF\n", foundError ); - } - if (errs == 0) { - printf( " No Errors\n" ); - } - else { - printf( " Found %d errors\n", errs ); - } - fflush(stdout ); + /* In case more than one process exits MPI_Finalize */ + if (wasCalled != 1) { + errs++; + printf("Attribute delete function on MPI_COMM_SELF was not called\n"); + } + if (foundError != 0) { + errs++; + printf("Found %d errors while executing delete function in MPI_COMM_SELF\n", + foundError); + } + if (errs == 0) { + printf(" No Errors\n"); + } + else { + printf(" Found %d errors\n", errs); + } + fflush(stdout); } return 0; } -int delete_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state) +int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { int flag; wasCalled++; - MPI_Finalized( &flag ); + MPI_Finalized(&flag); if (flag) { - foundError++; + foundError++; } return MPI_SUCCESS; } - diff --git a/teshsuite/smpi/mpich3-test/attr/attrend2.c b/teshsuite/smpi/mpich3-test/attr/attrend2.c index 44545318c5..d71592b486 100644 --- a/teshsuite/smpi/mpich3-test/attr/attrend2.c +++ b/teshsuite/smpi/mpich3-test/attr/attrend2.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ /* * - * (C) 2008 by Argonne National Laboratory. + * (C) 2009 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ /* @@ -22,22 +22,21 @@ * assuming a decent hash function is used. */ #define NUM_TEST_ATTRS (20) -static __attribute__((unused)) int exit_keys[NUM_TEST_ATTRS]; /* init to MPI_KEYVAL_INVALID */ -static __attribute__((unused)) int was_called[NUM_TEST_ATTRS]; +static int exit_keys[NUM_TEST_ATTRS]; /* init to MPI_KEYVAL_INVALID */ +static int was_called[NUM_TEST_ATTRS]; int foundError = 0; -int delete_fn (MPI_Comm, int, void *, void *); +int delete_fn(MPI_Comm, int, void *, void *); int main(int argc, char **argv) { - int wrank; + int errs = 0, wrank; + int i; MTest_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &wrank); #if MTEST_HAVE_MIN_MPI_VERSION(2,2) - int errs = 0; - int i; for (i = 0; i < NUM_TEST_ATTRS; ++i) { exit_keys[i] = MPI_KEYVAL_INVALID; was_called[i] = 0; @@ -45,7 +44,7 @@ int main(int argc, char **argv) /* create the keyval for the exit handler */ MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN, delete_fn, &exit_keys[i], NULL); /* attach to comm_self */ - MPI_Comm_set_attr(MPI_COMM_SELF, exit_keys[i], (void*)(long)i); + MPI_Comm_set_attr(MPI_COMM_SELF, exit_keys[i], (void *) (long) i); } /* we can free the keys now */ @@ -66,12 +65,15 @@ int main(int argc, char **argv) } else if (was_called[i] > 1) { errs++; - printf("Attribute delete function on MPI_COMM_SELF was called multiple times for idx=%d\n", i); + printf + ("Attribute delete function on MPI_COMM_SELF was called multiple times for idx=%d\n", + i); } } if (foundError != 0) { errs++; - printf("Found %d errors while executing delete function in MPI_COMM_SELF\n", foundError); + printf("Found %d errors while executing delete function in MPI_COMM_SELF\n", + foundError); } if (errs == 0) { printf(" No Errors\n"); @@ -94,7 +96,7 @@ int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { int flag; int i; - int my_idx = (int)(long)attribute_val; + int my_idx = (int) (long) attribute_val; if (my_idx < 0 || my_idx > NUM_TEST_ATTRS) { printf("internal error, my_idx=%d is invalid!\n", my_idx); @@ -126,4 +128,3 @@ int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) return MPI_SUCCESS; } - diff --git a/teshsuite/smpi/mpich3-test/attr/attrerr.c b/teshsuite/smpi/mpich3-test/attr/attrerr.c index 907e4a53f3..1799443e08 100644 --- a/teshsuite/smpi/mpich3-test/attr/attrerr.c +++ b/teshsuite/smpi/mpich3-test/attr/attrerr.c @@ -16,35 +16,35 @@ #include "mpi.h" #include "mpitest.h" -int test_communicators ( void ); -void abort_msg ( const char *, int ); -int copybomb_fn ( MPI_Comm, int, void *, void *, void *, int * ); -int deletebomb_fn ( MPI_Comm, int, void *, void * ); +int test_communicators(void); +void abort_msg(const char *, int); +int copybomb_fn(MPI_Comm, int, void *, void *, void *, int *); +int deletebomb_fn(MPI_Comm, int, void *, void *); -int main( int argc, char **argv ) +int main(int argc, char **argv) { int errs; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); errs = test_communicators(); - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } -/* - * MPI 1.2 Clarification: Clarification of Error Behavior of - * Attribute Callback Functions +/* + * MPI 1.2 Clarification: Clarification of Error Behavior of + * Attribute Callback Functions * Any return value other than MPI_SUCCESS is erroneous. The specific value * returned to the user is undefined (other than it can't be MPI_SUCCESS). * Proposals to specify particular values (e.g., user's value) failed. */ /* Return an error as the value */ -int copybomb_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, int *flag) +int copybomb_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Note that if (sizeof(int) < sizeof(void *), just setting the int - part of attribute_val_out may leave some dirty bits - */ + * part of attribute_val_out may leave some dirty bits + */ *flag = 1; return MPI_ERR_OTHER; } @@ -52,82 +52,79 @@ int copybomb_fn( MPI_Comm oldcomm, int keyval, void *extra_state, /* Set delete flag to 1 to allow the attribute to be deleted */ static int delete_flag = 0; -int deletebomb_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state) +int deletebomb_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { - if (delete_flag) return MPI_SUCCESS; + if (delete_flag) + return MPI_SUCCESS; return MPI_ERR_OTHER; } -void abort_msg( const char *str, int code ) +void abort_msg(const char *str, int code) { - fprintf( stderr, "%s, err = %d\n", str, code ); - MPI_Abort( MPI_COMM_WORLD, code ); - exit(code); + fprintf(stderr, "%s, err = %d\n", str, code); + MPI_Abort(MPI_COMM_WORLD, code); } -int test_communicators( void ) +int test_communicators(void) { MPI_Comm dup_comm_world, d2; int world_rank, world_size, key_1; int err, errs = 0; MPI_Aint value; - MPI_Comm_rank( MPI_COMM_WORLD, &world_rank ); - MPI_Comm_size( MPI_COMM_WORLD, &world_size ); + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + MPI_Comm_size(MPI_COMM_WORLD, &world_size); #ifdef DEBUG if (world_rank == 0) { - printf( "*** Attribute copy/delete return codes ***\n" ); + printf("*** Attribute copy/delete return codes ***\n"); } #endif - MPI_Comm_dup( MPI_COMM_WORLD, &dup_comm_world ); - MPI_Barrier( dup_comm_world ); + MPI_Comm_dup(MPI_COMM_WORLD, &dup_comm_world); + MPI_Barrier(dup_comm_world); - MPI_Errhandler_set( dup_comm_world, MPI_ERRORS_RETURN ); + MPI_Errhandler_set(dup_comm_world, MPI_ERRORS_RETURN); - value = - 11; - if ((err=MPI_Keyval_create( copybomb_fn, deletebomb_fn, &key_1, &value ))) - abort_msg( "Keyval_create", err ); + value = -11; + if ((err = MPI_Keyval_create(copybomb_fn, deletebomb_fn, &key_1, &value))) + abort_msg("Keyval_create", err); - err = MPI_Attr_put( dup_comm_world, key_1, (void *) (MPI_Aint) world_rank ); + err = MPI_Attr_put(dup_comm_world, key_1, (void *) (MPI_Aint) world_rank); if (err) { - errs++; - printf( "Error with first put\n" ); + errs++; + printf("Error with first put\n"); } - err = MPI_Attr_put( dup_comm_world, key_1, - (void *) (MPI_Aint) (2*world_rank) ); + err = MPI_Attr_put(dup_comm_world, key_1, (void *) (MPI_Aint) (2 * world_rank)); if (err == MPI_SUCCESS) { - errs++; - printf( "delete function return code was MPI_SUCCESS in put\n" ); + errs++; + printf("delete function return code was MPI_SUCCESS in put\n"); } /* Because the attribute delete function should fail, the attribute - should *not be removed* */ - err = MPI_Attr_delete( dup_comm_world, key_1 ); + * should *not be removed* */ + err = MPI_Attr_delete(dup_comm_world, key_1); if (err == MPI_SUCCESS) { - errs++; - printf( "delete function return code was MPI_SUCCESS in delete\n" ); + errs++; + printf("delete function return code was MPI_SUCCESS in delete\n"); } - - err = MPI_Comm_dup( dup_comm_world, &d2 ); + + err = MPI_Comm_dup(dup_comm_world, &d2); if (err == MPI_SUCCESS) { - errs++; - printf( "copy function return code was MPI_SUCCESS in dup\n" ); + errs++; + printf("copy function return code was MPI_SUCCESS in dup\n"); } #ifndef USE_STRICT_MPI /* Another interpretation is to leave d2 unchanged on error */ if (err && d2 != MPI_COMM_NULL) { - errs++; - printf( "dup did not return MPI_COMM_NULL on error\n" ); + errs++; + printf("dup did not return MPI_COMM_NULL on error\n"); } #endif delete_flag = 1; - MPI_Comm_free( &dup_comm_world ); - MPI_Keyval_free( &key_1 ); + MPI_Comm_free(&dup_comm_world); + MPI_Keyval_free(&key_1); return errs; } - diff --git a/teshsuite/smpi/mpich3-test/attr/attrerrcomm.c b/teshsuite/smpi/mpich3-test/attr/attrerrcomm.c index 9384dd4a94..a8947bd20e 100644 --- a/teshsuite/smpi/mpich3-test/attr/attrerrcomm.c +++ b/teshsuite/smpi/mpich3-test/attr/attrerrcomm.c @@ -16,35 +16,35 @@ #include "mpi.h" #include "mpitest.h" -int test_communicators ( void ); -void abort_msg ( const char *, int ); -int copybomb_fn ( MPI_Comm, int, void *, void *, void *, int * ); -int deletebomb_fn ( MPI_Comm, int, void *, void * ); +int test_communicators(void); +void abort_msg(const char *, int); +int copybomb_fn(MPI_Comm, int, void *, void *, void *, int *); +int deletebomb_fn(MPI_Comm, int, void *, void *); -int main( int argc, char **argv ) +int main(int argc, char **argv) { int errs; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); errs = test_communicators(); - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } -/* - * MPI 1.2 Clarification: Clarification of Error Behavior of - * Attribute Callback Functions +/* + * MPI 1.2 Clarification: Clarification of Error Behavior of + * Attribute Callback Functions * Any return value other than MPI_SUCCESS is erroneous. The specific value * returned to the user is undefined (other than it can't be MPI_SUCCESS). * Proposals to specify particular values (e.g., user's value) failed. */ /* Return an error as the value */ -int copybomb_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, int *flag) +int copybomb_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Note that if (sizeof(int) < sizeof(void *), just setting the int - part of attribute_val_out may leave some dirty bits - */ + * part of attribute_val_out may leave some dirty bits + */ *flag = 1; return MPI_ERR_OTHER; } @@ -52,91 +52,89 @@ int copybomb_fn( MPI_Comm oldcomm, int keyval, void *extra_state, /* Set delete flag to 1 to allow the attribute to be deleted */ static int delete_flag = 0; -int deletebomb_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state) +int deletebomb_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { - if (delete_flag) return MPI_SUCCESS; + if (delete_flag) + return MPI_SUCCESS; return MPI_ERR_OTHER; } -void abort_msg( const char *str, int code ) +void abort_msg(const char *str, int code) { - fprintf( stderr, "%s, err = %d\n", str, code ); - MPI_Abort( MPI_COMM_WORLD, code ); - exit(code); + fprintf(stderr, "%s, err = %d\n", str, code); + MPI_Abort(MPI_COMM_WORLD, code); } -int test_communicators( void ) +int test_communicators(void) { MPI_Comm dup_comm_world, d2; int world_rank, world_size, key_1; int err, errs = 0; MPI_Aint value; - MPI_Comm_rank( MPI_COMM_WORLD, &world_rank ); - MPI_Comm_size( MPI_COMM_WORLD, &world_size ); + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + MPI_Comm_size(MPI_COMM_WORLD, &world_size); #ifdef DEBUG if (world_rank == 0) { - printf( "*** Attribute copy/delete return codes ***\n" ); + printf("*** Attribute copy/delete return codes ***\n"); } #endif - MPI_Comm_dup( MPI_COMM_WORLD, &dup_comm_world ); - MPI_Barrier( dup_comm_world ); + MPI_Comm_dup(MPI_COMM_WORLD, &dup_comm_world); + MPI_Barrier(dup_comm_world); - MPI_Errhandler_set( dup_comm_world, MPI_ERRORS_RETURN ); + MPI_Errhandler_set(dup_comm_world, MPI_ERRORS_RETURN); - value = - 11; - if ((err=MPI_Comm_create_keyval( copybomb_fn, deletebomb_fn, &key_1, &value ))) - abort_msg( "Keyval_create", err ); + value = -11; + if ((err = MPI_Comm_create_keyval(copybomb_fn, deletebomb_fn, &key_1, &value))) + abort_msg("Keyval_create", err); - err = MPI_Comm_set_attr( dup_comm_world, key_1, (void *) (MPI_Aint) world_rank ); + err = MPI_Comm_set_attr(dup_comm_world, key_1, (void *) (MPI_Aint) world_rank); if (err) { - errs++; - printf( "Error with first put\n" ); + errs++; + printf("Error with first put\n"); } - err = MPI_Comm_set_attr( dup_comm_world, key_1, (void *) (MPI_Aint) (2*world_rank) ); + err = MPI_Comm_set_attr(dup_comm_world, key_1, (void *) (MPI_Aint) (2 * world_rank)); if (err == MPI_SUCCESS) { - errs++; - printf( "delete function return code was MPI_SUCCESS in put\n" ); + errs++; + printf("delete function return code was MPI_SUCCESS in put\n"); } /* Because the attribute delete function should fail, the attribute - should *not be removed* */ - err = MPI_Comm_delete_attr( dup_comm_world, key_1 ); + * should *not be removed* */ + err = MPI_Comm_delete_attr(dup_comm_world, key_1); if (err == MPI_SUCCESS) { - errs++; - printf( "delete function return code was MPI_SUCCESS in delete\n" ); + errs++; + printf("delete function return code was MPI_SUCCESS in delete\n"); } - - err = MPI_Comm_dup( dup_comm_world, &d2 ); + + err = MPI_Comm_dup(dup_comm_world, &d2); if (err == MPI_SUCCESS) { - errs++; - printf( "copy function return code was MPI_SUCCESS in dup\n" ); + errs++; + printf("copy function return code was MPI_SUCCESS in dup\n"); } if (err != MPI_ERR_OTHER) { - int lerrclass; - MPI_Error_class( err, &lerrclass ); - if (lerrclass != MPI_ERR_OTHER) { - errs++; - printf( "dup did not return an error code of class ERR_OTHER; " ); - printf( "err = %d, class = %d\n", err, lerrclass ); - } + int lerrclass; + MPI_Error_class(err, &lerrclass); + if (lerrclass != MPI_ERR_OTHER) { + errs++; + printf("dup did not return an error code of class ERR_OTHER; "); + printf("err = %d, class = %d\n", err, lerrclass); + } } #ifndef USE_STRICT_MPI /* Another interpretation is to leave d2 unchanged on error */ if (err && d2 != MPI_COMM_NULL) { - errs++; - printf( "dup did not return MPI_COMM_NULL on error\n" ); + errs++; + printf("dup did not return MPI_COMM_NULL on error\n"); } #endif delete_flag = 1; - MPI_Comm_free( &dup_comm_world ); + MPI_Comm_free(&dup_comm_world); - MPI_Comm_free_keyval( &key_1 ); + MPI_Comm_free_keyval(&key_1); return errs; } - diff --git a/teshsuite/smpi/mpich3-test/attr/attrerrtype.c b/teshsuite/smpi/mpich3-test/attr/attrerrtype.c index 19a27cbbed..567ea9ef5b 100644 --- a/teshsuite/smpi/mpich3-test/attr/attrerrtype.c +++ b/teshsuite/smpi/mpich3-test/attr/attrerrtype.c @@ -16,35 +16,35 @@ #include "mpi.h" #include "mpitest.h" -int test_attrs ( void ); -void abort_msg ( const char *, int ); -int copybomb_fn ( MPI_Datatype, int, void *, void *, void *, int * ); -int deletebomb_fn ( MPI_Datatype, int, void *, void * ); +int test_attrs(void); +void abort_msg(const char *, int); +int copybomb_fn(MPI_Datatype, int, void *, void *, void *, int *); +int deletebomb_fn(MPI_Datatype, int, void *, void *); -int main( int argc, char **argv ) +int main(int argc, char **argv) { int errs; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); errs = test_attrs(); - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } -/* - * MPI 1.2 Clarification: Clarification of Error Behavior of - * Attribute Callback Functions +/* + * MPI 1.2 Clarification: Clarification of Error Behavior of + * Attribute Callback Functions * Any return value other than MPI_SUCCESS is erroneous. The specific value * returned to the user is undefined (other than it can't be MPI_SUCCESS). * Proposals to specify particular values (e.g., user's value) failed. */ /* Return an error as the value */ -int copybomb_fn( MPI_Datatype oldtype, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, int *flag) +int copybomb_fn(MPI_Datatype oldtype, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Note that if (sizeof(int) < sizeof(void *), just setting the int - part of attribute_val_out may leave some dirty bits - */ + * part of attribute_val_out may leave some dirty bits + */ *flag = 1; return MPI_ERR_OTHER; } @@ -53,88 +53,87 @@ int copybomb_fn( MPI_Datatype oldtype, int keyval, void *extra_state, static int delete_flag = 0; static int deleteCalled = 0; -int deletebomb_fn( MPI_Datatype type, int keyval, void *attribute_val, - void *extra_state) +int deletebomb_fn(MPI_Datatype type, int keyval, void *attribute_val, void *extra_state) { - deleteCalled ++; - if (delete_flag) return MPI_SUCCESS; + deleteCalled++; + if (delete_flag) + return MPI_SUCCESS; return MPI_ERR_OTHER; } -void abort_msg( const char *str, int code ) +void abort_msg(const char *str, int code) { - fprintf( stderr, "%s, err = %d\n", str, code ); - MPI_Abort( MPI_COMM_WORLD, code ); - exit(code); + fprintf(stderr, "%s, err = %d\n", str, code); + MPI_Abort(MPI_COMM_WORLD, code); } -int test_attrs( void ) +int test_attrs(void) { MPI_Datatype dup_type, d2; int world_rank, world_size, key_1; int err, errs = 0; MPI_Aint value; - MPI_Comm_rank( MPI_COMM_WORLD, &world_rank ); - MPI_Comm_size( MPI_COMM_WORLD, &world_size ); + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + MPI_Comm_size(MPI_COMM_WORLD, &world_size); #ifdef DEBUG if (world_rank == 0) { - printf( "*** Attribute copy/delete return codes ***\n" ); + printf("*** Attribute copy/delete return codes ***\n"); } #endif - - MPI_Type_dup( MPI_DOUBLE, &dup_type ); - MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN ); + MPI_Type_dup(MPI_DOUBLE, &dup_type); + + MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN); - value = - 11; - if ((err=MPI_Type_create_keyval( copybomb_fn, deletebomb_fn, &key_1, &value ))) - abort_msg( "Keyval_create", err ); + value = -11; + if ((err = MPI_Type_create_keyval(copybomb_fn, deletebomb_fn, &key_1, &value))) + abort_msg("Keyval_create", err); - err = MPI_Type_set_attr( dup_type, key_1, (void *) (MPI_Aint) world_rank ); + err = MPI_Type_set_attr(dup_type, key_1, (void *) (MPI_Aint) world_rank); if (err) { - errs++; - printf( "Error with first put\n" ); + errs++; + printf("Error with first put\n"); } - err = MPI_Type_set_attr( dup_type, key_1, (void *) (MPI_Aint) (2*world_rank) ); + err = MPI_Type_set_attr(dup_type, key_1, (void *) (MPI_Aint) (2 * world_rank)); if (err == MPI_SUCCESS) { - errs++; - printf( "delete function return code was MPI_SUCCESS in put\n" ); + errs++; + printf("delete function return code was MPI_SUCCESS in put\n"); } /* Because the attribute delete function should fail, the attribute - should *not be removed* */ - err = MPI_Type_delete_attr( dup_type, key_1 ); + * should *not be removed* */ + err = MPI_Type_delete_attr(dup_type, key_1); if (err == MPI_SUCCESS) { - errs++; - printf( "delete function return code was MPI_SUCCESS in delete\n" ); + errs++; + printf("delete function return code was MPI_SUCCESS in delete\n"); } - - err = MPI_Type_dup( dup_type, &d2 ); + + err = MPI_Type_dup(dup_type, &d2); if (err == MPI_SUCCESS) { - errs++; - printf( "copy function return code was MPI_SUCCESS in dup\n" ); + errs++; + printf("copy function return code was MPI_SUCCESS in dup\n"); } #ifndef USE_STRICT_MPI /* Another interpretation is to leave d2 unchanged on error */ if (err && d2 != MPI_DATATYPE_NULL) { - errs++; - printf( "dup did not return MPI_DATATYPE_NULL on error\n" ); + errs++; + printf("dup did not return MPI_DATATYPE_NULL on error\n"); } #endif - delete_flag = 1; + delete_flag = 1; deleteCalled = 0; - if (d2 != MPI_DATATYPE_NULL) - MPI_Type_free(&d2); - MPI_Type_free( &dup_type ); + if (d2 != MPI_DATATYPE_NULL) + MPI_Type_free(&d2); + MPI_Type_free(&dup_type); if (deleteCalled == 0) { - errs++; - printf( "Free of a datatype did not invoke the attribute delete routine\n" ); + errs++; + printf("Free of a datatype did not invoke the attribute delete routine\n"); } - MPI_Type_free_keyval( &key_1 ); + MPI_Type_free_keyval(&key_1); return errs; } diff --git a/teshsuite/smpi/mpich3-test/attr/attric.c b/teshsuite/smpi/mpich3-test/attr/attric.c index 9b3b04c723..25d7a6d93d 100644 --- a/teshsuite/smpi/mpich3-test/attr/attric.c +++ b/teshsuite/smpi/mpich3-test/attr/attric.c @@ -17,143 +17,137 @@ #include "mpitest.h" /* #define DEBUG */ -int test_communicators ( void ); -int copy_fn ( MPI_Comm, int, void *, void *, void *, int * ); -int delete_fn ( MPI_Comm, int, void *, void * ); +int test_communicators(void); +int copy_fn(MPI_Comm, int, void *, void *, void *, int *); +int delete_fn(MPI_Comm, int, void *, void *); #ifdef DEBUG #define FFLUSH fflush(stdout); #else #define FFLUSH #endif -int main( int argc, char **argv ) +int main(int argc, char **argv) { int errs = 0; - MTest_Init( &argc, &argv ); - + MTest_Init(&argc, &argv); + errs = test_communicators(); - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } -int copy_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, int *flag) +int copy_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Note that if (sizeof(int) < sizeof(void *), just setting the int - part of attribute_val_out may leave some dirty bits - */ - *(MPI_Aint *)attribute_val_out = (MPI_Aint)attribute_val_in; + * part of attribute_val_out may leave some dirty bits + */ + *(MPI_Aint *) attribute_val_out = (MPI_Aint) attribute_val_in; *flag = 1; return MPI_SUCCESS; } -int delete_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state) +int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { int world_rank; - MPI_Comm_rank( MPI_COMM_WORLD, &world_rank ); - if ((MPI_Aint)attribute_val != (MPI_Aint)world_rank) { - printf( "incorrect attribute value %d\n", *(int*)attribute_val ); - MPI_Abort(MPI_COMM_WORLD, 1005 ); - exit(1005); + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + if ((MPI_Aint) attribute_val != (MPI_Aint) world_rank) { + printf("incorrect attribute value %d\n", *(int *) attribute_val); + MPI_Abort(MPI_COMM_WORLD, 1005); } return MPI_SUCCESS; } -int test_communicators( void ) +int test_communicators(void) { MPI_Comm dup_comm, comm; void *vvalue; int flag, world_rank, world_size, key_1, key_3; int errs = 0; MPI_Aint value; - int isLeft; + int isLeft; - MPI_Comm_rank( MPI_COMM_WORLD, &world_rank ); - MPI_Comm_size( MPI_COMM_WORLD, &world_size ); + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + MPI_Comm_size(MPI_COMM_WORLD, &world_size); #ifdef DEBUG if (world_rank == 0) { - printf( "*** Communicators ***\n" ); fflush(stdout); + printf("*** Communicators ***\n"); + fflush(stdout); } #endif - while (MTestGetIntercomm( &comm, &isLeft, 2 )) { + while (MTestGetIntercomm(&comm, &isLeft, 2)) { MTestPrintfMsg(1, "start while loop, isLeft=%s\n", (isLeft ? "TRUE" : "FALSE")); - if (comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { MTestPrintfMsg(1, "got COMM_NULL, skipping\n"); continue; } - /* - Check Comm_dup by adding attributes to comm & duplicating - */ - - value = 9; - MPI_Keyval_create(copy_fn, delete_fn, &key_1, &value ); + /* + * Check Comm_dup by adding attributes to comm & duplicating + */ + + value = 9; + MPI_Keyval_create(copy_fn, delete_fn, &key_1, &value); MTestPrintfMsg(1, "Keyval_create key=%#x value=%d\n", key_1, value); - value = 7; - MPI_Keyval_create(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, - &key_3, &value ); + value = 7; + MPI_Keyval_create(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key_3, &value); MTestPrintfMsg(1, "Keyval_create key=%#x value=%d\n", key_3, value); - /* This may generate a compilation warning; it is, however, an - easy way to cache a value instead of a pointer */ - /* printf( "key1 = %x key3 = %x\n", key_1, key_3 ); */ - MPI_Attr_put(comm, key_1, (void *) (MPI_Aint) world_rank ); - MPI_Attr_put(comm, key_3, (void *)0 ); - - MTestPrintfMsg(1, "Comm_dup\n" ); - MPI_Comm_dup(comm, &dup_comm ); - - /* Note that if sizeof(int) < sizeof(void *), we can't use - (void **)&value to get the value we passed into Attr_put. To avoid - problems (e.g., alignment errors), we recover the value into - a (void *) and cast to int. Note that this may generate warning - messages from the compiler. */ - MPI_Attr_get(dup_comm, key_1, (void **)&vvalue, &flag ); - value = (MPI_Aint)vvalue; - - if (! flag) { - errs++; - printf( "dup_comm key_1 not found on %d\n", world_rank ); - fflush( stdout ); - MPI_Abort(MPI_COMM_WORLD, 3004 ); - exit(3004); - } - - if (value != world_rank) { - errs++; - printf( "dup_comm key_1 value incorrect: %ld\n", (long)value ); - fflush( stdout ); - MPI_Abort(MPI_COMM_WORLD, 3005 ); - exit(3005); - } - - MPI_Attr_get(dup_comm, key_3, (void **)&vvalue, &flag ); - value = (MPI_Aint)vvalue; - if (flag) { - errs++; - printf( "dup_comm key_3 found!\n" ); - fflush( stdout ); - MPI_Abort(MPI_COMM_WORLD, 3008 ); - exit(3008); - } + /* This may generate a compilation warning; it is, however, an + * easy way to cache a value instead of a pointer */ + /* printf("key1 = %x key3 = %x\n", key_1, key_3); */ + MPI_Attr_put(comm, key_1, (void *) (MPI_Aint) world_rank); + MPI_Attr_put(comm, key_3, (void *) 0); + + MTestPrintfMsg(1, "Comm_dup\n"); + MPI_Comm_dup(comm, &dup_comm); + + /* Note that if sizeof(int) < sizeof(void *), we can't use + * (void **)&value to get the value we passed into Attr_put. To avoid + * problems (e.g., alignment errors), we recover the value into + * a (void *) and cast to int. Note that this may generate warning + * messages from the compiler. */ + MPI_Attr_get(dup_comm, key_1, (void **) &vvalue, &flag); + value = (MPI_Aint) vvalue; + + if (!flag) { + errs++; + printf("dup_comm key_1 not found on %d\n", world_rank); + fflush(stdout); + MPI_Abort(MPI_COMM_WORLD, 3004); + } + + if (value != world_rank) { + errs++; + printf("dup_comm key_1 value incorrect: %ld\n", (long) value); + fflush(stdout); + MPI_Abort(MPI_COMM_WORLD, 3005); + } + + MPI_Attr_get(dup_comm, key_3, (void **) &vvalue, &flag); + value = (MPI_Aint) vvalue; + if (flag) { + errs++; + printf("dup_comm key_3 found!\n"); + fflush(stdout); + MPI_Abort(MPI_COMM_WORLD, 3008); + } MTestPrintfMsg(1, "Keyval_free key=%#x\n", key_1); - MPI_Keyval_free(&key_1 ); + MPI_Keyval_free(&key_1); MTestPrintfMsg(1, "Keyval_free key=%#x\n", key_3); - MPI_Keyval_free(&key_3 ); - /* - Free all communicators created - */ + MPI_Keyval_free(&key_3); + /* + * Free all communicators created + */ MTestPrintfMsg(1, "Comm_free comm\n"); - MPI_Comm_free( &comm ); + MPI_Comm_free(&comm); MTestPrintfMsg(1, "Comm_free dup_comm\n"); - MPI_Comm_free( &dup_comm ); + MPI_Comm_free(&dup_comm); } return errs; } - diff --git a/teshsuite/smpi/mpich3-test/attr/attrorder.c b/teshsuite/smpi/mpich3-test/attr/attrorder.c index d1539aedc3..0fd53bdc8d 100644 --- a/teshsuite/smpi/mpich3-test/attr/attrorder.c +++ b/teshsuite/smpi/mpich3-test/attr/attrorder.c @@ -13,111 +13,108 @@ static char MTestDescrip[] = "Test creating and inserting attributes in \ different orders to ensure that the list management code handles all cases."; */ -int checkAttrs( MPI_Comm comm, int n, int key[], int attrval[] ); -int checkNoAttrs( MPI_Comm comm, int n, int key[] ); +int checkAttrs(MPI_Comm comm, int n, int key[], int attrval[]); +int checkNoAttrs(MPI_Comm comm, int n, int key[]); -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int key[3], attrval[3]; int i; MPI_Comm comm; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); { - comm = MPI_COMM_WORLD; - /* Create key values */ - for (i=0; i<3; i++) { - MPI_Keyval_create( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, - &key[i], (void *)0 ); - attrval[i] = 1024 * i; - } - - /* Insert attribute in several orders. Test after put with get, - then delete, then confirm delete with get. */ - - MPI_Attr_put( comm, key[2], &attrval[2] ); - MPI_Attr_put( comm, key[1], &attrval[1] ); - MPI_Attr_put( comm, key[0], &attrval[0] ); - - errs += checkAttrs( comm, 3, key, attrval ); - - MPI_Attr_delete( comm, key[0] ); - MPI_Attr_delete( comm, key[1] ); - MPI_Attr_delete( comm, key[2] ); - - errs += checkNoAttrs( comm, 3, key ); - - MPI_Attr_put( comm, key[1], &attrval[1] ); - MPI_Attr_put( comm, key[2], &attrval[2] ); - MPI_Attr_put( comm, key[0], &attrval[0] ); - - errs += checkAttrs( comm, 3, key, attrval ); - - MPI_Attr_delete( comm, key[2] ); - MPI_Attr_delete( comm, key[1] ); - MPI_Attr_delete( comm, key[0] ); - - errs += checkNoAttrs( comm, 3, key ); - - MPI_Attr_put( comm, key[0], &attrval[0] ); - MPI_Attr_put( comm, key[1], &attrval[1] ); - MPI_Attr_put( comm, key[2], &attrval[2] ); - - errs += checkAttrs( comm, 3, key, attrval ); - - MPI_Attr_delete( comm, key[1] ); - MPI_Attr_delete( comm, key[2] ); - MPI_Attr_delete( comm, key[0] ); - - errs += checkNoAttrs( comm, 3, key ); - - for (i=0; i<3; i++) { - MPI_Keyval_free( &key[i] ); - } + comm = MPI_COMM_WORLD; + /* Create key values */ + for (i = 0; i < 3; i++) { + MPI_Keyval_create(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0); + attrval[i] = 1024 * i; + } + + /* Insert attribute in several orders. Test after put with get, + * then delete, then confirm delete with get. */ + + MPI_Attr_put(comm, key[2], &attrval[2]); + MPI_Attr_put(comm, key[1], &attrval[1]); + MPI_Attr_put(comm, key[0], &attrval[0]); + + errs += checkAttrs(comm, 3, key, attrval); + + MPI_Attr_delete(comm, key[0]); + MPI_Attr_delete(comm, key[1]); + MPI_Attr_delete(comm, key[2]); + + errs += checkNoAttrs(comm, 3, key); + + MPI_Attr_put(comm, key[1], &attrval[1]); + MPI_Attr_put(comm, key[2], &attrval[2]); + MPI_Attr_put(comm, key[0], &attrval[0]); + + errs += checkAttrs(comm, 3, key, attrval); + + MPI_Attr_delete(comm, key[2]); + MPI_Attr_delete(comm, key[1]); + MPI_Attr_delete(comm, key[0]); + + errs += checkNoAttrs(comm, 3, key); + + MPI_Attr_put(comm, key[0], &attrval[0]); + MPI_Attr_put(comm, key[1], &attrval[1]); + MPI_Attr_put(comm, key[2], &attrval[2]); + + errs += checkAttrs(comm, 3, key, attrval); + + MPI_Attr_delete(comm, key[1]); + MPI_Attr_delete(comm, key[2]); + MPI_Attr_delete(comm, key[0]); + + errs += checkNoAttrs(comm, 3, key); + + for (i = 0; i < 3; i++) { + MPI_Keyval_free(&key[i]); + } } - - MTest_Finalize( errs ); + + MTest_Finalize(errs); MPI_Finalize(); return 0; - + } -int checkAttrs( MPI_Comm comm, int n, int key[], int attrval[] ) +int checkAttrs(MPI_Comm comm, int n, int key[], int attrval[]) { int errs = 0; int i, flag, *val_p; - for (i=0; i= size) && vval != MPI_PROC_NULL) { - errs++; - fprintf( stderr, "Got invalid value %d for HOST\n", vval ); - } - } + if (!flag) { + errs++; + fprintf(stderr, "Could not get HOST\n"); + } + else { + vval = *(int *) v; + if ((vval < 0 || vval >= size) && vval != MPI_PROC_NULL) { + errs++; + fprintf(stderr, "Got invalid value %d for HOST\n", vval); + } + } } - rc = MPI_Attr_get( MPI_COMM_WORLD, MPI_IO, &v, &flag ); + rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_IO, &v, &flag); if (rc) { - MissingKeyval( rc, "MPI_IO" ); - errs++; + MissingKeyval(rc, "MPI_IO"); + errs++; } else { - if (!flag) { - errs++; - fprintf( stderr, "Could not get IO\n" ); - } - else { - vval = *(int*)v; - if ((vval < 0 || vval >= size) && vval != MPI_ANY_SOURCE && - vval != MPI_PROC_NULL) { - errs++; - fprintf( stderr, "Got invalid value %d for IO\n", vval ); - } - } + if (!flag) { + errs++; + fprintf(stderr, "Could not get IO\n"); + } + else { + vval = *(int *) v; + if ((vval < 0 || vval >= size) && vval != MPI_ANY_SOURCE && vval != MPI_PROC_NULL) { + errs++; + fprintf(stderr, "Got invalid value %d for IO\n", vval); + } + } } - rc = MPI_Attr_get( MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag ); + rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag); if (rc) { - MissingKeyval( rc, "MPI_WTIME_IS_GLOBAL" ); - errs++; + MissingKeyval(rc, "MPI_WTIME_IS_GLOBAL"); + errs++; } else { - if (flag) { - /* Wtime need not be set */ - vval = *(int*)v; - if (vval < 0 || vval > 1) { - errs++; - fprintf( stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n", - vval ); - } - } + if (flag) { + /* Wtime need not be set */ + vval = *(int *) v; + if (vval < 0 || vval > 1) { + errs++; + fprintf(stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n", vval); + } + } } - rc = MPI_Attr_get( MPI_COMM_WORLD, MPI_APPNUM, &v, &flag ); + rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_APPNUM, &v, &flag); if (rc) { - MissingKeyval( rc, "MPI_APPNUM" ); - errs++; + MissingKeyval(rc, "MPI_APPNUM"); + errs++; } else { - /* appnum need not be set */ - if (flag) { - vval = *(int *)v; - if (vval < 0) { - errs++; - fprintf( stderr, "MPI_APPNUM is defined as %d but must be nonnegative\n", vval ); - } - } + /* appnum need not be set */ + if (flag) { + vval = *(int *) v; + if (vval < 0) { + errs++; + fprintf(stderr, "MPI_APPNUM is defined as %d but must be nonnegative\n", vval); + } + } } - rc = MPI_Attr_get( MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &v, &flag ); + rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &v, &flag); if (rc) { - MissingKeyval( rc, "MPI_UNIVERSE_SIZE" ); - errs++; + MissingKeyval(rc, "MPI_UNIVERSE_SIZE"); + errs++; } else { - /* MPI_UNIVERSE_SIZE need not be set */ - if (flag) { - vval = *(int *)v; - if (vval < size) { - errs++; - fprintf( stderr, "MPI_UNIVERSE_SIZE = %d, less than comm world (%d)\n", vval, size ); - } - } + /* MPI_UNIVERSE_SIZE need not be set */ + if (flag) { + vval = *(int *) v; + if (vval < size) { + errs++; + fprintf(stderr, "MPI_UNIVERSE_SIZE = %d, less than comm world (%d)\n", vval, size); + } + } } - rc = MPI_Attr_get( MPI_COMM_WORLD, MPI_LASTUSEDCODE, &v, &flag ); + rc = MPI_Attr_get(MPI_COMM_WORLD, MPI_LASTUSEDCODE, &v, &flag); if (rc) { - MissingKeyval( rc, "MPI_LASTUSEDCODE" ); - errs++; + MissingKeyval(rc, "MPI_LASTUSEDCODE"); + errs++; } else { - /* Last used code must be defined and >= MPI_ERR_LASTCODE */ - if (flag) { - vval = *(int*)v; - if (vval < MPI_ERR_LASTCODE) { - errs++; - fprintf( stderr, "MPI_LASTUSEDCODE points to an integer (%d) smaller than MPI_ERR_LASTCODE (%d)\n", vval, MPI_ERR_LASTCODE ); - } - } - else { - errs++; - fprintf( stderr, "MPI_LASTUSECODE is not defined\n" ); - } + /* Last used code must be defined and >= MPI_ERR_LASTCODE */ + if (flag) { + vval = *(int *) v; + if (vval < MPI_ERR_LASTCODE) { + errs++; + fprintf(stderr, + "MPI_LASTUSEDCODE points to an integer (%d) smaller than MPI_ERR_LASTCODE (%d)\n", + vval, MPI_ERR_LASTCODE); + } + } + else { + errs++; + fprintf(stderr, "MPI_LASTUSECODE is not defined\n"); + } } - MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL ); + MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL); + + MTest_Finalize(errs); + MPI_Finalize(); - MTest_Finalize( errs ); - MPI_Finalize( ); - return 0; } -void MissingKeyval( int errcode, const char keyname[] ) +void MissingKeyval(int errcode, const char keyname[]) { int errclass, slen; char string[MPI_MAX_ERROR_STRING]; - - MPI_Error_class( errcode, &errclass ); - MPI_Error_string( errcode, string, &slen ); - printf( "For key %s: Error class %d (%s)\n", keyname, errclass, string ); - fflush( stdout ); + + MPI_Error_class(errcode, &errclass); + MPI_Error_string(errcode, string, &slen); + printf("For key %s: Error class %d (%s)\n", keyname, errclass, string); + fflush(stdout); } diff --git a/teshsuite/smpi/mpich3-test/attr/baseattrcomm.c b/teshsuite/smpi/mpich3-test/attr/baseattrcomm.c index aaa76223bf..83c79718e8 100644 --- a/teshsuite/smpi/mpich3-test/attr/baseattrcomm.c +++ b/teshsuite/smpi/mpich3-test/attr/baseattrcomm.c @@ -8,111 +8,111 @@ #include "mpi.h" #include "mpitest.h" -int main( int argc, char **argv) +int main(int argc, char **argv) { - int errs = 0; + int errs = 0; void *v; - int flag; - int vval; - int rank, size; + int flag; + int vval; + int rank, size; - MTest_Init( &argc, &argv ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &size); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_TAG_UB, &v, &flag ); + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &v, &flag); if (!flag) { - errs++; - fprintf( stderr, "Could not get TAG_UB\n" ); + errs++; + fprintf(stderr, "Could not get TAG_UB\n"); } else { - vval = *(int*)v; - if (vval < 32767) { - errs++; - fprintf( stderr, "Got too-small value (%d) for TAG_UB\n", vval ); - } + vval = *(int *) v; + if (vval < 32767) { + errs++; + fprintf(stderr, "Got too-small value (%d) for TAG_UB\n", vval); + } } - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_HOST, &v, &flag ); + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_HOST, &v, &flag); if (!flag) { - errs++; - fprintf( stderr, "Could not get HOST\n" ); + errs++; + fprintf(stderr, "Could not get HOST\n"); } else { - vval = *(int*)v; - if ((vval < 0 || vval >= size) && vval != MPI_PROC_NULL) { - errs++; - fprintf( stderr, "Got invalid value %d for HOST\n", vval ); - } + vval = *(int *) v; + if ((vval < 0 || vval >= size) && vval != MPI_PROC_NULL) { + errs++; + fprintf(stderr, "Got invalid value %d for HOST\n", vval); + } } - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_IO, &v, &flag ); + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_IO, &v, &flag); if (!flag) { - errs++; - fprintf( stderr, "Could not get IO\n" ); + errs++; + fprintf(stderr, "Could not get IO\n"); } else { - vval = *(int*)v; - if ((vval < 0 || vval >= size) && vval != MPI_ANY_SOURCE && - vval != MPI_PROC_NULL) { - errs++; - fprintf( stderr, "Got invalid value %d for IO\n", vval ); - } + vval = *(int *) v; + if ((vval < 0 || vval >= size) && vval != MPI_ANY_SOURCE && vval != MPI_PROC_NULL) { + errs++; + fprintf(stderr, "Got invalid value %d for IO\n", vval); + } } - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag ); + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag); if (flag) { - /* Wtime need not be set */ - vval = *(int*)v; - if (vval < 0 || vval > 1) { - errs++; - fprintf( stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n", - vval ); - } + /* Wtime need not be set */ + vval = *(int *) v; + if (vval < 0 || vval > 1) { + errs++; + fprintf(stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n", vval); + } } /* MPI 2.0, section 5.5.3 - MPI_APPNUM should be set if the program is - started with more than one executable name (e.g., in MPMD instead - of SPMD mode). This is independent of the dynamic process routines, - and should be supported even if MPI_COMM_SPAWN and friends are not. */ - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_APPNUM, &v, &flag ); + * started with more than one executable name (e.g., in MPMD instead + * of SPMD mode). This is independent of the dynamic process routines, + * and should be supported even if MPI_COMM_SPAWN and friends are not. */ + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_APPNUM, &v, &flag); /* appnum need not be set */ if (flag) { - vval = *(int *)v; - if (vval < 0) { - errs++; - fprintf( stderr, "MPI_APPNUM is defined as %d but must be nonnegative\n", vval ); - } + vval = *(int *) v; + if (vval < 0) { + errs++; + fprintf(stderr, "MPI_APPNUM is defined as %d but must be nonnegative\n", vval); + } } /* MPI 2.0 section 5.5.1. MPI_UNIVERSE_SIZE need not be set, but - should be present. */ - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &v, &flag ); + * should be present. */ + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &v, &flag); /* MPI_UNIVERSE_SIZE need not be set */ if (flag) { - /* But if it is set, it must be at least the size of comm_world */ - vval = *(int *)v; - if (vval < size) { - errs++; - fprintf( stderr, "MPI_UNIVERSE_SIZE = %d, less than comm world (%d)\n", vval, size ); - } + /* But if it is set, it must be at least the size of comm_world */ + vval = *(int *) v; + if (vval < size) { + errs++; + fprintf(stderr, "MPI_UNIVERSE_SIZE = %d, less than comm world (%d)\n", vval, size); + } } - - MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_LASTUSEDCODE, &v, &flag ); + + MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_LASTUSEDCODE, &v, &flag); /* Last used code must be defined and >= MPI_ERR_LASTCODE */ if (flag) { - vval = *(int*)v; - if (vval < MPI_ERR_LASTCODE) { - errs++; - fprintf( stderr, "MPI_LASTUSEDCODE points to an integer (%d) smaller than MPI_ERR_LASTCODE (%d)\n", vval, MPI_ERR_LASTCODE ); - } + vval = *(int *) v; + if (vval < MPI_ERR_LASTCODE) { + errs++; + fprintf(stderr, + "MPI_LASTUSEDCODE points to an integer (%d) smaller than MPI_ERR_LASTCODE (%d)\n", + vval, MPI_ERR_LASTCODE); + } } else { - errs++; - fprintf( stderr, "MPI_LASTUSECODE is not defined\n" ); + errs++; + fprintf(stderr, "MPI_LASTUSECODE is not defined\n"); } - MTest_Finalize( errs ); - MPI_Finalize( ); - + MTest_Finalize(errs); + MPI_Finalize(); + return 0; } diff --git a/teshsuite/smpi/mpich3-test/attr/fkeyval.c b/teshsuite/smpi/mpich3-test/attr/fkeyval.c index 48722c1ece..ecaff99485 100644 --- a/teshsuite/smpi/mpich3-test/attr/fkeyval.c +++ b/teshsuite/smpi/mpich3-test/attr/fkeyval.c @@ -15,99 +15,92 @@ executed"; */ /* Function prototypes to keep compilers happy */ -int copy_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, - int *flag); -int delete_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state); +int copy_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag); +int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state); /* Copy increments the attribute value */ -int copy_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, - int *flag) +int copy_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Copy the address of the attribute */ - *(void **)attribute_val_out = attribute_val_in; + *(void **) attribute_val_out = attribute_val_in; /* Change the value */ - *(int *)attribute_val_in = *(int *)attribute_val_in + 1; + *(int *) attribute_val_in = *(int *) attribute_val_in + 1; /* set flag to 1 to tell comm dup to insert this attribute - into the new communicator */ + * into the new communicator */ *flag = 1; return MPI_SUCCESS; } /* Delete decrements the attribute value */ -int delete_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state) +int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { - *(int *)attribute_val = *(int *)attribute_val - 1; + *(int *) attribute_val = *(int *) attribute_val - 1; return MPI_SUCCESS; } -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int attrval; int i, key[32], keyval, saveKeyval; MPI_Comm comm, dupcomm; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - while (MTestGetIntracomm( &comm, 1 )) { - if (comm == MPI_COMM_NULL) continue; + while (MTestGetIntracomm(&comm, 1)) { + if (comm == MPI_COMM_NULL) + continue; - MPI_Keyval_create( copy_fn, delete_fn, &keyval, (void *)0 ); - saveKeyval = keyval; /* in case we need to free explicitly */ - attrval = 1; - MPI_Attr_put( comm, keyval, (void*)&attrval ); - /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it - is in use in an attribute */ - MPI_Keyval_free( &keyval ); - - /* We create some dummy keyvals here in case the same keyval - is reused */ - for (i=0; i<32; i++) { - MPI_Keyval_create( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, - &key[i], (void *)0 ); - } + MPI_Keyval_create(copy_fn, delete_fn, &keyval, (void *) 0); + saveKeyval = keyval; /* in case we need to free explicitly */ + attrval = 1; + MPI_Attr_put(comm, keyval, (void *) &attrval); + /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it + * is in use in an attribute */ + MPI_Keyval_free(&keyval); - MPI_Comm_dup( comm, &dupcomm ); - /* Check that the attribute was copied */ - if (attrval != 2) { - errs++; - printf( "Attribute not incremented when comm dup'ed (%s)\n", - MTestGetIntracommName() ); - } - MPI_Comm_free( &dupcomm ); - if (attrval != 1) { - errs++; - printf( "Attribute not decremented when dupcomm %s freed\n", - MTestGetIntracommName() ); - } - /* Check that the attribute was freed in the dupcomm */ + /* We create some dummy keyvals here in case the same keyval + * is reused */ + for (i = 0; i < 32; i++) { + MPI_Keyval_create(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0); + } - if (comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF) { - MPI_Comm_free( &comm ); - /* Check that the original attribute was freed */ - if (attrval != 0) { - errs++; - printf( "Attribute not decremented when comm %s freed\n", - MTestGetIntracommName() ); - } - } - else { - /* Explicitly delete the attributes from world and self */ - MPI_Attr_delete( comm, saveKeyval ); - } - /* Free those other keyvals */ - for (i=0; i<32; i++) { - MPI_Keyval_free( &key[i] ); - } + MPI_Comm_dup(comm, &dupcomm); + /* Check that the attribute was copied */ + if (attrval != 2) { + errs++; + printf("Attribute not incremented when comm dup'ed (%s)\n", MTestGetIntracommName()); + } + MPI_Comm_free(&dupcomm); + if (attrval != 1) { + errs++; + printf("Attribute not decremented when dupcomm %s freed\n", MTestGetIntracommName()); + } + /* Check that the attribute was freed in the dupcomm */ + + if (comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF) { + MPI_Comm_free(&comm); + /* Check that the original attribute was freed */ + if (attrval != 0) { + errs++; + printf("Attribute not decremented when comm %s freed\n", MTestGetIntracommName()); + } + } + else { + /* Explicitly delete the attributes from world and self */ + MPI_Attr_delete(comm, saveKeyval); + } + /* Free those other keyvals */ + for (i = 0; i < 32; i++) { + MPI_Keyval_free(&key[i]); + } } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); - /* The attributes on comm self and world were deleted by finalize - (see separate test) */ - + /* The attributes on comm self and world were deleted by finalize + * (see separate test) */ + return 0; } diff --git a/teshsuite/smpi/mpich3-test/attr/fkeyvalcomm.c b/teshsuite/smpi/mpich3-test/attr/fkeyvalcomm.c index e2e661449a..c6478968f4 100644 --- a/teshsuite/smpi/mpich3-test/attr/fkeyvalcomm.c +++ b/teshsuite/smpi/mpich3-test/attr/fkeyvalcomm.c @@ -15,100 +15,93 @@ executed"; */ /* Function prototypes to keep compilers happy */ -int copy_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, - int *flag); -int delete_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state); +int copy_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag); +int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state); /* Copy increments the attribute value */ -int copy_fn( MPI_Comm oldcomm, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, - int *flag) +int copy_fn(MPI_Comm oldcomm, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Copy the address of the attribute */ - *(void **)attribute_val_out = attribute_val_in; + *(void **) attribute_val_out = attribute_val_in; /* Change the value */ - *(int *)attribute_val_in = *(int *)attribute_val_in + 1; + *(int *) attribute_val_in = *(int *) attribute_val_in + 1; /* set flag to 1 to tell comm dup to insert this attribute - into the new communicator */ + * into the new communicator */ *flag = 1; return MPI_SUCCESS; } /* Delete decrements the attribute value */ -int delete_fn( MPI_Comm comm, int keyval, void *attribute_val, - void *extra_state) +int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state) { - *(int *)attribute_val = *(int *)attribute_val - 1; + *(int *) attribute_val = *(int *) attribute_val - 1; return MPI_SUCCESS; } -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int attrval; int i, key[32], keyval, saveKeyval; MPI_Comm comm, dupcomm; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - while (MTestGetIntracomm( &comm, 1 )) { - if (comm == MPI_COMM_NULL) continue; + while (MTestGetIntracomm(&comm, 1)) { + if (comm == MPI_COMM_NULL) + continue; - MPI_Comm_create_keyval( copy_fn, delete_fn, &keyval, (void *)0 ); - saveKeyval = keyval; /* in case we need to free explicitly */ - attrval = 1; - MPI_Comm_set_attr( comm, keyval, (void*)&attrval ); - /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it - is in use in an attribute */ - MPI_Comm_free_keyval( &keyval ); - - /* We create some dummy keyvals here in case the same keyval - is reused */ - for (i=0; i<32; i++) { - MPI_Comm_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, - &key[i], (void *)0 ); - } + MPI_Comm_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0); + saveKeyval = keyval; /* in case we need to free explicitly */ + attrval = 1; + MPI_Comm_set_attr(comm, keyval, (void *) &attrval); + /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it + * is in use in an attribute */ + MPI_Comm_free_keyval(&keyval); - MPI_Comm_dup( comm, &dupcomm ); - /* Check that the attribute was copied */ - if (attrval != 2) { - errs++; - printf( "Attribute not incremented when comm dup'ed (%s)\n", - MTestGetIntracommName() ); - } - MPI_Comm_free( &dupcomm ); - if (attrval != 1) { - errs++; - printf( "Attribute not decremented when dupcomm %s freed\n", - MTestGetIntracommName() ); - } - /* Check that the attribute was freed in the dupcomm */ + /* We create some dummy keyvals here in case the same keyval + * is reused */ + for (i = 0; i < 32; i++) { + MPI_Comm_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0); + } - if (comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF) { - MPI_Comm_free( &comm ); - /* Check that the original attribute was freed */ - if (attrval != 0) { - errs++; - printf( "Attribute not decremented when comm %s freed\n", - MTestGetIntracommName() ); - } - } - else { - /* Explicitly delete the attributes from world and self */ - MPI_Comm_delete_attr( comm, saveKeyval ); - } - /* Free those other keyvals */ - for (i=0; i<32; i++) { - MPI_Comm_free_keyval( &key[i] ); - } + MPI_Comm_dup(comm, &dupcomm); + /* Check that the attribute was copied */ + if (attrval != 2) { + errs++; + printf("Attribute not incremented when comm dup'ed (%s)\n", MTestGetIntracommName()); + } + MPI_Comm_free(&dupcomm); + if (attrval != 1) { + errs++; + printf("Attribute not decremented when dupcomm %s freed\n", MTestGetIntracommName()); + } + /* Check that the attribute was freed in the dupcomm */ + + if (comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF) { + MPI_Comm_free(&comm); + /* Check that the original attribute was freed */ + if (attrval != 0) { + errs++; + printf("Attribute not decremented when comm %s freed\n", MTestGetIntracommName()); + } + } + else { + /* Explicitly delete the attributes from world and self */ + MPI_Comm_delete_attr(comm, saveKeyval); + } + /* Free those other keyvals */ + for (i = 0; i < 32; i++) { + MPI_Comm_free_keyval(&key[i]); + } } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); - /* The attributes on comm self and world were deleted by finalize - (see separate test) */ - + /* The attributes on comm self and world were deleted by finalize + * (see separate test) */ + return 0; - + } diff --git a/teshsuite/smpi/mpich3-test/attr/fkeyvaltype.c b/teshsuite/smpi/mpich3-test/attr/fkeyvaltype.c index 392e51dec3..59cfe0b447 100644 --- a/teshsuite/smpi/mpich3-test/attr/fkeyvaltype.c +++ b/teshsuite/smpi/mpich3-test/attr/fkeyvaltype.c @@ -16,34 +16,30 @@ executed"; */ /* Copy increments the attribute value */ -int copy_fn( MPI_Datatype oldtype, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, - int *flag); -int copy_fn( MPI_Datatype oldtype, int keyval, void *extra_state, - void *attribute_val_in, void *attribute_val_out, - int *flag) +int copy_fn(MPI_Datatype oldtype, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag); +int copy_fn(MPI_Datatype oldtype, int keyval, void *extra_state, + void *attribute_val_in, void *attribute_val_out, int *flag) { /* Copy the address of the attribute */ - *(void **)attribute_val_out = attribute_val_in; + *(void **) attribute_val_out = attribute_val_in; /* Change the value */ - *(int *)attribute_val_in = *(int *)attribute_val_in + 1; + *(int *) attribute_val_in = *(int *) attribute_val_in + 1; /* set flag to 1 to tell comm dup to insert this attribute - into the new communicator */ + * into the new communicator */ *flag = 1; return MPI_SUCCESS; } /* Delete decrements the attribute value */ -int delete_fn( MPI_Datatype type, int keyval, void *attribute_val, - void *extra_state); -int delete_fn( MPI_Datatype type, int keyval, void *attribute_val, - void *extra_state) +int delete_fn(MPI_Datatype type, int keyval, void *attribute_val, void *extra_state); +int delete_fn(MPI_Datatype type, int keyval, void *attribute_val, void *extra_state) { - *(int *)attribute_val = *(int *)attribute_val - 1; + *(int *) attribute_val = *(int *) attribute_val - 1; return MPI_SUCCESS; } -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int attrval; @@ -53,75 +49,70 @@ int main( int argc, char *argv[] ) char typename[MPI_MAX_OBJECT_NAME]; int tnlen; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - while (MTestGetDatatypes( &mstype, &mrtype, 1 )) { - type = mstype.datatype; - MPI_Type_create_keyval( copy_fn, delete_fn, &keyval, (void *)0 ); - saveKeyval = keyval; /* in case we need to free explicitly */ - attrval = 1; - MPI_Type_set_attr( type, keyval, (void*)&attrval ); - /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it - is in use in an attribute */ - MPI_Type_free_keyval( &keyval ); - - /* We create some dummy keyvals here in case the same keyval - is reused */ - for (i=0; i<32; i++) { - MPI_Type_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, - &key[i], (void *)0 ); - } + while (MTestGetDatatypes(&mstype, &mrtype, 1)) { + type = mstype.datatype; + MPI_Type_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0); + saveKeyval = keyval; /* in case we need to free explicitly */ + attrval = 1; + MPI_Type_set_attr(type, keyval, (void *) &attrval); + /* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it + * is in use in an attribute */ + MPI_Type_free_keyval(&keyval); - if (attrval != 1) { - errs++; - MPI_Type_get_name( type, typename, &tnlen ); - printf( "attrval is %d, should be 1, before dup in type %s\n", - attrval, typename ); - } - MPI_Type_dup( type, &duptype ); - /* Check that the attribute was copied */ - if (attrval != 2) { - errs++; - MPI_Type_get_name( type, typename, &tnlen ); - printf( "Attribute not incremented when type dup'ed (%s)\n", - typename ); - } - MPI_Type_free( &duptype ); - if (attrval != 1) { - errs++; - MPI_Type_get_name( type, typename, &tnlen ); - printf( "Attribute not decremented when duptype %s freed\n", - typename ); - } - /* Check that the attribute was freed in the duptype */ + /* We create some dummy keyvals here in case the same keyval + * is reused */ + for (i = 0; i < 32; i++) { + MPI_Type_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0); + } - if (!mstype.isBasic) { - MPI_Type_get_name( type, typename, &tnlen ); + if (attrval != 1) { + errs++; + MPI_Type_get_name(type, typename, &tnlen); + printf("attrval is %d, should be 1, before dup in type %s\n", attrval, typename); + } + MPI_Type_dup(type, &duptype); + /* Check that the attribute was copied */ + if (attrval != 2) { + errs++; + MPI_Type_get_name(type, typename, &tnlen); + printf("Attribute not incremented when type dup'ed (%s)\n", typename); + } + MPI_Type_free(&duptype); + if (attrval != 1) { + errs++; + MPI_Type_get_name(type, typename, &tnlen); + printf("Attribute not decremented when duptype %s freed\n", typename); + } + /* Check that the attribute was freed in the duptype */ + + if (!mstype.isBasic) { + MPI_Type_get_name(type, typename, &tnlen); MTestFreeDatatype(&mstype); - /* Check that the original attribute was freed */ - if (attrval != 0) { - errs++; - printf( "Attribute not decremented when type %s freed\n", - typename ); - } - } - else { - /* Explicitly delete the attributes from world and self */ - MPI_Type_delete_attr( type, saveKeyval ); + /* Check that the original attribute was freed */ + if (attrval != 0) { + errs++; + printf("Attribute not decremented when type %s freed\n", typename); + } + } + else { + /* Explicitly delete the attributes from world and self */ + MPI_Type_delete_attr(type, saveKeyval); if (mstype.buf) { free(mstype.buf); mstype.buf = 0; } - } - /* Free those other keyvals */ - for (i=0; i<32; i++) { - MPI_Type_free_keyval( &key[i] ); - } + } + /* Free those other keyvals */ + for (i = 0; i < 32; i++) { + MPI_Type_free_keyval(&key[i]); + } MTestFreeDatatype(&mrtype); } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; - + } diff --git a/teshsuite/smpi/mpich3-test/attr/keyval_double_free.c b/teshsuite/smpi/mpich3-test/attr/keyval_double_free.c index 9b5eaa60fc..b331d9ac46 100644 --- a/teshsuite/smpi/mpich3-test/attr/keyval_double_free.c +++ b/teshsuite/smpi/mpich3-test/attr/keyval_double_free.c @@ -12,31 +12,32 @@ /* tests multiple invocations of Keyval_free on the same keyval */ int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra); -int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra) { +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra) +{ MPI_Keyval_free(&keyval); return MPI_SUCCESS; } -int main (int argc, char **argv) +int main(int argc, char **argv) { MPI_Comm duped; int keyval = MPI_KEYVAL_INVALID; int keyval_copy = MPI_KEYVAL_INVALID; - int errs=0; + int errs = 0; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); MPI_Comm_dup(MPI_COMM_SELF, &duped); - MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL); + MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL); keyval_copy = keyval; MPI_Attr_put(MPI_COMM_SELF, keyval, NULL); MPI_Attr_put(duped, keyval, NULL); - MPI_Comm_free(&duped); /* first MPI_Keyval_free */ - MPI_Keyval_free(&keyval); /* second MPI_Keyval_free */ - MPI_Keyval_free(&keyval_copy); /* third MPI_Keyval_free */ - MTest_Finalize( errs ); - MPI_Finalize(); /* fourth MPI_Keyval_free */ + MPI_Comm_free(&duped); /* first MPI_Keyval_free */ + MPI_Keyval_free(&keyval); /* second MPI_Keyval_free */ + MPI_Keyval_free(&keyval_copy); /* third MPI_Keyval_free */ + MTest_Finalize(errs); + MPI_Finalize(); /* fourth MPI_Keyval_free */ return 0; } diff --git a/teshsuite/smpi/mpich3-test/attr/keyval_double_free_comm.c b/teshsuite/smpi/mpich3-test/attr/keyval_double_free_comm.c new file mode 100644 index 0000000000..5baf9e64c5 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/attr/keyval_double_free_comm.c @@ -0,0 +1,43 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2009 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include +#include +#include +#include "mpitest.h" + +/* tests multiple invocations of MPI_Comm_free_keyval on the same keyval */ + +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra); +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra) +{ + MPI_Comm_free_keyval(&keyval); + return MPI_SUCCESS; +} + +int main(int argc, char **argv) +{ + MPI_Comm duped; + int keyval = MPI_KEYVAL_INVALID; + int keyval_copy = MPI_KEYVAL_INVALID; + int errs = 0; + + MTest_Init(&argc, &argv); + MPI_Comm_dup(MPI_COMM_SELF, &duped); + + MPI_Comm_create_keyval(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL); + keyval_copy = keyval; + + MPI_Comm_set_attr(MPI_COMM_SELF, keyval, NULL); + MPI_Comm_set_attr(duped, keyval, NULL); + + MPI_Comm_free(&duped); /* first MPI_Comm_free_keyval */ + MPI_Comm_free_keyval(&keyval); /* second MPI_Comm_free_keyval */ + MPI_Comm_free_keyval(&keyval_copy); /* third MPI_Comm_free_keyval */ + MTest_Finalize(errs); + MPI_Finalize(); /* fourth MPI_Comm_free_keyval */ + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/attr/keyval_double_free_type.c b/teshsuite/smpi/mpich3-test/attr/keyval_double_free_type.c new file mode 100644 index 0000000000..406d7e82a1 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/attr/keyval_double_free_type.c @@ -0,0 +1,45 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include +#include +#include +#include "mpitest.h" + +/* tests multiple invocations of MPI_Type_free_keyval on the same keyval */ + +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra); +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra) +{ + MPI_Type_free_keyval(&keyval); + return MPI_SUCCESS; +} + +int main(int argc, char **argv) +{ + MPI_Datatype type; + MPI_Datatype type_dup; + int keyval = MPI_KEYVAL_INVALID; + int keyval_copy = MPI_KEYVAL_INVALID; + int errs = 0; + + MTest_Init(&argc, &argv); + MPI_Type_dup(MPI_INT, &type); + MPI_Type_dup(MPI_INT, &type_dup); + + MPI_Type_create_keyval(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL); + keyval_copy = keyval; + MPI_Type_set_attr(type, keyval, NULL); + MPI_Type_set_attr(type_dup, keyval, NULL); + + MPI_Type_free(&type); /* first MPI_Type_free_keyval */ + MPI_Type_free_keyval(&keyval); /* second MPI_Type_free_keyval */ + MPI_Type_free_keyval(&keyval_copy); /* third MPI_Type_free_keyval */ + MPI_Type_free(&type_dup); /* fourth MPI_Type_free_keyval */ + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/attr/keyval_double_free_win.c b/teshsuite/smpi/mpich3-test/attr/keyval_double_free_win.c new file mode 100644 index 0000000000..a954da6868 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/attr/keyval_double_free_win.c @@ -0,0 +1,54 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include +#include +#include +#include "mpitest.h" + +#define NUM_WIN 2 +#define DATA_SZ sizeof(int) + +/* tests multiple invocations of MPI_Win_free_keyval on the same keyval */ + +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra); +int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra) +{ + MPI_Win_free_keyval(&keyval); + return MPI_SUCCESS; +} + +int main(int argc, char **argv) +{ + void *base_ptr[NUM_WIN]; + MPI_Win windows[NUM_WIN]; + int keyval = MPI_KEYVAL_INVALID; + int keyval_copy = MPI_KEYVAL_INVALID; + int errs = 0; + + MTest_Init(&argc, &argv); + MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptr[0]); + MPI_Win_create(base_ptr[0], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[0]); + MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptr[1]); + MPI_Win_create(base_ptr[1], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[1]); + + MPI_Win_create_keyval(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL); + keyval_copy = keyval; + + MPI_Win_set_attr(windows[0], keyval, NULL); + MPI_Win_set_attr(windows[1], keyval, NULL); + + MPI_Win_free(&windows[0]); /* first MPI_Win_free_keyval */ + MPI_Free_mem(base_ptr[0]); + MPI_Win_free_keyval(&keyval); /* second MPI_Win_free_keyval */ + MPI_Win_free_keyval(&keyval_copy); /* third MPI_Win_free_keyval */ + MPI_Win_free(&windows[1]); /* fourth MPI_Win_free_keyval */ + MPI_Free_mem(base_ptr[1]); + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} + diff --git a/teshsuite/smpi/mpich3-test/attr/testlist b/teshsuite/smpi/mpich3-test/attr/testlist index 83461d6feb..c798a8c772 100644 --- a/teshsuite/smpi/mpich3-test/attr/testlist +++ b/teshsuite/smpi/mpich3-test/attr/testlist @@ -13,6 +13,7 @@ attrerr 1 #attrend2 5 attrerrcomm 1 attrerrtype 1 +attrdeleteget 1 attr2type 1 attrorder 1 attrordercomm 1 -- 2.20.1