From: degomme Date: Sun, 12 Feb 2017 00:20:37 +0000 (+0100) Subject: Update RMA tests X-Git-Tag: v3_15~427 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4cdc0f888550cbaefe6094ae801230336d005337?hp=aac4ba41ea27fe8168bebed009abebd7e5c3f006 Update RMA tests --- diff --git a/teshsuite/smpi/mpich3-test/rma/CMakeLists.txt b/teshsuite/smpi/mpich3-test/rma/CMakeLists.txt index adf5e2ff95..4bedbee6d8 100644 --- a/teshsuite/smpi/mpich3-test/rma/CMakeLists.txt +++ b/teshsuite/smpi/mpich3-test/rma/CMakeLists.txt @@ -12,7 +12,9 @@ if(enable_smpi AND enable_smpi_MPICH3_testsuite) foreach(file accfence1 accfence2_am accfence2 accpscw1 allocmem epochtest getfence1 getgroup manyrma3 nullpscw putfence1 putfidx putpscw1 test1_am test1 test1_dt test2_am test2 test3 test5_am test5 transpose1 transpose2 - transpose3 transpose6 transpose7 window_creation) + transpose3 transpose6 transpose7 window_creation + at_complete acc-pairtype manyget large-small-acc + lock_nested) # not compiled files: acc-loc adlb_mimic1 attrorderwin badrma baseattrwin compare_and_swap contention_put # contention_putget contig_displ fence_shm fetchandadd_am fetchandadd fetchandadd_tree_am fetchandadd_tree # fetch_and_op fkeyvalwin flush get_acc_local get_accumulate ircpi linked_list_bench_lock_all @@ -22,7 +24,8 @@ if(enable_smpi AND enable_smpi_MPICH3_testsuite) # strided_acc_onelock strided_acc_subarray strided_getacc_indexed strided_getacc_indexed_shared strided_get_indexed # strided_putget_indexed strided_putget_indexed_shared test3_am test4_am test4 transpose4 transpose5 wincall # win_dynamic_acc win_flavors win_info winname win_shared win_shared_noncontig win_shared_noncontig_put - # win_large_shm win_zero wintest + # win_large_shm win_zero wintest get-struct atomic_rmw_fop atomic_rmw_gacc rget-unlock atomic_get atomic_rmw_cas + # win_shared_zerobyte aint add_executable(${file} ${file}.c) target_link_libraries(${file} simgrid mtest_c) set_target_properties(${file} PROPERTIES COMPILE_FLAGS "${MPICH_FLAGS}") @@ -46,7 +49,9 @@ foreach(file accfence1 accfence2_am accfence2 accpscw1 allocmem epochtest getfen strided_acc_subarray strided_getacc_indexed strided_getacc_indexed_shared strided_get_indexed strided_putget_indexed strided_putget_indexed_shared test3_am test4_am test4 transpose4 transpose5 wincall win_dynamic_acc win_flavors win_info winname win_shared win_shared_noncontig win_shared_noncontig_put - win_large_shm win_zero wintest) + win_large_shm win_zero wintest win_shared_zerobyte get-struct + at_complete atomic_rmw_fop atomic_rmw_cas atomic_rmw_gacc atomic_get aint acc-pairtype manyget large-small-acc + rget-unlock overlap_wins_rma lock_nested) set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${file}.c) endforeach() diff --git a/teshsuite/smpi/mpich3-test/rma/acc-loc.c b/teshsuite/smpi/mpich3-test/rma/acc-loc.c index 18c3e3a947..6e76970636 100644 --- a/teshsuite/smpi/mpich3-test/rma/acc-loc.c +++ b/teshsuite/smpi/mpich3-test/rma/acc-loc.c @@ -20,7 +20,8 @@ typedef struct { static int errors = 0; -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int me, nproc; twoint_t *data = NULL; twoint_t mine; @@ -76,10 +77,10 @@ int main(int argc, char **argv) { MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win); MPI_Win_fence(0, win); - if (me == 0 && (data->loc != nproc-1 || data->val != 1)) { + if (me == 0 && (data->loc != nproc - 1 || data->val != 1)) { errors++; printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n", - nproc-1, 1, data->loc, data->val); + nproc - 1, 1, data->loc, data->val); } /* All processes perform MAXLOC and MINLOC operations on a 2INT on rank 0. diff --git a/teshsuite/smpi/mpich3-test/rma/acc-pairtype.c b/teshsuite/smpi/mpich3-test/rma/acc-pairtype.c new file mode 100644 index 0000000000..5c2343509e --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/acc-pairtype.c @@ -0,0 +1,87 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This test is going to test when Accumulate operation is working + * with pair types. */ + +#include "mpi.h" +#include + +#define DATA_SIZE 25 + +typedef struct long_double_int { + long double a; + int b; +} long_double_int_t; + +int main(int argc, char *argv[]) +{ + MPI_Win win; + int errors = 0; + int rank, nproc, i; + long_double_int_t *orig_buf; + long_double_int_t *tar_buf; + MPI_Datatype vector_dtp; + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Alloc_mem(sizeof(long_double_int_t) * DATA_SIZE, MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(sizeof(long_double_int_t) * DATA_SIZE, MPI_INFO_NULL, &tar_buf); + + for (i = 0; i < DATA_SIZE; i++) { + orig_buf[i].a = 1.0; + orig_buf[i].b = 1; + tar_buf[i].a = 0; + tar_buf[i].b = 0; + } + + MPI_Type_vector(5 /* count */ , 3 /* blocklength */ , 5 /* stride */ , MPI_LONG_DOUBLE_INT, + &vector_dtp); + MPI_Type_commit(&vector_dtp); + + MPI_Win_create(tar_buf, sizeof(long_double_int_t) * DATA_SIZE, sizeof(long_double_int_t), + MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + if (rank == 0) { + MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win); + MPI_Accumulate(orig_buf, 1, vector_dtp, 1, 0, 1, vector_dtp, MPI_MAXLOC, win); + MPI_Win_unlock(1, win); + } + + MPI_Win_free(&win); + + if (rank == 1) { + for (i = 0; i < DATA_SIZE; i++) { + if (i % 5 < 3) { + if (tar_buf[i].a != 1.0 || tar_buf[i].b != 1) { + errors++; + } + } + else { + if (tar_buf[i].a != 0.0 || tar_buf[i].b != 0) { + errors++; + } + } + } + } + + MPI_Type_free(&vector_dtp); + + MPI_Free_mem(orig_buf); + MPI_Free_mem(tar_buf); + + if (rank == 1) { + if (errors == 0) + printf(" No Errors\n"); + } + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/accfence1.c b/teshsuite/smpi/mpich3-test/rma/accfence1.c index 91d9f439cb..f4b8930d6b 100644 --- a/teshsuite/smpi/mpich3-test/rma/accfence1.c +++ b/teshsuite/smpi/mpich3-test/rma/accfence1.c @@ -12,92 +12,93 @@ static char MTEST_Descrip[] = "Accumulate/Replace with Fence"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0, err; int rank, size, source, dest; - int minsize = 2, count; - MPI_Comm comm; - MPI_Win win; - MPI_Aint extent; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint extent, lb; MTestDatatype sendtype, recvtype; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - /* The following illustrates the use of the routines to - run through a selection of communicators and datatypes. - Use subsets of these for tests that do not involve combinations - of communicators, datatypes, and counts of datatypes */ - while (MTestGetIntracommGeneral( &comm, minsize, 1 )) { - if (comm == MPI_COMM_NULL) continue; - /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); - source = 0; - dest = size - 1; - - for (count = 1; count < 65000; count = count * 2) { - while (MTestGetDatatypes( &sendtype, &recvtype, count )) { - /* Make sure that everyone has a recv buffer */ - recvtype.InitBuf( &recvtype ); + /* The following illustrates the use of the routines to + * run through a selection of communicators and datatypes. + * Use subsets of these for tests that do not involve combinations + * of communicators, datatypes, and counts of datatypes */ + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; - MPI_Type_extent( recvtype.datatype, &extent ); - MPI_Win_create( recvtype.buf, recvtype.count * extent, - (int)extent, MPI_INFO_NULL, comm, &win ); - MPI_Win_fence( 0, win ); - if (rank == source) { - sendtype.InitBuf( &sendtype ); + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + /* Make sure that everyone has a recv buffer */ + recvtype.InitBuf(&recvtype); - /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); - - /* MPI_REPLACE on accumulate is almost the same - as MPI_Put; the only difference is in the - handling of overlapping accumulate operations, - which are not tested here */ - err = MPI_Accumulate( sendtype.buf, sendtype.count, - sendtype.datatype, dest, 0, - recvtype.count, recvtype.datatype, - MPI_REPLACE, win ); - if (err) { - errs++; - if (errs < 10) { - printf( "Accumulate types: send %s, recv %s\n", - MTestGetDatatypeName( &sendtype ), - MTestGetDatatypeName( &recvtype ) ); - MTestPrintError( err ); - } - } - err = MPI_Win_fence( 0, win ); - if (err) { - errs++; - if (errs < 10) { - MTestPrintError( err ); - } - } - } - else if (rank == dest) { - MPI_Win_fence( 0, win ); - /* This should have the same effect, in terms of - transfering data, as a send/recv pair */ - err = MTestCheckRecv( 0, &recvtype ); - if (err) { - errs += err; - } - } - else { - MPI_Win_fence( 0, win ); - } - MPI_Win_free( &win ); - MTestFreeDatatype( &sendtype ); - MTestFreeDatatype( &recvtype ); - } - } + MPI_Type_extent(recvtype.datatype, &extent); + MPI_Type_lb(recvtype.datatype, &lb); + MPI_Win_create(recvtype.buf, recvtype.count * extent + lb, + (int) extent, MPI_INFO_NULL, comm, &win); + MPI_Win_fence(0, win); + if (rank == source) { + sendtype.InitBuf(&sendtype); + + /* To improve reporting of problems about operations, we + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); + + /* MPI_REPLACE on accumulate is almost the same + * as MPI_Put; the only difference is in the + * handling of overlapping accumulate operations, + * which are not tested here */ + err = MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + if (err) { + errs++; + if (errs < 10) { + printf("Accumulate types: send %s, recv %s\n", + MTestGetDatatypeName(&sendtype), + MTestGetDatatypeName(&recvtype)); + MTestPrintError(err); + } + } + err = MPI_Win_fence(0, win); + if (err) { + errs++; + if (errs < 10) { + MTestPrintError(err); + } + } + } + else if (rank == dest) { + MPI_Win_fence(0, win); + /* This should have the same effect, in terms of + * transfering data, as a send/recv pair */ + err = MTestCheckRecv(0, &recvtype); + if (err) { + errs += err; + } + } + else { + MPI_Win_fence(0, win); + } + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } MTestFreeComm(&comm); } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/accfence2.c b/teshsuite/smpi/mpich3-test/rma/accfence2.c index 4366e101a9..b0bf95823c 100644 --- a/teshsuite/smpi/mpich3-test/rma/accfence2.c +++ b/teshsuite/smpi/mpich3-test/rma/accfence2.c @@ -17,72 +17,75 @@ static char MTEST_Descrip[] = "Test MPI_Accumulate with fence"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int rank, size, source; - int minsize = 2, count, i; - MPI_Comm comm; - MPI_Win win; - int *winbuf, *sbuf; + int minsize = 2, count, i; + MPI_Comm comm; + MPI_Win win; + int *winbuf, *sbuf; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - /* The following illustrates the use of the routines to - run through a selection of communicators and datatypes. - Use subsets of these for tests that do not involve combinations - of communicators, datatypes, and counts of datatypes */ - while (MTestGetIntracommGeneral( &comm, minsize, 1 )) { - if (comm == MPI_COMM_NULL) continue; - /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); - source = 0; - - for (count = 1; count < 65000; count = count * 2) { - /* We compare with an integer value that can be as large as - size * (count * count + (1/2)*(size-1)) - For large machines (size large), this can exceed the - maximum integer for some large values of count. We check - that in advance and break this loop if the above value - would exceed MAX_INT. Specifically, + /* The following illustrates the use of the routines to + * run through a selection of communicators and datatypes. + * Use subsets of these for tests that do not involve combinations + * of communicators, datatypes, and counts of datatypes */ + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; - size*count*count + (1/2)*size*(size-1) > MAX_INT - count*count > (MAX_INT/size - (1/2)*(size-1)) - */ - if (count * count > (MAX_INT/size - (size-1)/2)) break; - winbuf = (int *)malloc( count * sizeof(int) ); - sbuf = (int *)malloc( count * sizeof(int) ); + for (count = 1; count < 65000; count = count * 2) { + /* We compare with an integer value that can be as large as + * size * (count * count + (1/2)*(size-1)) + * For large machines (size large), this can exceed the + * maximum integer for some large values of count. We check + * that in advance and break this loop if the above value + * would exceed MAX_INT. Specifically, + * + * size*count*count + (1/2)*size*(size-1) > MAX_INT + * count*count > (MAX_INT/size - (1/2)*(size-1)) + */ + if (count * count > (MAX_INT / size - (size - 1) / 2)) + break; + winbuf = (int *) malloc(count * sizeof(int)); + sbuf = (int *) malloc(count * sizeof(int)); - for (i=0; i MAX_INT + * count*count > (MAX_INT/size - (1/2)*(size-1)) + */ + if (count * count > (MAX_INT / size - (size - 1) / 2)) + break; - size*count*count + (1/2)*size*(size-1) > MAX_INT - count*count > (MAX_INT/size - (1/2)*(size-1)) - */ - if (count * count > (MAX_INT/size - (size-1)/2)) break; + MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf); + MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &sbuf); - MPI_Alloc_mem( count * sizeof(int), MPI_INFO_NULL, &winbuf ); - MPI_Alloc_mem( count * sizeof(int), MPI_INFO_NULL, &sbuf ); + for (i = 0; i < count; i++) + winbuf[i] = 0; + for (i = 0; i < count; i++) + sbuf[i] = rank + i * count; + MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win); + MPI_Win_fence(0, win); + MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win); + MPI_Win_fence(0, win); + if (rank == source) { + /* Check the results */ + for (i = 0; i < count; i++) { + int result = i * count * size + (size * (size - 1)) / 2; + if (winbuf[i] != result) { + if (errs < 10) { + fprintf(stderr, + "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i, + winbuf[i], result, count, size); + } + errs++; + } + } + } - for (i=0; i MAX_BUF_SIZE) { - fprintf( stderr, "Too many processes in COMM_WORLD (max is %d)\n", - MAX_BUF_SIZE / put_size ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Too many processes in COMM_WORLD (max is %d)\n", MAX_BUF_SIZE / put_size); + MPI_Abort(MPI_COMM_WORLD, 1); } /* If alloc mem returns an error (because too much memory is requested */ - MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN ); + MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN); rc = MPI_Alloc_mem(max_buf_size, MPI_INFO_NULL, (void *) &rma_win_addr); if (rc) { - MTestPrintErrorMsg( "Unable to MPI_Alloc_mem space (not an error)", rc ); - MPI_Abort( MPI_COMM_WORLD, 0 ); + MTestPrintErrorMsg("Unable to MPI_Alloc_mem space (not an error)", rc); + MPI_Abort(MPI_COMM_WORLD, 0); } memset(rma_win_addr, 0, max_buf_size); - MPI_Win_create((void *) rma_win_addr, max_buf_size, 1, MPI_INFO_NULL, - MPI_COMM_WORLD, &win); + MPI_Win_create((void *) rma_win_addr, max_buf_size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); /* Note that it is not necessary to use MPI_Alloc_mem for the memory that - is not part of the MPI_Win. */ + * is not part of the MPI_Win. */ rc = MPI_Alloc_mem(put_size, MPI_INFO_NULL, (void *) &local_buf); if (rc) { - MTestPrintErrorMsg( "Unable to MPI_Alloc_mem space (not an error)", rc ); - MPI_Abort( MPI_COMM_WORLD, 0 ); + MTestPrintErrorMsg("Unable to MPI_Alloc_mem space (not an error)", rc); + MPI_Abort(MPI_COMM_WORLD, 0); } for (i = 0; i < put_size; i++) @@ -98,7 +96,7 @@ int main(int argc, char **argv) MPI_Barrier(MPI_COMM_WORLD); - if (comm_rank == 0) { /* target */ + if (comm_rank == 0) { /* target */ for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) { /* Wait for a message from the server to notify me that * someone put some data in my window */ @@ -108,9 +106,8 @@ int main(int argc, char **argv) * data in my local window. Check the last byte to make * sure we got it correctly. */ MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win); - MPI_Get((void *) &check, 1, MPI_CHAR, 0, - ((by_rank + 1) * put_size) - 1, 1, - MPI_CHAR, win); + MPI_Get((void *) &check, 1, MPI_CHAR, 0, + ((by_rank + 1) * put_size) - 1, 1, MPI_CHAR, win); MPI_Win_unlock(0, win); /* If this is not the value I expect, count it as an error */ @@ -125,13 +122,12 @@ int main(int argc, char **argv) } } - else if (comm_rank == 1) { /* server */ + else if (comm_rank == 1) { /* server */ for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) { /* Wait for a message from any of the origin processes * informing me that it has put data to the target * process */ - MPI_Recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, - &status); + MPI_Recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status); by_rank = status.MPI_SOURCE; /* Tell the target process that it should be seeing some @@ -140,12 +136,12 @@ int main(int argc, char **argv) } } - else { /* origin */ + else { /* origin */ for (i = 0; i < NUM_TIMES; i++) { /* Put some data in the target window */ MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win); - MPI_Put(local_buf, put_size, MPI_CHAR, 0, comm_rank * put_size, - put_size, MPI_CHAR, win); + MPI_Put(local_buf, put_size, MPI_CHAR, 0, comm_rank * put_size, + put_size, MPI_CHAR, win); MPI_Win_unlock(0, win); /* Tell the server that the put has completed */ diff --git a/teshsuite/smpi/mpich3-test/rma/aint.c b/teshsuite/smpi/mpich3-test/rma/aint.c new file mode 100644 index 0000000000..72c10d234e --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/aint.c @@ -0,0 +1,82 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* + * This program tests MPI_Aint_add/diff in MPI-3.1. + * The two functions are often used in RMA code. + * See https://svn.mpi-forum.org/trac/mpi-forum-web/ticket/349 + */ + +#include +#include +#include "mpitest.h" + +int main(int argc, char **argv) +{ + int rank, nproc; + int errs = 0; + int array[1024]; + int val = 0; + int target_rank; + MPI_Aint bases[2]; + MPI_Aint disp, offset; + MPI_Win win; + + MTest_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + if (rank == 0 && nproc != 2) { + MTestError("Must run with 2 ranks\n"); + } + + /* Get the base address in the middle of the array */ + if (rank == 0) { + target_rank = 1; + array[0] = 1234; + MPI_Get_address(&array[512], &bases[0]); + } + else if (rank == 1) { + target_rank = 0; + array[1023] = 1234; + MPI_Get_address(&array[512], &bases[1]); + } + + /* Exchange bases */ + MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, bases, 1, MPI_AINT, MPI_COMM_WORLD); + + MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &win); + MPI_Win_attach(win, array, sizeof(int) * 1024); + + /* Do MPI_Aint addressing arithmetic */ + if (rank == 0) { + disp = sizeof(int) * 511; + offset = MPI_Aint_add(bases[1], disp); /* offset points to array[1023] */ + } + else if (rank == 1) { + disp = sizeof(int) * 512; + offset = MPI_Aint_diff(bases[0], disp); /* offset points to array[0] */ + } + + /* Get val and verify it */ + MPI_Win_fence(MPI_MODE_NOPRECEDE, win); + MPI_Get(&val, 1, MPI_INT, target_rank, offset, 1, MPI_INT, win); + MPI_Win_fence(MPI_MODE_NOSUCCEED, win); + + if (val != 1234) { + errs++; + printf("%d -- Got %d, expected 1234\n", rank, val); + } + + MPI_Win_detach(win, array); + MPI_Win_free(&win); + + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/allocmem.c b/teshsuite/smpi/mpich3-test/rma/allocmem.c index 1969941fae..125562872e 100644 --- a/teshsuite/smpi/mpich3-test/rma/allocmem.c +++ b/teshsuite/smpi/mpich3-test/rma/allocmem.c @@ -12,38 +12,38 @@ static char MTEST_Descrip[] = "Simple test that alloc_mem and free_mem work together"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0, err; int j, count; char *ap; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN ); - for (count=1; count < 128000; count *= 2) { - - err = MPI_Alloc_mem( count, MPI_INFO_NULL, &ap ); - if (err) { - int errclass; - /* An error of MPI_ERR_NO_MEM is allowed */ - MPI_Error_class( err, &errclass ); - if (errclass != MPI_ERR_NO_MEM) { - errs++; - MTestPrintError( err ); - } - - } - else { - /* Access all of this memory */ - for (j=0; j +#include + +#define PUT_SIZE 1 +#define GET_SIZE 100000 +#define WIN_SIZE (PUT_SIZE+GET_SIZE) +#define LOOP 100 + +int main(int argc, char **argv) +{ + MPI_Win win; + int i, k, rank, nproc; + int win_buf[WIN_SIZE], orig_get_buf[GET_SIZE], orig_put_buf[PUT_SIZE]; + int orig_rank = 0, dest_rank = 1; + int errors = 0; + MPI_Group comm_group, orig_group, dest_group; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + MPI_Comm_group(MPI_COMM_WORLD, &comm_group); + MPI_Group_incl(comm_group, 1, &orig_rank, &orig_group); + MPI_Group_incl(comm_group, 1, &dest_rank, &dest_group); + + for (i = 0; i < PUT_SIZE; i++) + orig_put_buf[i] = 1; + for (i = 0; i < GET_SIZE; i++) + orig_get_buf[i] = 0; + for (i = 0; i < WIN_SIZE; i++) + win_buf[i] = 1; + + MPI_Win_create(win_buf, sizeof(int) * WIN_SIZE, sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &win); + + for (k = 0; k < LOOP; k++) { + + /* test for FENCE */ + + if (rank == orig_rank) { + MPI_Win_fence(MPI_MODE_NOPRECEDE, win); + MPI_Get(orig_get_buf, GET_SIZE, MPI_INT, + dest_rank, PUT_SIZE /*disp */ , GET_SIZE, MPI_INT, win); + MPI_Put(orig_put_buf, PUT_SIZE, MPI_INT, + dest_rank, 0 /*disp */ , PUT_SIZE, MPI_INT, win); + MPI_Win_fence(MPI_MODE_NOSUCCEED, win); + + /* check GET result values */ + for (i = 0; i < GET_SIZE; i++) { + if (orig_get_buf[i] != 1) { + printf("LOOP=%d, FENCE, orig_get_buf[%d] = %d, expected 1.\n", + k, i, orig_get_buf[i]); + errors++; + } + } + } + else if (rank == dest_rank) { + MPI_Win_fence(MPI_MODE_NOPRECEDE, win); + MPI_Win_fence(MPI_MODE_NOSUCCEED, win); + + /* modify the last element in window */ + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + win_buf[WIN_SIZE - 1] = 2; + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + /* reset buffers */ + for (i = 0; i < PUT_SIZE; i++) + orig_put_buf[i] = 1; + for (i = 0; i < GET_SIZE; i++) + orig_get_buf[i] = 0; + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_SIZE; i++) + win_buf[i] = 1; + MPI_Win_unlock(rank, win); + MPI_Barrier(MPI_COMM_WORLD); + + /* test for PSCW */ + + if (rank == orig_rank) { + MPI_Win_start(dest_group, 0, win); + MPI_Get(orig_get_buf, GET_SIZE, MPI_INT, + dest_rank, PUT_SIZE /*disp */ , GET_SIZE, MPI_INT, win); + MPI_Put(orig_put_buf, PUT_SIZE, MPI_INT, + dest_rank, 0 /*disp */ , PUT_SIZE, MPI_INT, win); + MPI_Win_complete(win); + + /* check GET result values */ + for (i = 0; i < GET_SIZE; i++) { + if (orig_get_buf[i] != 1) { + printf("LOOP=%d, PSCW, orig_get_buf[%d] = %d, expected 1.\n", + k, i, orig_get_buf[i]); + errors++; + } + } + } + else if (rank == dest_rank) { + MPI_Win_post(orig_group, 0, win); + MPI_Win_wait(win); + + /* modify the last element in window */ + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + win_buf[WIN_SIZE - 1] = 2; + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + /* reset buffers */ + for (i = 0; i < PUT_SIZE; i++) + orig_put_buf[i] = 1; + for (i = 0; i < GET_SIZE; i++) + orig_get_buf[i] = 0; + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_SIZE; i++) + win_buf[i] = 1; + MPI_Win_unlock(rank, win); + MPI_Barrier(MPI_COMM_WORLD); + } + + MPI_Win_free(&win); + + MPI_Group_free(&orig_group); + MPI_Group_free(&dest_group); + MPI_Group_free(&comm_group); + + if (rank == orig_rank && errors == 0) { + printf(" No Errors\n"); + } + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_get.c b/teshsuite/smpi/mpich3-test/rma/atomic_get.c new file mode 100644 index 0000000000..54bffa6b20 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/atomic_get.c @@ -0,0 +1,183 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This test is going to test atomic GET (GACC/FOP+MPI_NO_OP). + * + * There are totally three processes involved in this test. Both + * rank 1 and rank 2 issue RMA operations to rank 0. Rank 2 issues + * atomic PUT (ACC+MPI_REPLACE), whereas rank 1 issues atomic + * GET (GACC/FOP+MPI_NO_OP). The datatype used in the test is + * pair-type. The initial value of pair-type data in origin buffer + * of atomic PUT is set so that the two basic values equal with + * each other. Due to the atomicity of GET, the expected resulting + * data should also have equivalent basic values. */ + +#include "mpi.h" +#include + +#define LOOP 100 +#define DATA_SIZE 100 +#define OPS_NUM 10000 +#define GACC_SZ 10 + +typedef struct pair_struct { + long double a; + int b; +} pair_struct_t; + +int main(int argc, char *argv[]) +{ + int rank, nproc; + int i, j, k; + int errors = 0, curr_errors = 0; + MPI_Win win; + pair_struct_t *tar_buf = NULL; + pair_struct_t *orig_buf = NULL; + pair_struct_t *result_buf = NULL; + + /* This test needs to work with 3 processes. */ + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Alloc_mem(sizeof(pair_struct_t) * DATA_SIZE, MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(sizeof(pair_struct_t) * DATA_SIZE, MPI_INFO_NULL, &result_buf); + + MPI_Win_allocate(sizeof(pair_struct_t) * DATA_SIZE, sizeof(pair_struct_t), + MPI_INFO_NULL, MPI_COMM_WORLD, &tar_buf, &win); + + for (j = 0; j < LOOP * 6; j++) { + + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); + + /* initialize data */ + for (i = 0; i < DATA_SIZE; i++) { + tar_buf[i].a = 0.0; + tar_buf[i].b = 0; + result_buf[i].a = 0.0; + result_buf[i].b = 0; + } + + MPI_Win_unlock(rank, win); + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_fence(0, win); + + if (rank == 2) { + if (j < 2 * LOOP) { + /* Work with FOP test (Test #1 to Test #2) */ + for (i = 0; i < OPS_NUM; i++) { + + int curr_val = j * OPS_NUM + i; + orig_buf[0].a = (long double) (curr_val); + orig_buf[0].b = curr_val; + + MPI_Accumulate(orig_buf, 1, MPI_LONG_DOUBLE_INT, + 0, 0, 1, MPI_LONG_DOUBLE_INT, MPI_REPLACE, win); + } + } + else { + /* Work with GACC test (Test #3 to Test #6) */ + for (i = 0; i < OPS_NUM / GACC_SZ; i++) { + + for (k = 0; k < GACC_SZ; k++) { + int curr_val = j * OPS_NUM + i * GACC_SZ + k; + orig_buf[k].a = (long double) (curr_val); + orig_buf[k].b = curr_val; + } + + MPI_Accumulate(orig_buf, GACC_SZ, MPI_LONG_DOUBLE_INT, + 0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_REPLACE, win); + } + } + } + else if (rank == 1) { + /* equals to an atomic GET */ + if (j < LOOP) { + for (i = 0; i < DATA_SIZE; i++) { + /* Test #1: FOP + MPI_NO_OP */ + MPI_Fetch_and_op(orig_buf, &(result_buf[i]), MPI_LONG_DOUBLE_INT, + 0, 0, MPI_NO_OP, win); + } + } + else if (j < 2 * LOOP) { + for (i = 0; i < DATA_SIZE; i++) { + /* Test #2: FOP + MPI_NO_OP + NULL origin buffer address */ + MPI_Fetch_and_op(NULL, &(result_buf[i]), MPI_LONG_DOUBLE_INT, + 0, 0, MPI_NO_OP, win); + } + } + else if (j < 3 * LOOP) { + for (i = 0; i < DATA_SIZE / GACC_SZ; i++) { + /* Test #3: GACC + MPI_NO_OP */ + MPI_Get_accumulate(orig_buf, GACC_SZ, MPI_LONG_DOUBLE_INT, + &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT, + 0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win); + } + } + else if (j < 4 * LOOP) { + for (i = 0; i < DATA_SIZE / GACC_SZ; i++) { + /* Test #4: GACC + MPI_NO_OP + NULL origin buffer address */ + MPI_Get_accumulate(NULL, GACC_SZ, MPI_LONG_DOUBLE_INT, + &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT, + 0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win); + } + } + else if (j < 5 * LOOP) { + for (i = 0; i < DATA_SIZE / GACC_SZ; i++) { + /* Test #5: GACC + MPI_NO_OP + zero origin count */ + MPI_Get_accumulate(orig_buf, 0, MPI_LONG_DOUBLE_INT, + &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT, + 0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win); + } + } + else if (j < 6 * LOOP) { + for (i = 0; i < DATA_SIZE / GACC_SZ; i++) { + /* Test #5: GACC + MPI_NO_OP + NULL origin datatype */ + MPI_Get_accumulate(orig_buf, GACC_SZ, MPI_DATATYPE_NULL, + &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT, + 0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win); + } + } + } + + MPI_Win_fence(0, win); + + /* check results */ + if (rank == 1) { + for (i = 0; i < DATA_SIZE; i++) { + if (result_buf[i].a != (long double) (result_buf[i].b)) { + if (curr_errors < 10) { + printf("LOOP %d: result_buf[%d].a = %Lf, result_buf[%d].b = %d\n", + j, i, result_buf[i].a, i, result_buf[i].b); + } + curr_errors++; + } + } + } + + if (j % LOOP == 0) { + errors += curr_errors; + curr_errors = 0; + } + } + + MPI_Win_free(&win); + + MPI_Free_mem(orig_buf); + MPI_Free_mem(result_buf); + + if (rank == 1) { + if (errors == 0) + printf(" No Errors\n"); + } + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_rmw_cas.c b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_cas.c new file mode 100644 index 0000000000..dfd722849a --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_cas.c @@ -0,0 +1,137 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This test is going to test the atomicity for "read-modify-write" in CAS + * operations */ + +/* There are three processes involved in this test: P0 (origin_shm), P1 (origin_am), + * and P2 (dest). P0 and P1 issues one CAS to P2 via SHM and AM respectively. + * For P0, origin value is 1 and compare value is 0; for P1, origin value is 0 and + * compare value is 1; for P2, initial target value is 0. The correct results can + * only be one of the following cases: + * + * (1) result value on P0: 0, result value on P1: 0, target value on P2: 1. + * (2) result value on P0: 0, result value on P1: 1, target value on P2: 0. + * + * All other results are not correct. */ + +#include "mpi.h" +#include + +#define LOOP_SIZE 10000 +#define CHECK_TAG 123 + +int main(int argc, char *argv[]) +{ + int rank, size, k; + int errors = 0; + int origin_shm, origin_am, dest; + int *orig_buf = NULL, *result_buf = NULL, *compare_buf = NULL, + *target_buf = NULL, *check_buf = NULL; + int target_value = 0; + MPI_Win win; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size != 3) { + /* run this test with three processes */ + goto exit_test; + } + + /* this works when MPIR_PARAM_CH3_ODD_EVEN_CLIQUES is set */ + dest = 2; + origin_shm = 0; + origin_am = 1; + + if (rank != dest) { + MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &result_buf); + MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &compare_buf); + } + + MPI_Win_allocate(sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &target_buf, &win); + + for (k = 0; k < LOOP_SIZE; k++) { + + /* init buffers */ + if (rank == origin_shm) { + orig_buf[0] = 1; + compare_buf[0] = 0; + result_buf[0] = 0; + } + else if (rank == origin_am) { + orig_buf[0] = 0; + compare_buf[0] = 1; + result_buf[0] = 0; + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + target_buf[0] = 0; + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* perform FOP */ + MPI_Win_lock_all(0, win); + if (rank != dest) { + MPI_Compare_and_swap(orig_buf, compare_buf, result_buf, MPI_INT, dest, 0, win); + MPI_Win_flush(dest, win); + } + MPI_Win_unlock_all(win); + + MPI_Barrier(MPI_COMM_WORLD); + + /* check results */ + if (rank != dest) { + MPI_Gather(result_buf, 1, MPI_INT, check_buf, 1, MPI_INT, dest, MPI_COMM_WORLD); + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + target_value = target_buf[0]; + MPI_Win_unlock(rank, win); + + MPI_Alloc_mem(sizeof(int) * 3, MPI_INFO_NULL, &check_buf); + MPI_Gather(&target_value, 1, MPI_INT, check_buf, 1, MPI_INT, dest, MPI_COMM_WORLD); + + if (!(check_buf[dest] == 0 && check_buf[origin_shm] == 0 && check_buf[origin_am] == 1) + && !(check_buf[dest] == 1 && check_buf[origin_shm] == 0 && + check_buf[origin_am] == 0)) { + + printf + ("Wrong results: target result = %d, origin_shm result = %d, origin_am result = %d\n", + check_buf[dest], check_buf[origin_shm], check_buf[origin_am]); + + printf + ("Expected results (1): target result = 1, origin_shm result = 0, origin_am result = 0\n"); + printf + ("Expected results (2): target result = 0, origin_shm result = 0, origin_am result = 1\n"); + + errors++; + } + + MPI_Free_mem(check_buf); + } + } + + MPI_Win_free(&win); + + if (rank == origin_am || rank == origin_shm) { + MPI_Free_mem(orig_buf); + MPI_Free_mem(result_buf); + MPI_Free_mem(compare_buf); + } + + exit_test: + if (rank == dest && errors == 0) + printf(" No Errors\n"); + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_rmw_fop.c b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_fop.c new file mode 100644 index 0000000000..42875f6178 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_fop.c @@ -0,0 +1,143 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This test is going to test the atomicity for "read-modify-write" in FOP + * operations */ + +/* There are three processes involved in this test: P0 (origin_shm), P1 (origin_am), + * and P2 (dest). P0 and P1 issues multiple FOP with MPI_SUM and integer (value 1) + * to P2 via SHM and AM respectively. The correct results should be that the + * results on P0 and P1 never be the same. */ + +#include "mpi.h" +#include + +#define AM_BUF_SIZE 10 +#define SHM_BUF_SIZE 1000 +#define WIN_BUF_SIZE 1 + +#define LOOP_SIZE 15 +#define CHECK_TAG 123 + +int main(int argc, char *argv[]) +{ + int rank, size, i, j, k; + int errors = 0, all_errors = 0; + int origin_shm, origin_am, dest; + int my_buf_size; + int *orig_buf = NULL, *result_buf = NULL, *target_buf = NULL, *check_buf = NULL; + MPI_Win win; + MPI_Status status; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size != 3) { + /* run this test with three processes */ + goto exit_test; + } + + /* this works when MPIR_PARAM_CH3_ODD_EVEN_CLIQUES is set */ + dest = 2; + origin_shm = 0; + origin_am = 1; + + if (rank == origin_am) + my_buf_size = AM_BUF_SIZE; + else if (rank == origin_shm) + my_buf_size = SHM_BUF_SIZE; + + if (rank != dest) { + MPI_Alloc_mem(sizeof(int) * my_buf_size, MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(sizeof(int) * my_buf_size, MPI_INFO_NULL, &result_buf); + } + + MPI_Win_allocate(sizeof(int) * WIN_BUF_SIZE, sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &target_buf, &win); + + for (k = 0; k < LOOP_SIZE; k++) { + + /* init buffers */ + if (rank != dest) { + for (i = 0; i < my_buf_size; i++) { + orig_buf[i] = 1; + result_buf[i] = 0; + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_BUF_SIZE; i++) { + target_buf[i] = 0; + } + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* perform FOP */ + MPI_Win_lock_all(0, win); + if (rank != dest) { + for (i = 0; i < my_buf_size; i++) { + MPI_Fetch_and_op(&(orig_buf[i]), &(result_buf[i]), MPI_INT, dest, 0, MPI_SUM, win); + MPI_Win_flush(dest, win); + } + } + MPI_Win_unlock_all(win); + + MPI_Barrier(MPI_COMM_WORLD); + + if (rank != dest) { + /* check results on P0 and P2 (origin) */ + if (rank == origin_am) { + MPI_Send(result_buf, AM_BUF_SIZE, MPI_INT, origin_shm, CHECK_TAG, MPI_COMM_WORLD); + } + else if (rank == origin_shm) { + MPI_Alloc_mem(sizeof(int) * AM_BUF_SIZE, MPI_INFO_NULL, &check_buf); + MPI_Recv(check_buf, AM_BUF_SIZE, MPI_INT, origin_am, CHECK_TAG, MPI_COMM_WORLD, + &status); + for (i = 0; i < AM_BUF_SIZE; i++) { + for (j = 0; j < SHM_BUF_SIZE; j++) { + if (check_buf[i] == result_buf[j]) { + printf + ("LOOP=%d, rank=%d, FOP, both check_buf[%d] and result_buf[%d] equal to %d, expected to be different. \n", + k, rank, i, j, check_buf[i]); + errors++; + } + } + } + MPI_Free_mem(check_buf); + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + /* check results on P1 */ + if (target_buf[0] != AM_BUF_SIZE + SHM_BUF_SIZE) { + printf("LOOP=%d, rank=%d, FOP, target_buf[0] = %d, expected %d. \n", + k, rank, target_buf[0], AM_BUF_SIZE + SHM_BUF_SIZE); + errors++; + } + MPI_Win_unlock(rank, win); + } + } + + MPI_Win_free(&win); + + if (rank == origin_am || rank == origin_shm) { + MPI_Free_mem(orig_buf); + MPI_Free_mem(result_buf); + } + + exit_test: + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_rmw_gacc.c b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_gacc.c new file mode 100644 index 0000000000..0e73e2d4a7 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_gacc.c @@ -0,0 +1,276 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This test is going to test the atomicity for "read-modify-write" in GACC + * operations */ + +/* This test is similiar with atomic_rmw_fop.c. + * There are three processes involved in this test: P0 (origin_shm), P1 (origin_am), + * and P2 (dest). P0 and P1 issues multiple GACC with MPI_SUM and OP_COUNT integers + * (value 1) to P2 via SHM and AM respectively. The correct results should be that the + * results on P0 and P1 never be the same for intergers on the corresponding index + * in [0...OP_COUNT-1]. + */ + +#include "mpi.h" +#include + +#define OP_COUNT 10 +#define AM_BUF_NUM 10 +#define SHM_BUF_NUM 10000 +#define WIN_BUF_NUM 1 + +#define LOOP_SIZE 15 +#define CHECK_TAG 123 + +int rank, size; +int dest, origin_shm, origin_am; +int *orig_buf = NULL, *result_buf = NULL, *target_buf = NULL, *check_buf = NULL; +MPI_Win win; + +void checkResults(int loop_k, int *errors) +{ + int i, j, m; + MPI_Status status; + + if (rank != dest) { + /* check results on P0 and P2 (origin) */ + if (rank == origin_am) { + MPI_Send(result_buf, AM_BUF_NUM * OP_COUNT, MPI_INT, origin_shm, CHECK_TAG, + MPI_COMM_WORLD); + } + else if (rank == origin_shm) { + MPI_Alloc_mem(sizeof(int) * AM_BUF_NUM * OP_COUNT, MPI_INFO_NULL, &check_buf); + MPI_Recv(check_buf, AM_BUF_NUM * OP_COUNT, MPI_INT, origin_am, CHECK_TAG, + MPI_COMM_WORLD, &status); + for (i = 0; i < AM_BUF_NUM; i++) { + for (j = 0; j < SHM_BUF_NUM; j++) { + for (m = 0; m < OP_COUNT; m++) { + if (check_buf[i * OP_COUNT + m] == result_buf[j * OP_COUNT + m]) { + printf + ("LOOP=%d, rank=%d, FOP, both check_buf[%d] and result_buf[%d] equal to %d, expected to be different. \n", + loop_k, rank, i * OP_COUNT + m, j * OP_COUNT + m, + check_buf[i * OP_COUNT + m]); + (*errors)++; + } + } + } + } + MPI_Free_mem(check_buf); + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + /* check results on P1 */ + for (i = 0; i < OP_COUNT; i++) { + if (target_buf[i] != AM_BUF_NUM + SHM_BUF_NUM) { + printf("LOOP=%d, rank=%d, FOP, target_buf[%d] = %d, expected %d. \n", + loop_k, rank, i, target_buf[i], AM_BUF_NUM + SHM_BUF_NUM); + (*errors)++; + } + } + MPI_Win_unlock(rank, win); + } +} + +int main(int argc, char *argv[]) +{ + int i, k; + int errors = 0, all_errors = 0; + int my_buf_num; + MPI_Datatype origin_dtp, target_dtp; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size != 3) { + /* run this test with three processes */ + goto exit_test; + } + + MPI_Type_contiguous(OP_COUNT, MPI_INT, &origin_dtp); + MPI_Type_commit(&origin_dtp); + MPI_Type_contiguous(OP_COUNT, MPI_INT, &target_dtp); + MPI_Type_commit(&target_dtp); + + /* this works when MPIR_PARAM_CH3_ODD_EVEN_CLIQUES is set */ + dest = 2; + origin_shm = 0; + origin_am = 1; + + if (rank == origin_am) + my_buf_num = AM_BUF_NUM; + else if (rank == origin_shm) + my_buf_num = SHM_BUF_NUM; + + if (rank != dest) { + MPI_Alloc_mem(sizeof(int) * my_buf_num * OP_COUNT, MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(sizeof(int) * my_buf_num * OP_COUNT, MPI_INFO_NULL, &result_buf); + } + + MPI_Win_allocate(sizeof(int) * WIN_BUF_NUM * OP_COUNT, sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &target_buf, &win); + + for (k = 0; k < LOOP_SIZE; k++) { + + /* ====== Part 1: test basic datatypes ======== */ + + /* init buffers */ + if (rank != dest) { + for (i = 0; i < my_buf_num * OP_COUNT; i++) { + orig_buf[i] = 1; + result_buf[i] = 0; + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) { + target_buf[i] = 0; + } + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_lock_all(0, win); + if (rank != dest) { + for (i = 0; i < my_buf_num; i++) { + MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), OP_COUNT, MPI_INT, + &(result_buf[i * OP_COUNT]), OP_COUNT, MPI_INT, + dest, 0, OP_COUNT, MPI_INT, MPI_SUM, win); + MPI_Win_flush(dest, win); + } + } + MPI_Win_unlock_all(win); + + MPI_Barrier(MPI_COMM_WORLD); + + checkResults(k, &errors); + + /* ====== Part 2: test derived datatypes (origin derived, target derived) ======== */ + + /* init buffers */ + if (rank != dest) { + for (i = 0; i < my_buf_num * OP_COUNT; i++) { + orig_buf[i] = 1; + result_buf[i] = 0; + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) { + target_buf[i] = 0; + } + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_lock_all(0, win); + if (rank != dest) { + for (i = 0; i < my_buf_num; i++) { + MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), 1, origin_dtp, + &(result_buf[i * OP_COUNT]), 1, origin_dtp, + dest, 0, 1, target_dtp, MPI_SUM, win); + MPI_Win_flush(dest, win); + } + } + MPI_Win_unlock_all(win); + + MPI_Barrier(MPI_COMM_WORLD); + + checkResults(k, &errors); + + /* ====== Part 3: test derived datatypes (origin basic, target derived) ======== */ + + /* init buffers */ + if (rank != dest) { + for (i = 0; i < my_buf_num * OP_COUNT; i++) { + orig_buf[i] = 1; + result_buf[i] = 0; + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) { + target_buf[i] = 0; + } + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_lock_all(0, win); + if (rank != dest) { + for (i = 0; i < my_buf_num; i++) { + MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), OP_COUNT, MPI_INT, + &(result_buf[i * OP_COUNT]), OP_COUNT, MPI_INT, + dest, 0, 1, target_dtp, MPI_SUM, win); + MPI_Win_flush(dest, win); + } + } + MPI_Win_unlock_all(win); + + MPI_Barrier(MPI_COMM_WORLD); + + checkResults(k, &errors); + + /* ====== Part 4: test derived datatypes (origin derived target basic) ======== */ + + /* init buffers */ + if (rank != dest) { + for (i = 0; i < my_buf_num * OP_COUNT; i++) { + orig_buf[i] = 1; + result_buf[i] = 0; + } + } + else { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) { + target_buf[i] = 0; + } + MPI_Win_unlock(rank, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_lock_all(0, win); + if (rank != dest) { + for (i = 0; i < my_buf_num; i++) { + MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), 1, origin_dtp, + &(result_buf[i * OP_COUNT]), 1, origin_dtp, + dest, 0, OP_COUNT, MPI_INT, MPI_SUM, win); + MPI_Win_flush(dest, win); + } + } + MPI_Win_unlock_all(win); + + MPI_Barrier(MPI_COMM_WORLD); + + checkResults(k, &errors); + } + + MPI_Win_free(&win); + + if (rank == origin_am || rank == origin_shm) { + MPI_Free_mem(orig_buf); + MPI_Free_mem(result_buf); + } + + MPI_Type_free(&origin_dtp); + MPI_Type_free(&target_dtp); + + exit_test: + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/attrorderwin.c b/teshsuite/smpi/mpich3-test/rma/attrorderwin.c index 972dda719b..9d6ef8721d 100644 --- a/teshsuite/smpi/mpich3-test/rma/attrorderwin.c +++ b/teshsuite/smpi/mpich3-test/rma/attrorderwin.c @@ -13,117 +13,113 @@ static char MTestDescrip[] = "Test creating and inserting attributes in \ different orders to ensure that the list management code handles all cases."; */ -int checkAttrs( MPI_Win win, int n, int key[], int attrval[] ); -int checkNoAttrs( MPI_Win win, int n, int key[] ); +int checkAttrs(MPI_Win win, int n, int key[], int attrval[]); +int checkNoAttrs(MPI_Win win, 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; int buf[1]; MPI_Comm comm; - MPI_Win win; + MPI_Win win; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); { - comm = MPI_COMM_WORLD; - MPI_Win_create( buf, sizeof(int), sizeof(int), MPI_INFO_NULL, - comm, &win ); - - /* Create key values */ - for (i=0; i<3; i++) { - MPI_Win_create_keyval( 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_Win_set_attr( win, key[2], &attrval[2] ); - MPI_Win_set_attr( win, key[1], &attrval[1] ); - MPI_Win_set_attr( win, key[0], &attrval[0] ); - - errs += checkAttrs( win, 3, key, attrval ); - - MPI_Win_delete_attr( win, key[0] ); - MPI_Win_delete_attr( win, key[1] ); - MPI_Win_delete_attr( win, key[2] ); - - errs += checkNoAttrs( win, 3, key ); - - MPI_Win_set_attr( win, key[1], &attrval[1] ); - MPI_Win_set_attr( win, key[2], &attrval[2] ); - MPI_Win_set_attr( win, key[0], &attrval[0] ); - - errs += checkAttrs( win, 3, key, attrval ); - - MPI_Win_delete_attr( win, key[2] ); - MPI_Win_delete_attr( win, key[1] ); - MPI_Win_delete_attr( win, key[0] ); - - errs += checkNoAttrs( win, 3, key ); - - MPI_Win_set_attr( win, key[0], &attrval[0] ); - MPI_Win_set_attr( win, key[1], &attrval[1] ); - MPI_Win_set_attr( win, key[2], &attrval[2] ); - - errs += checkAttrs( win, 3, key, attrval ); - - MPI_Win_delete_attr( win, key[1] ); - MPI_Win_delete_attr( win, key[2] ); - MPI_Win_delete_attr( win, key[0] ); - - errs += checkNoAttrs( win, 3, key ); - - for (i=0; i<3; i++) { - MPI_Win_free_keyval( &key[i] ); - } - MPI_Win_free( &win ); + comm = MPI_COMM_WORLD; + MPI_Win_create(buf, sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win); + + /* Create key values */ + for (i = 0; i < 3; i++) { + MPI_Win_create_keyval(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_Win_set_attr(win, key[2], &attrval[2]); + MPI_Win_set_attr(win, key[1], &attrval[1]); + MPI_Win_set_attr(win, key[0], &attrval[0]); + + errs += checkAttrs(win, 3, key, attrval); + + MPI_Win_delete_attr(win, key[0]); + MPI_Win_delete_attr(win, key[1]); + MPI_Win_delete_attr(win, key[2]); + + errs += checkNoAttrs(win, 3, key); + + MPI_Win_set_attr(win, key[1], &attrval[1]); + MPI_Win_set_attr(win, key[2], &attrval[2]); + MPI_Win_set_attr(win, key[0], &attrval[0]); + + errs += checkAttrs(win, 3, key, attrval); + + MPI_Win_delete_attr(win, key[2]); + MPI_Win_delete_attr(win, key[1]); + MPI_Win_delete_attr(win, key[0]); + + errs += checkNoAttrs(win, 3, key); + + MPI_Win_set_attr(win, key[0], &attrval[0]); + MPI_Win_set_attr(win, key[1], &attrval[1]); + MPI_Win_set_attr(win, key[2], &attrval[2]); + + errs += checkAttrs(win, 3, key, attrval); + + MPI_Win_delete_attr(win, key[1]); + MPI_Win_delete_attr(win, key[2]); + MPI_Win_delete_attr(win, key[0]); + + errs += checkNoAttrs(win, 3, key); + + for (i = 0; i < 3; i++) { + MPI_Win_free_keyval(&key[i]); + } + MPI_Win_free(&win); } - - MTest_Finalize( errs ); + + MTest_Finalize(errs); MPI_Finalize(); return 0; - + } -int checkAttrs( MPI_Win win, int n, int key[], int attrval[] ) +int checkAttrs(MPI_Win win, int n, int key[], int attrval[]) { int errs = 0; int i, flag, *val_p; - for (i=0; i%d -- Error: next=%d compare=%d result=%d val=%d\n", rank, - rank, next, i, result, *val_ptr); ); + SQUELCH(printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank, + rank, next, i, result, *val_ptr);); errors++; } } @@ -55,12 +56,12 @@ int main(int argc, char **argv) { for (i = 0; i < ITER; i++) { int next = i + 1, result = -1; - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank+1)%nproc, 0, win); - MPI_Compare_and_swap(&next, &i, &result, MPI_INT, (rank+1)%nproc, 0, win); - MPI_Win_unlock((rank+1)%nproc, win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank + 1) % nproc, 0, win); + MPI_Compare_and_swap(&next, &i, &result, MPI_INT, (rank + 1) % nproc, 0, win); + MPI_Win_unlock((rank + 1) % nproc, win); if (result != i) { - SQUELCH( printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank, - (rank+1)%nproc, next, i, result, *val_ptr); ); + SQUELCH(printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank, + (rank + 1) % nproc, next, i, result, *val_ptr);); errors++; } } @@ -89,7 +90,7 @@ int main(int argc, char **argv) { if (rank == 0 && nproc > 1) { if (*val_ptr != ITER) { - SQUELCH( printf("%d - Error: expected=%d val=%d\n", rank, ITER, *val_ptr); ); + SQUELCH(printf("%d - Error: expected=%d val=%d\n", rank, ITER, *val_ptr);); errors++; } } diff --git a/teshsuite/smpi/mpich3-test/rma/contention_put.c b/teshsuite/smpi/mpich3-test/rma/contention_put.c index 2b2be301ca..b549c9b315 100644 --- a/teshsuite/smpi/mpich3-test/rma/contention_put.c +++ b/teshsuite/smpi/mpich3-test/rma/contention_put.c @@ -26,80 +26,82 @@ int test_put(void); int test_put(void) { - MPI_Win dst_win; - double *dst_buf; - double src_buf[MAXELEMS]; - int i, j; - int errs = 0; + MPI_Win dst_win; + double *dst_buf; + double src_buf[MAXELEMS]; + int i, j; + int errs = 0; - MPI_Alloc_mem(sizeof(double)*nproc*MAXELEMS, MPI_INFO_NULL, &dst_buf); - MPI_Win_create(dst_buf, sizeof(double)*nproc*MAXELEMS, 1, MPI_INFO_NULL, - MPI_COMM_WORLD, &dst_win); + MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf); + MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL, + MPI_COMM_WORLD, &dst_win); - for (i = 0; i < MAXELEMS; i++) - src_buf[i] = me + 1.0; + for (i = 0; i < MAXELEMS; i++) + src_buf[i] = me + 1.0; - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win); - for (i = 0; i < nproc*MAXELEMS; i++) - dst_buf[i] = 0.0; + for (i = 0; i < nproc * MAXELEMS; i++) + dst_buf[i] = 0.0; - MPI_Win_unlock(me, dst_win); + MPI_Win_unlock(me, dst_win); - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - for(i = 0; i < nproc; i++) { - /* int target = (me + i) % nproc; */ - int target = i; - for(j = 0; j < COUNT; j++) { - if (verbose) printf("%2d -> %2d [%2d]\n", me, target, j); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win); - MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, - (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win); - MPI_Win_unlock(target, dst_win); + for (i = 0; i < nproc; i++) { + /* int target = (me + i) % nproc; */ + int target = i; + for (j = 0; j < COUNT; j++) { + if (verbose) + printf("%2d -> %2d [%2d]\n", me, target, j); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win); + MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, + (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win); + MPI_Win_unlock(target, dst_win); + } } - } - - MPI_Barrier(MPI_COMM_WORLD); - - /* Check that the correct data was returned. This assumes that the - systems have the same data representations */ - for (i=0; i %2d [%2d]\n", me, target, j); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win); - MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win); - MPI_Win_unlock(target, dst_win); - } - - for(j = 0; j < COUNT; j++) { - if (verbose) printf("%2d <- %2d [%2d]\n", me, target, j); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win); - MPI_Get(&src_buf[j], sizeof(double), MPI_BYTE, target, (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win); - MPI_Win_unlock(target, dst_win); + MPI_Win dst_win; + double *dst_buf; + double src_buf[MAXELEMS]; + int i, j; + + MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf); + MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL, MPI_COMM_WORLD, + &dst_win); + + for (i = 0; i < MAXELEMS; i++) + src_buf[i] = me + 1.0; + + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win); + + for (i = 0; i < nproc * MAXELEMS; i++) + dst_buf[i] = 0.0; + + MPI_Win_unlock(me, dst_win); + + MPI_Barrier(MPI_COMM_WORLD); + + for (i = 0; i < nproc; i++) { + int target = i; + + for (j = 0; j < COUNT; j++) { + if (verbose) + printf("%2d -> %2d [%2d]\n", me, target, j); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win); + MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, + (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win); + MPI_Win_unlock(target, dst_win); + } + + for (j = 0; j < COUNT; j++) { + if (verbose) + printf("%2d <- %2d [%2d]\n", me, target, j); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win); + MPI_Get(&src_buf[j], sizeof(double), MPI_BYTE, target, + (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win); + MPI_Win_unlock(target, dst_win); + } } - } - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Win_free(&dst_win); - MPI_Free_mem(dst_buf); + MPI_Win_free(&dst_win); + MPI_Free_mem(dst_buf); } -int main(int argc, char* argv[]) { - MPI_Init(&argc, &argv); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - MPI_Comm_rank(MPI_COMM_WORLD, &me); +int main(int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &me); - assert(COUNT <= MAXELEMS); + assert(COUNT <= MAXELEMS); - if (me == 0 && verbose) { - printf("Test starting on %d processes\n", nproc); - fflush(stdout); - } + if (me == 0 && verbose) { + printf("Test starting on %d processes\n", nproc); + fflush(stdout); + } - test_put(); + test_put(); - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Finalize(); + MPI_Finalize(); - if (me == 0 && verbose) { - printf("Test completed.\n"); - fflush(stdout); - } + if (me == 0 && verbose) { + printf("Test completed.\n"); + fflush(stdout); + } - if (me == 0) - printf(" No Errors\n"); + if (me == 0) + printf(" No Errors\n"); - return 0; + return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/contig_displ.c b/teshsuite/smpi/mpich3-test/rma/contig_displ.c index 9d37da6cc3..459c8b622b 100644 --- a/teshsuite/smpi/mpich3-test/rma/contig_displ.c +++ b/teshsuite/smpi/mpich3-test/rma/contig_displ.c @@ -11,72 +11,80 @@ /* Run with 1 process. This program does an MPI_Get with an indexed datatype. The datatype - comprises a single integer at an initial displacement of 1 integer. + comprises a single integer at an initial displacement of 1 integer. That is, the first integer in the array is to be skipped. This program found a bug in IBM's MPI in which MPI_Get ignored the - displacement and got the first integer instead of the second. + displacement and got the first integer instead of the second. */ int main(int argc, char **argv) { int rank, nprocs, mpi_err, *array; - int getval, disp, errs=0; + int getval, disp, errs = 0; MPI_Win win; MPI_Datatype type; - - MTest_Init(&argc,&argv); + + MTest_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); if (rank == 0) { /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Comm_set_errhandler( MPI_COMM_SELF, MPI_ERRORS_RETURN ); - - /* create an indexed datatype that points to the second integer - in an array (the first integer is skipped). */ - disp = 1; + * change the error handler to errors return */ + MPI_Comm_set_errhandler(MPI_COMM_SELF, MPI_ERRORS_RETURN); + + /* create an indexed datatype that points to the second integer + * in an array (the first integer is skipped). */ + disp = 1; mpi_err = MPI_Type_create_indexed_block(1, 1, &disp, MPI_INT, &type); - if (mpi_err != MPI_SUCCESS) goto err_return; + if (mpi_err != MPI_SUCCESS) + goto err_return; mpi_err = MPI_Type_commit(&type); - if (mpi_err != MPI_SUCCESS) goto err_return; - - /* allocate window of size 2 integers*/ - mpi_err = MPI_Alloc_mem(2*sizeof(int), MPI_INFO_NULL, &array); - if (mpi_err != MPI_SUCCESS) goto err_return; - + if (mpi_err != MPI_SUCCESS) + goto err_return; + + /* allocate window of size 2 integers */ + mpi_err = MPI_Alloc_mem(2 * sizeof(int), MPI_INFO_NULL, &array); + if (mpi_err != MPI_SUCCESS) + goto err_return; + /* create window object */ - mpi_err = MPI_Win_create(array, 2*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win); - if (mpi_err != MPI_SUCCESS) goto err_return; - + mpi_err = + MPI_Win_create(array, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win); + if (mpi_err != MPI_SUCCESS) + goto err_return; + /* initialize array */ array[0] = 100; array[1] = 200; - + getval = 0; - + /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); - + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); + mpi_err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win); - if (mpi_err != MPI_SUCCESS) goto err_return; - + if (mpi_err != MPI_SUCCESS) + goto err_return; + /* get the current value of element array[1] */ mpi_err = MPI_Get(&getval, 1, MPI_INT, 0, 0, 1, type, win); - if (mpi_err != MPI_SUCCESS) goto err_return; - + if (mpi_err != MPI_SUCCESS) + goto err_return; + mpi_err = MPI_Win_unlock(0, win); - if (mpi_err != MPI_SUCCESS) goto err_return; - + if (mpi_err != MPI_SUCCESS) + goto err_return; + /* getval should contain the value of array[1] */ if (getval != array[1]) { errs++; printf("getval=%d, should be %d\n", getval, array[1]); } - + MPI_Free_mem(array); MPI_Win_free(&win); MPI_Type_free(&type); @@ -86,13 +94,11 @@ int main(int argc, char **argv) MPI_Finalize(); return 0; - err_return: + err_return: printf("MPI function error returned an error\n"); - MTestPrintError( mpi_err ); + MTestPrintError(mpi_err); errs++; MTest_Finalize(errs); MPI_Finalize(); return 1; } - - diff --git a/teshsuite/smpi/mpich3-test/rma/derived-acc-flush_local.c b/teshsuite/smpi/mpich3-test/rma/derived-acc-flush_local.c new file mode 100644 index 0000000000..032a0225c4 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/derived-acc-flush_local.c @@ -0,0 +1,130 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This code tests the case when one process issues large number + * of MPI_Accumulate operations (with large derived datatype) and + * issues a MPI_Win_flush_local at end. */ + +/* FIXME: we should merge this into a comprehensive test for RMA + * operations + MPI_Win_flush_local. */ + +#include "mpi.h" +#include +#include +#include + +#define DATA_SIZE 1000000 +#define COUNT 5000 +#define BLOCKLENGTH (DATA_SIZE/COUNT) +#define STRIDE BLOCKLENGTH +#define OPS_NUM 500 + +int main(int argc, char *argv[]) +{ + int rank, nproc; + int i; + MPI_Win win; + int *tar_buf = NULL; + int *orig_buf = NULL; + MPI_Datatype derived_dtp; + int errors = 0; + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + if (nproc < 3) { + fprintf(stderr, "Run this program with at least 3 processes\n"); + MPI_Abort(MPI_COMM_WORLD, 1); + } + + MPI_Alloc_mem(sizeof(int) * DATA_SIZE, MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(sizeof(int) * DATA_SIZE, MPI_INFO_NULL, &tar_buf); + + for (i = 0; i < DATA_SIZE; i++) { + orig_buf[i] = 1; + tar_buf[i] = 0; + } + + MPI_Type_vector(COUNT, BLOCKLENGTH - 1, STRIDE, MPI_INT, &derived_dtp); + MPI_Type_commit(&derived_dtp); + + MPI_Win_create(tar_buf, sizeof(int) * DATA_SIZE, sizeof(int), + MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + /***** test between rank 0 and rank 1 *****/ + + if (rank == 1) { + MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win); + + for (i = 0; i < OPS_NUM; i++) { + MPI_Accumulate(orig_buf, 1, derived_dtp, + 0, 0, DATA_SIZE - COUNT, MPI_INT, MPI_SUM, win); + MPI_Win_flush_local(0, win); + } + + MPI_Win_unlock(0, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* check results */ + if (rank == 0) { + for (i = 0; i < DATA_SIZE - COUNT; i++) { + if (tar_buf[i] != OPS_NUM) { + printf("tar_buf[%d] = %d, expected %d\n", i, tar_buf[i], OPS_NUM); + errors++; + } + } + } + + for (i = 0; i < DATA_SIZE; i++) { + tar_buf[i] = 0; + } + + MPI_Barrier(MPI_COMM_WORLD); + + /***** test between rank 0 and rank 2 *****/ + + if (rank == 2) { + MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win); + + for (i = 0; i < OPS_NUM; i++) { + MPI_Accumulate(orig_buf, 1, derived_dtp, + 0, 0, DATA_SIZE - COUNT, MPI_INT, MPI_SUM, win); + MPI_Win_flush_local(0, win); + } + + MPI_Win_unlock(0, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* check results */ + if (rank == 0) { + for (i = 0; i < DATA_SIZE - COUNT; i++) { + if (tar_buf[i] != OPS_NUM) { + printf("tar_buf[%d] = %d, expected %d\n", i, tar_buf[i], OPS_NUM); + errors++; + } + } + + if (errors == 0) + printf(" No Errors\n"); + } + + MPI_Win_free(&win); + + MPI_Type_free(&derived_dtp); + + MPI_Free_mem(orig_buf); + MPI_Free_mem(tar_buf); + + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/epochtest.c b/teshsuite/smpi/mpich3-test/rma/epochtest.c index 7a3222a3fc..bd07732b84 100644 --- a/teshsuite/smpi/mpich3-test/rma/epochtest.c +++ b/teshsuite/smpi/mpich3-test/rma/epochtest.c @@ -6,7 +6,7 @@ */ /* - * This test looks at the behavior of MPI_Win_fence and epochs. Each + * This test looks at the behavior of MPI_Win_fence and epochs. Each * MPI_Win_fence may both begin and end both the exposure and access epochs. * Thus, it is not necessary to use MPI_Win_fence in pairs. * @@ -32,160 +32,192 @@ static char MTEST_Descrip[] = "Put with Fences used to separate epochs"; #define MAX_PERR 10 -int PrintRecvedError( const char *, MTestDatatype *, MTestDatatype * ); +int PrintRecvedError(const char *, MTestDatatype *, MTestDatatype *); -int main( int argc, char **argv ) +int main(int argc, char **argv) { int errs = 0, err; int rank, size, source, dest; - int minsize = 2, count; - MPI_Comm comm; - MPI_Win win; - MPI_Aint extent; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint extent,lb; MTestDatatype sendtype, recvtype; - int onlyInt = 0; + int onlyInt = 0; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); /* Check for a simple choice of communicator and datatypes */ - if (getenv( "MTEST_SIMPLE" )) onlyInt = 1; - - while (MTestGetIntracommGeneral( &comm, minsize, 1 )) { - if (comm == MPI_COMM_NULL) continue; - /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); - source = 0; - dest = size - 1; - - for (count = 1; count < 65000; count = count * 2) { - while (MTestGetDatatypes( &sendtype, &recvtype, count )) { - - MTestPrintfMsg( 1, - "Putting count = %d of sendtype %s receive type %s\n", - count, MTestGetDatatypeName( &sendtype ), - MTestGetDatatypeName( &recvtype ) ); - - /* Make sure that everyone has a recv buffer */ - recvtype.InitBuf( &recvtype ); - - MPI_Type_extent( recvtype.datatype, &extent ); - MPI_Win_create( recvtype.buf, recvtype.count * extent, - extent, MPI_INFO_NULL, comm, &win ); - /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); - - /* At this point, we have all of the elements that we - need to begin the multiple fence and put tests */ - /* Fence 1 */ - err = MPI_Win_fence( MPI_MODE_NOPRECEDE, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - /* Source puts */ - if (rank == source) { - sendtype.InitBuf( &sendtype ); - - err = MPI_Put( sendtype.buf, sendtype.count, - sendtype.datatype, dest, 0, - recvtype.count, recvtype.datatype, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - } - - /* Fence 2 */ - err = MPI_Win_fence( 0, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - /* dest checks data, then Dest puts */ - if (rank == dest) { - err = MTestCheckRecv( 0, &recvtype ); - if (err) { if (errs++ < MAX_PERR) { - PrintRecvedError( "fence 2", &sendtype, &recvtype ); - } - } - sendtype.InitBuf( &sendtype ); - - err = MPI_Put( sendtype.buf, sendtype.count, - sendtype.datatype, source, 0, - recvtype.count, recvtype.datatype, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - } - - /* Fence 3 */ - err = MPI_Win_fence( 0, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - /* src checks data, then Src and dest puts*/ - if (rank == source) { - err = MTestCheckRecv( 0, &recvtype ); - if (err) { if (errs++ < MAX_PERR) { - PrintRecvedError( "fence 3", &sendtype, &recvtype ); - } - } - sendtype.InitBuf( &sendtype ); - - err = MPI_Put( sendtype.buf, sendtype.count, - sendtype.datatype, dest, 0, - recvtype.count, recvtype.datatype, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - } - if (rank == dest) { - sendtype.InitBuf( &sendtype ); - - err = MPI_Put( sendtype.buf, sendtype.count, - sendtype.datatype, source, 0, - recvtype.count, recvtype.datatype, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - } - - /* Fence 4 */ - err = MPI_Win_fence( MPI_MODE_NOSUCCEED, win ); - if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); } - /* src and dest checks data */ - if (rank == source) { - err = MTestCheckRecv( 0, &recvtype ); - if (err) { if (errs++ < MAX_PERR) { - PrintRecvedError( "src fence4", &sendtype, &recvtype ); - } - } - } - if (rank == dest) { - err = MTestCheckRecv( 0, &recvtype ); - if (err) { if (errs++ < MAX_PERR) { - PrintRecvedError( "dest fence4", &sendtype, &recvtype ); - } - } - } - - MPI_Win_free( &win ); - MTestFreeDatatype( &sendtype ); - MTestFreeDatatype( &recvtype ); - - /* Only do one datatype in the simple case */ - if (onlyInt) break; - } - /* Only do one count in the simple case */ - if (onlyInt) break; - } + if (getenv("MTEST_SIMPLE")) + onlyInt = 1; + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + + MTestPrintfMsg(1, + "Putting count = %d of sendtype %s receive type %s\n", + count, MTestGetDatatypeName(&sendtype), + MTestGetDatatypeName(&recvtype)); + + /* Make sure that everyone has a recv buffer */ + recvtype.InitBuf(&recvtype); + + MPI_Type_extent(recvtype.datatype, &extent); + MPI_Type_lb(recvtype.datatype, &lb); + MPI_Win_create(recvtype.buf, recvtype.count * extent + lb, + extent, MPI_INFO_NULL, comm, &win); + /* To improve reporting of problems about operations, we + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); + + /* At this point, we have all of the elements that we + * need to begin the multiple fence and put tests */ + /* Fence 1 */ + err = MPI_Win_fence(MPI_MODE_NOPRECEDE, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + /* Source puts */ + if (rank == source) { + sendtype.InitBuf(&sendtype); + + err = MPI_Put(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + } + + /* Fence 2 */ + err = MPI_Win_fence(0, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + /* dest checks data, then Dest puts */ + if (rank == dest) { + err = MTestCheckRecv(0, &recvtype); + if (err) { + if (errs++ < MAX_PERR) { + PrintRecvedError("fence 2", &sendtype, &recvtype); + } + } + sendtype.InitBuf(&sendtype); + + err = MPI_Put(sendtype.buf, sendtype.count, + sendtype.datatype, source, 0, + recvtype.count, recvtype.datatype, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + } + + /* Fence 3 */ + err = MPI_Win_fence(0, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + /* src checks data, then Src and dest puts */ + if (rank == source) { + err = MTestCheckRecv(0, &recvtype); + if (err) { + if (errs++ < MAX_PERR) { + PrintRecvedError("fence 3", &sendtype, &recvtype); + } + } + sendtype.InitBuf(&sendtype); + + err = MPI_Put(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + } + if (rank == dest) { + sendtype.InitBuf(&sendtype); + + err = MPI_Put(sendtype.buf, sendtype.count, + sendtype.datatype, source, 0, + recvtype.count, recvtype.datatype, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + } + + /* Fence 4 */ + err = MPI_Win_fence(MPI_MODE_NOSUCCEED, win); + if (err) { + if (errs++ < MAX_PERR) + MTestPrintError(err); + } + /* src and dest checks data */ + if (rank == source) { + err = MTestCheckRecv(0, &recvtype); + if (err) { + if (errs++ < MAX_PERR) { + PrintRecvedError("src fence4", &sendtype, &recvtype); + } + } + } + if (rank == dest) { + err = MTestCheckRecv(0, &recvtype); + if (err) { + if (errs++ < MAX_PERR) { + PrintRecvedError("dest fence4", &sendtype, &recvtype); + } + } + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + + /* Only do one datatype in the simple case */ + if (onlyInt) + break; + } + /* Only do one count in the simple case */ + if (onlyInt) + break; + } MTestFreeComm(&comm); - /* Only do one communicator in the simple case */ - if (onlyInt) break; + /* Only do one communicator in the simple case */ + if (onlyInt) + break; } - MTest_Finalize( errs ); + MTest_Finalize(errs); + + - - MPI_Finalize(); return 0; } -int PrintRecvedError( const char *msg, - MTestDatatype *sendtypePtr, MTestDatatype *recvtypePtr ) +int PrintRecvedError(const char *msg, MTestDatatype * sendtypePtr, MTestDatatype * recvtypePtr) { - printf( "At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", - msg, - MTestGetDatatypeName( recvtypePtr ), - MTestGetDatatypeName( sendtypePtr ) ); + printf + ("At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", + msg, MTestGetDatatypeName(recvtypePtr), MTestGetDatatypeName(sendtypePtr)); /* Redo the test, with the errors printed */ recvtypePtr->printErrors = 1; - (void)MTestCheckRecv( 0, recvtypePtr ); + (void) MTestCheckRecv(0, recvtypePtr); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/fence_shm.c b/teshsuite/smpi/mpich3-test/rma/fence_shm.c index d3f53c0951..ac50128b3a 100644 --- a/teshsuite/smpi/mpich3-test/rma/fence_shm.c +++ b/teshsuite/smpi/mpich3-test/rma/fence_shm.c @@ -78,8 +78,7 @@ int main(int argc, char *argv[]) if (result_data != one) { errors++; - printf("Expected: result_data = %d Actual: result_data = %d\n", - one, result_data); + printf("Expected: result_data = %d Actual: result_data = %d\n", one, result_data); } } diff --git a/teshsuite/smpi/mpich3-test/rma/fetch_and_op.c b/teshsuite/smpi/mpich3-test/rma/fetch_and_op.c index f8b7fb23e8..bd10bb6017 100644 --- a/teshsuite/smpi/mpich3-test/rma/fetch_and_op.c +++ b/teshsuite/smpi/mpich3-test/rma/fetch_and_op.c @@ -42,7 +42,8 @@ #define CMP(x, y) ((x - ((TYPE_C) (y))) > 1.0e-9) -void reset_vars(TYPE_C *val_ptr, TYPE_C *res_ptr, MPI_Win win) { +void reset_vars(TYPE_C * val_ptr, TYPE_C * res_ptr, MPI_Win win) +{ int i, rank, nproc; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -58,24 +59,28 @@ void reset_vars(TYPE_C *val_ptr, TYPE_C *res_ptr, MPI_Win win) { MPI_Barrier(MPI_COMM_WORLD); } -int main(int argc, char **argv) { - int i, rank, nproc, mpi_type_size; - int errors = 0, all_errors = 0; - TYPE_C *val_ptr, *res_ptr; - MPI_Win win; +int main(int argc, char **argv) +{ + int i, rank, nproc, mpi_type_size; + int errors = 0, all_errors = 0; + TYPE_C *val_ptr, *res_ptr; + MPI_Win win; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); - + MPI_Type_size(TYPE_MPI, &mpi_type_size); assert(mpi_type_size == sizeof(TYPE_C)); - val_ptr = malloc(sizeof(TYPE_C)*nproc); - res_ptr = malloc(sizeof(TYPE_C)*nproc); + val_ptr = malloc(sizeof(TYPE_C) * nproc); + res_ptr = malloc(sizeof(TYPE_C) * nproc); + MTEST_VG_MEM_INIT(val_ptr, sizeof(TYPE_C) * nproc); + MTEST_VG_MEM_INIT(res_ptr, sizeof(TYPE_C) * nproc); - MPI_Win_create(val_ptr, sizeof(TYPE_C)*nproc, sizeof(TYPE_C), MPI_INFO_NULL, MPI_COMM_WORLD, &win); + MPI_Win_create(val_ptr, sizeof(TYPE_C) * nproc, sizeof(TYPE_C), MPI_INFO_NULL, MPI_COMM_WORLD, + &win); /* Test self communication */ @@ -89,8 +94,10 @@ int main(int argc, char **argv) { } MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); - if ( CMP(val_ptr[0], ITER) ) { - SQUELCH( printf("%d->%d -- SELF: expected "TYPE_FMT", got "TYPE_FMT"\n", rank, rank, (TYPE_C) ITER, val_ptr[0]); ); + if (CMP(val_ptr[0], ITER)) { + SQUELCH(printf + ("%d->%d -- SELF: expected " TYPE_FMT ", got " TYPE_FMT "\n", rank, rank, + (TYPE_C) ITER, val_ptr[0]);); errors++; } MPI_Win_unlock(rank, win); @@ -101,11 +108,13 @@ int main(int argc, char **argv) { for (i = 0; i < ITER; i++) { TYPE_C one = 1, result = -1; - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank+1)%nproc, 0, win); - MPI_Fetch_and_op(&one, &result, TYPE_MPI, (rank+1)%nproc, 0, MPI_SUM, win); - MPI_Win_unlock((rank+1)%nproc, win); - if ( CMP(result, i) ) { - SQUELCH( printf("%d->%d -- NEIGHBOR[%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", (rank+1)%nproc, rank, i, (TYPE_C) i, result); ); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank + 1) % nproc, 0, win); + MPI_Fetch_and_op(&one, &result, TYPE_MPI, (rank + 1) % nproc, 0, MPI_SUM, win); + MPI_Win_unlock((rank + 1) % nproc, win); + if (CMP(result, i)) { + SQUELCH(printf + ("%d->%d -- NEIGHBOR[%d]: expected result " TYPE_FMT ", got " TYPE_FMT "\n", + (rank + 1) % nproc, rank, i, (TYPE_C) i, result);); errors++; } } @@ -113,8 +122,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); - if ( CMP(val_ptr[0], ITER) ) { - SQUELCH( printf("%d->%d -- NEIGHBOR: expected "TYPE_FMT", got "TYPE_FMT"\n", (rank+1)%nproc, rank, (TYPE_C) ITER, val_ptr[0]); ); + if (CMP(val_ptr[0], ITER)) { + SQUELCH(printf + ("%d->%d -- NEIGHBOR: expected " TYPE_FMT ", got " TYPE_FMT "\n", + (rank + 1) % nproc, rank, (TYPE_C) ITER, val_ptr[0]);); errors++; } MPI_Win_unlock(rank, win); @@ -136,8 +147,10 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); if (rank == 0 && nproc > 1) { - if ( CMP(val_ptr[0], ITER*(nproc-1)) ) { - SQUELCH( printf("*->%d - CONTENTION: expected="TYPE_FMT" val="TYPE_FMT"\n", rank, (TYPE_C) ITER*(nproc-1), val_ptr[0]); ); + if (CMP(val_ptr[0], ITER * (nproc - 1))) { + SQUELCH(printf + ("*->%d - CONTENTION: expected=" TYPE_FMT " val=" TYPE_FMT "\n", rank, + (TYPE_C) ITER * (nproc - 1), val_ptr[0]);); errors++; } } @@ -159,8 +172,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); for (j = 0; j < nproc; j++) { - if ( CMP(res_ptr[j], i*rank) ) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE) [%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", rank, j, i, (TYPE_C) i*rank, res_ptr[j]); ); + if (CMP(res_ptr[j], i * rank)) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (FENCE) [%d]: expected result " TYPE_FMT ", got " + TYPE_FMT "\n", rank, j, i, (TYPE_C) i * rank, res_ptr[j]);); errors++; } } @@ -169,8 +184,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); for (i = 0; i < nproc; i++) { - if ( CMP(val_ptr[i], ITER*i) ) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE): expected "TYPE_FMT", got "TYPE_FMT"\n", i, rank, (TYPE_C) ITER*i, val_ptr[i]); ); + if (CMP(val_ptr[i], ITER * i)) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (FENCE): expected " TYPE_FMT ", got " TYPE_FMT "\n", i, + rank, (TYPE_C) ITER * i, val_ptr[i]);); errors++; } } @@ -192,8 +209,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); for (j = 0; j < nproc; j++) { - if ( CMP(res_ptr[j], i*rank) ) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", rank, j, i, (TYPE_C) i*rank, res_ptr[j]); ); + if (CMP(res_ptr[j], i * rank)) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: expected result " TYPE_FMT ", got " + TYPE_FMT "\n", rank, j, i, (TYPE_C) i * rank, res_ptr[j]);); errors++; } } @@ -202,8 +221,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); for (i = 0; i < nproc; i++) { - if ( CMP(val_ptr[i], ITER*i) ) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected "TYPE_FMT", got "TYPE_FMT"\n", i, rank, (TYPE_C) ITER*i, val_ptr[i]); ); + if (CMP(val_ptr[i], ITER * i)) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected " TYPE_FMT ", got " TYPE_FMT "\n", + i, rank, (TYPE_C) ITER * i, val_ptr[i]);); errors++; } } @@ -226,8 +247,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); for (j = 0; j < nproc; j++) { - if ( CMP(res_ptr[j], i*rank) ) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", rank, j, i, (TYPE_C) i*rank, res_ptr[j]); ); + if (CMP(res_ptr[j], i * rank)) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: expected result " TYPE_FMT + ", got " TYPE_FMT "\n", rank, j, i, (TYPE_C) i * rank, res_ptr[j]);); errors++; } } @@ -236,8 +259,10 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); for (i = 0; i < nproc; i++) { - if ( CMP(val_ptr[i], ITER*i) ) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected "TYPE_FMT", got "TYPE_FMT"\n", i, rank, (TYPE_C) ITER*i, val_ptr[i]); ); + if (CMP(val_ptr[i], ITER * i)) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected " TYPE_FMT ", got " TYPE_FMT + "\n", i, rank, (TYPE_C) ITER * i, val_ptr[i]);); errors++; } } @@ -255,15 +280,15 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); for (i = 0; i < ITER; i++) { - int target = (rank+1) % nproc; + int target = (rank + 1) % nproc; MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Fetch_and_op(NULL, res_ptr, TYPE_MPI, target, 0, MPI_NO_OP, win); MPI_Win_unlock(target, win); if (res_ptr[0] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[0]); ); + SQUELCH(printf("%d->%d -- NOP[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[0]);); errors++; } } @@ -287,8 +312,8 @@ int main(int argc, char **argv) { MPI_Win_unlock(target, win); if (res_ptr[0] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP_SELF[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[0]); ); + SQUELCH(printf("%d->%d -- NOP_SELF[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[0]);); errors++; } } diff --git a/teshsuite/smpi/mpich3-test/rma/fetchandadd.c b/teshsuite/smpi/mpich3-test/rma/fetchandadd.c index dd12a4c64a..493e158c6b 100644 --- a/teshsuite/smpi/mpich3-test/rma/fetchandadd.c +++ b/teshsuite/smpi/mpich3-test/rma/fetchandadd.c @@ -3,64 +3,62 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "stdlib.h" #include "mpitest.h" /* Fetch and add example from Using MPI-2 (the non-scalable version, - Fig. 6.12). */ + Fig. 6.12). */ -#define NTIMES 20 /* no of times each process calls the counter - routine */ +#define NTIMES 20 /* no of times each process calls the counter + * routine */ -int localvalue=0; /* contribution of this process to the counter. We - define it as a global variable because attribute - caching on the window is not enabled yet. */ +int localvalue = 0; /* contribution of this process to the counter. We + * define it as a global variable because attribute + * caching on the window is not enabled yet. */ void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type, int rank, int nprocs, int *value); int compar(const void *a, const void *b); -int main(int argc, char *argv[]) -{ - int rank, nprocs, i, blens[2], disps[2], *counter_mem, *val_array, - *results, *counter_vals; +int main(int argc, char *argv[]) +{ + int rank, nprocs, i, blens[2], disps[2], *counter_mem, *val_array, *results, *counter_vals; MPI_Datatype get_type; MPI_Win win; int errs = 0; - - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) { /* allocate counter memory and initialize to 0 */ counter_mem = (int *) calloc(nprocs, sizeof(int)); - MPI_Win_create(counter_mem, nprocs*sizeof(int), sizeof(int), + MPI_Win_create(counter_mem, nprocs * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); free(counter_mem); - /* gather the results from other processes, sort them, and check - whether they represent a counter being incremented by 1 */ + /* gather the results from other processes, sort them, and check + * whether they represent a counter being incremented by 1 */ - results = (int *) malloc(NTIMES*nprocs*sizeof(int)); - for (i=0; i= nprocs */ pof2 = 1; - while (pof2 < nprocs) pof2 *= 2; + while (pof2 < nprocs) + pof2 *= 2; - counter_mem = (int *) calloc(pof2*2, sizeof(int)); - MPI_Win_create(counter_mem, pof2*2*sizeof(int), sizeof(int), + counter_mem = (int *) calloc(pof2 * 2, sizeof(int)); + MPI_Win_create(counter_mem, pof2 * 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); free(counter_mem); - /* gather the results from other processes, sort them, and check - whether they represent a counter being incremented by 1 */ + /* gather the results from other processes, sort them, and check + * whether they represent a counter being incremented by 1 */ - results = (int *) malloc(NTIMES*nprocs*sizeof(int)); - for (i=0; i>= 1; @@ -83,28 +83,28 @@ int main(int argc, char *argv[]) get_idx = (int *) malloc(nlevels * sizeof(int)); acc_idx = (int *) malloc(nlevels * sizeof(int)); - level = 0; - idx = 0; + level = 0; + idx = 0; tmp_rank = rank; - while (mask >= 1) { - if (tmp_rank < mask) { + while (mask >= 1) { + if (tmp_rank < mask) { /* go to left for acc_idx, go to right for - get_idx. set idx=acc_idx for next iteration */ - acc_idx[level] = idx + 1; - get_idx[level] = idx + mask*2; - idx = idx + 1; - } - else { + * get_idx. set idx=acc_idx for next iteration */ + acc_idx[level] = idx + 1; + get_idx[level] = idx + mask * 2; + idx = idx + 1; + } + else { /* go to right for acc_idx, go to left for - get_idx. set idx=acc_idx for next iteration */ - acc_idx[level] = idx + mask*2; - get_idx[level] = idx + 1; - idx = idx + mask*2; - } + * get_idx. set idx=acc_idx for next iteration */ + acc_idx[level] = idx + mask * 2; + get_idx[level] = idx + 1; + idx = idx + mask * 2; + } level++; tmp_rank = tmp_rank % mask; - mask >>= 1; - } + mask >>= 1; + } /* for (i=0; i= nprocs */ pof2 = 1; - while (pof2 < nprocs) pof2 *= 2; + while (pof2 < nprocs) + pof2 *= 2; /* counter_mem = (int *) calloc(pof2*2, sizeof(int)); */ - i = MPI_Alloc_mem(pof2*2*sizeof(int), MPI_INFO_NULL, &counter_mem); + i = MPI_Alloc_mem(pof2 * 2 * sizeof(int), MPI_INFO_NULL, &counter_mem); if (i) { printf("Can't allocate memory in test program\n"); MPI_Abort(MPI_COMM_WORLD, 1); } - for (i=0; i<(pof2*2); i++) counter_mem[i] = 0; + for (i = 0; i < (pof2 * 2); i++) + counter_mem[i] = 0; - MPI_Win_create(counter_mem, pof2*2*sizeof(int), sizeof(int), + MPI_Win_create(counter_mem, pof2 * 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); /* free(counter_mem) */ MPI_Free_mem(counter_mem); - /* gather the results from other processes, sort them, and check - whether they represent a counter being incremented by 1 */ + /* gather the results from other processes, sort them, and check + * whether they represent a counter being incremented by 1 */ - results = (int *) malloc(NTIMES*nprocs*sizeof(int)); - for (i=0; i>= 1; @@ -95,28 +96,28 @@ int main(int argc, char *argv[]) get_idx = (int *) malloc(nlevels * sizeof(int)); acc_idx = (int *) malloc(nlevels * sizeof(int)); - level = 0; - idx = 0; + level = 0; + idx = 0; tmp_rank = rank; - while (mask >= 1) { - if (tmp_rank < mask) { + while (mask >= 1) { + if (tmp_rank < mask) { /* go to left for acc_idx, go to right for - get_idx. set idx=acc_idx for next iteration */ - acc_idx[level] = idx + 1; - get_idx[level] = idx + mask*2; - idx = idx + 1; - } - else { + * get_idx. set idx=acc_idx for next iteration */ + acc_idx[level] = idx + 1; + get_idx[level] = idx + mask * 2; + idx = idx + 1; + } + else { /* go to right for acc_idx, go to left for - get_idx. set idx=acc_idx for next iteration */ - acc_idx[level] = idx + mask*2; - get_idx[level] = idx + 1; - idx = idx + mask*2; - } + * get_idx. set idx=acc_idx for next iteration */ + acc_idx[level] = idx + mask * 2; + get_idx[level] = idx + 1; + idx = idx + mask * 2; + } level++; tmp_rank = tmp_rank % mask; - mask >>= 1; - } + mask >>= 1; + } /* for (i=0; i 0) { - MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } - MPI_Get_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window); + MPI_Get_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, + window); MPI_Win_flush(0, window); - exp = (rank + nproc-1) % nproc; + exp = (rank + nproc - 1) % nproc; if (val != exp) { printf("%d - Got %d, expected %d\n", rank, val, exp); errors++; } - if (rank < nproc-1) { - MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD); + if (rank < nproc - 1) { + MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); @@ -76,7 +79,8 @@ int main( int argc, char *argv[] ) MPI_Win_unlock(0, window); MPI_Win_free(&window); - if (buf) MPI_Free_mem(buf); + if (buf) + MPI_Free_mem(buf); MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); diff --git a/teshsuite/smpi/mpich3-test/rma/get-struct.c b/teshsuite/smpi/mpich3-test/rma/get-struct.c new file mode 100644 index 0000000000..b85cfe5fbf --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/get-struct.c @@ -0,0 +1,173 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include "mpitest.h" +#include +#include + +/* Communicating a datatype built out of structs + * This test was motivated by the failure of an example program for + * RMA involving simple operations on a struct that included a struct + * + * The observed failure was a SEGV in the MPI_Get + * + * + */ +#define MAX_KEY_SIZE 64 +#define MAX_VALUE_SIZE 256 +typedef struct { + MPI_Aint disp; + int rank; + void *lptr; +} Rptr; +typedef struct { + Rptr next; + char key[MAX_KEY_SIZE], value[MAX_VALUE_SIZE]; +} ListElm; +Rptr nullDptr = { 0, -1, 0 }; + +int testCases = -1; +#define BYTE_ONLY 0x1 +#define TWO_STRUCT 0x2 +int isOneLevel = 0; + +int main(int argc, char **argv) +{ + int errors = 0; + Rptr headDptr; + ListElm *headLptr = 0; + int i, wrank; + MPI_Datatype dptrType, listelmType; + MPI_Win listwin; + + MTest_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &wrank); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-byteonly") == 0) { + testCases = BYTE_ONLY; + } + else if (strcmp(argv[i], "-twostruct") == 0) { + testCases = TWO_STRUCT; + } + else if (strcmp(argv[i], "-onelevel") == 0) { + isOneLevel = 1; + } + else { + printf("Unrecognized argument %s\n", argv[i]); + } + } + + /* Create the datatypes that we will use to move the data */ + { + int blens[3]; + MPI_Aint displ[3]; + MPI_Datatype dtypes[3]; + ListElm sampleElm; + + blens[0] = 1; + blens[1] = 1; + MPI_Get_address(&nullDptr.disp, &displ[0]); + MPI_Get_address(&nullDptr.rank, &displ[1]); + displ[1] = displ[1] - displ[0]; + displ[0] = 0; + dtypes[0] = MPI_AINT; + dtypes[1] = MPI_INT; + MPI_Type_create_struct(2, blens, displ, dtypes, &dptrType); + MPI_Type_commit(&dptrType); + + if (isOneLevel) { + blens[0] = sizeof(nullDptr); + dtypes[0] = MPI_BYTE; + } + else { + blens[0] = 1; + dtypes[0] = dptrType; + } + blens[1] = MAX_KEY_SIZE; + dtypes[1] = MPI_CHAR; + blens[2] = MAX_VALUE_SIZE; + dtypes[2] = MPI_CHAR; + MPI_Get_address(&sampleElm.next, &displ[0]); + MPI_Get_address(&sampleElm.key[0], &displ[1]); + MPI_Get_address(&sampleElm.value[0], &displ[2]); + displ[2] -= displ[0]; + displ[1] -= displ[0]; + displ[0] = 0; + for (i = 0; i < 3; i++) { + MTestPrintfMsg(0, "%d:count=%d,disp=%ld\n", i, blens[i], displ[i]); + } + MPI_Type_create_struct(3, blens, displ, dtypes, &listelmType); + MPI_Type_commit(&listelmType); + } + + MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &listwin); + + headDptr.rank = 0; + if (wrank == 0) { + /* Create 1 list element (the head) and initialize it */ + MPI_Alloc_mem(sizeof(ListElm), MPI_INFO_NULL, &headLptr); + MPI_Get_address(headLptr, &headDptr.disp); + headLptr->next.rank = -1; + headLptr->next.disp = (MPI_Aint) MPI_BOTTOM; + headLptr->next.lptr = 0; + strncpy(headLptr->key, "key1", MAX_KEY_SIZE); + strncpy(headLptr->value, "value1", MAX_VALUE_SIZE); + MPI_Win_attach(listwin, headLptr, sizeof(ListElm)); + } + MPI_Bcast(&headDptr.disp, 1, MPI_AINT, 0, MPI_COMM_WORLD); + + MPI_Barrier(MPI_COMM_WORLD); + + if (wrank == 1) { + ListElm headcopy; + + MPI_Win_lock_all(0, listwin); + /* Get head element with simple get of BYTES */ + if (testCases & BYTE_ONLY) { + headcopy.next.rank = 100; + headcopy.next.disp = 0xefefefef; + MPI_Get(&headcopy, sizeof(ListElm), MPI_BYTE, + headDptr.rank, headDptr.disp, sizeof(ListElm), MPI_BYTE, listwin); + MPI_Win_flush(headDptr.rank, listwin); + if (headcopy.next.rank != -1 && headcopy.next.disp != (MPI_Aint) MPI_BOTTOM) { + errors++; + printf("MPI_BYTE: headcopy contains incorrect next:<%d,%ld>\n", + headcopy.next.rank, (long) headcopy.next.disp); + } + } + + if (testCases & TWO_STRUCT) { + headcopy.next.rank = 100; + headcopy.next.disp = 0xefefefef; + /* Get head element using struct of struct type. This is + * not an identical get to the simple BYTE one above but should + * work */ + MPI_Get(&headcopy, 1, listelmType, headDptr.rank, headDptr.disp, + 1, listelmType, listwin); + MPI_Win_flush(headDptr.rank, listwin); + if (headcopy.next.rank != -1 && headcopy.next.disp != (MPI_Aint) MPI_BOTTOM) { + errors++; + printf("ListelmType: headcopy contains incorrect next:<%d,%ld>\n", + headcopy.next.rank, (long) headcopy.next.disp); + } + } + + MPI_Win_unlock_all(listwin); + } + MPI_Barrier(MPI_COMM_WORLD); + if (wrank == 0) { + MPI_Win_detach(listwin, headLptr); + MPI_Free_mem(headLptr); + } + MPI_Win_free(&listwin); + MPI_Type_free(&dptrType); + MPI_Type_free(&listelmType); + + MTest_Finalize(errors); + MPI_Finalize(); + return MTestReturnValue(errors); +} diff --git a/teshsuite/smpi/mpich3-test/rma/get_acc_local.c b/teshsuite/smpi/mpich3-test/rma/get_acc_local.c index ecf3258407..c1a38db86c 100644 --- a/teshsuite/smpi/mpich3-test/rma/get_acc_local.c +++ b/teshsuite/smpi/mpich3-test/rma/get_acc_local.c @@ -10,33 +10,32 @@ #include "mpitest.h" -int errors = 0; -const int NITER = 1000; +int errors = 0; +const int NITER = 1000; const int acc_val = 3; int main(int argc, char **argv) { - int rank, nproc; - int out_val, i, counter = 0; - MPI_Win win; + int rank, nproc; + int out_val, i, counter = 0; + MPI_Win win; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); - MPI_Win_create(&counter, sizeof(int), sizeof(int), MPI_INFO_NULL, - MPI_COMM_WORLD, &win); + MPI_Win_create(&counter, sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); for (i = 0; i < NITER; i++) { MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); MPI_Get_accumulate(&acc_val, 1, MPI_INT, &out_val, 1, MPI_INT, - rank, 0, 1, MPI_INT, MPI_SUM, win); + rank, 0, 1, MPI_INT, MPI_SUM, win); MPI_Win_unlock(rank, win); - if (out_val != acc_val*i) { + if (out_val != acc_val * i) { errors++; - printf("Error: got %d, expected %d at iter %d\n", out_val, acc_val*i, i); + printf("Error: got %d, expected %d at iter %d\n", out_val, acc_val * i, i); break; } } diff --git a/teshsuite/smpi/mpich3-test/rma/get_accumulate.c b/teshsuite/smpi/mpich3-test/rma/get_accumulate.c index 5a533fe0cc..0ffee69ec1 100644 --- a/teshsuite/smpi/mpich3-test/rma/get_accumulate.c +++ b/teshsuite/smpi/mpich3-test/rma/get_accumulate.c @@ -39,7 +39,9 @@ # define TYPE_MPI TYPE_MPI_BASE #endif -void reset_bufs(TYPE_C *win_ptr, TYPE_C *res_ptr, TYPE_C *val_ptr, TYPE_C value, MPI_Win win) { +static void reset_bufs(TYPE_C * win_ptr, TYPE_C * res_ptr, TYPE_C * val_ptr, TYPE_C value, + MPI_Win win) +{ int rank, nproc, i; MPI_Barrier(MPI_COMM_WORLD); @@ -48,10 +50,10 @@ void reset_bufs(TYPE_C *win_ptr, TYPE_C *res_ptr, TYPE_C *val_ptr, TYPE_C value, MPI_Comm_size(MPI_COMM_WORLD, &nproc); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); - memset(win_ptr, 0, sizeof(TYPE_C)*nproc*COUNT); + memset(win_ptr, 0, sizeof(TYPE_C) * nproc * COUNT); MPI_Win_unlock(rank, win); - memset(res_ptr, -1, sizeof(TYPE_C)*nproc*COUNT); + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); for (i = 0; i < COUNT; i++) val_ptr[i] = value; @@ -59,11 +61,12 @@ void reset_bufs(TYPE_C *win_ptr, TYPE_C *res_ptr, TYPE_C *val_ptr, TYPE_C value, MPI_Barrier(MPI_COMM_WORLD); } -int main(int argc, char **argv) { - int i, rank, nproc; - int errors = 0, all_errors = 0; - TYPE_C *win_ptr, *res_ptr, *val_ptr; - MPI_Win win; +int main(int argc, char **argv) +{ + int i, rank, nproc; + int errors = 0, all_errors = 0; + TYPE_C *win_ptr, *res_ptr, *val_ptr; + MPI_Win win; #if defined (GACC_TYPE_DERIVED) MPI_Datatype derived_type; #endif @@ -73,16 +76,16 @@ int main(int argc, char **argv) { MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); - win_ptr = malloc(sizeof(TYPE_C)*nproc*COUNT); - res_ptr = malloc(sizeof(TYPE_C)*nproc*COUNT); - val_ptr = malloc(sizeof(TYPE_C)*COUNT); + win_ptr = malloc(sizeof(TYPE_C) * nproc * COUNT); + res_ptr = malloc(sizeof(TYPE_C) * nproc * COUNT); + val_ptr = malloc(sizeof(TYPE_C) * COUNT); #if defined (GACC_TYPE_DERIVED) MPI_Type_contiguous(1, TYPE_MPI_BASE, &derived_type); MPI_Type_commit(&derived_type); #endif - MPI_Win_create(win_ptr, sizeof(TYPE_C)*nproc*COUNT, sizeof(TYPE_C), + MPI_Win_create(win_ptr, sizeof(TYPE_C) * nproc * COUNT, sizeof(TYPE_C), MPI_INFO_NULL, MPI_COMM_WORLD, &win); /* Test self communication */ @@ -91,16 +94,16 @@ int main(int argc, char **argv) { for (i = 0; i < ITER; i++) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); - MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - rank, 0, COUNT, TYPE_MPI, MPI_SUM, win); + MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, + rank, 0, COUNT, TYPE_MPI, MPI_SUM, win); MPI_Win_unlock(rank, win); } MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); for (i = 0; i < COUNT; i++) { if (win_ptr[i] != ITER) { - SQUELCH( printf("%d->%d -- SELF[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - rank, rank, i, (TYPE_C) ITER, win_ptr[i]); ); + SQUELCH(printf("%d->%d -- SELF[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + rank, rank, i, (TYPE_C) ITER, win_ptr[i]);); errors++; } } @@ -111,10 +114,10 @@ int main(int argc, char **argv) { reset_bufs(win_ptr, res_ptr, val_ptr, 1, win); for (i = 0; i < ITER; i++) { - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank+1)%nproc, 0, win); - MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - (rank+1)%nproc, 0, COUNT, TYPE_MPI, MPI_SUM, win); - MPI_Win_unlock((rank+1)%nproc, win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank + 1) % nproc, 0, win); + MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, + (rank + 1) % nproc, 0, COUNT, TYPE_MPI, MPI_SUM, win); + MPI_Win_unlock((rank + 1) % nproc, win); } MPI_Barrier(MPI_COMM_WORLD); @@ -122,8 +125,8 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); for (i = 0; i < COUNT; i++) { if (win_ptr[i] != ITER) { - SQUELCH( printf("%d->%d -- NEIGHBOR[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - (rank+1)%nproc, rank, i, (TYPE_C) ITER, win_ptr[i]); ); + SQUELCH(printf("%d->%d -- NEIGHBOR[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + (rank + 1) % nproc, rank, i, (TYPE_C) ITER, win_ptr[i]);); errors++; } } @@ -136,8 +139,8 @@ int main(int argc, char **argv) { if (rank != 0) { for (i = 0; i < ITER; i++) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win); - MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - 0, 0, COUNT, TYPE_MPI, MPI_SUM, win); + MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, + 0, 0, COUNT, TYPE_MPI, MPI_SUM, win); MPI_Win_unlock(0, win); } } @@ -147,9 +150,9 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); if (rank == 0 && nproc > 1) { for (i = 0; i < COUNT; i++) { - if (win_ptr[i] != ITER*(nproc-1)) { - SQUELCH( printf("*->%d - CONTENTION[%d]: expected="TYPE_FMT" val="TYPE_FMT"\n", - rank, i, (TYPE_C) ITER*(nproc-1), win_ptr[i]); ); + if (win_ptr[i] != ITER * (nproc - 1)) { + SQUELCH(printf("*->%d - CONTENTION[%d]: expected=" TYPE_FMT " val=" TYPE_FMT "\n", + rank, i, (TYPE_C) ITER * (nproc - 1), win_ptr[i]);); errors++; } } @@ -165,8 +168,8 @@ int main(int argc, char **argv) { MPI_Win_fence(MPI_MODE_NOPRECEDE, win); for (j = 0; j < nproc; j++) { - MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j*COUNT], COUNT, TYPE_MPI, - j, rank*COUNT, COUNT, TYPE_MPI, MPI_SUM, win); + MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j * COUNT], COUNT, TYPE_MPI, + j, rank * COUNT, COUNT, TYPE_MPI, MPI_SUM, win); } MPI_Win_fence(MPI_MODE_NOSUCCEED, win); MPI_Barrier(MPI_COMM_WORLD); @@ -174,9 +177,11 @@ int main(int argc, char **argv) { for (j = 0; j < nproc; j++) { int c; for (c = 0; c < COUNT; c++) { - if (res_ptr[j*COUNT+c] != i*rank) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE) [%d]: iter %d, expected result "TYPE_FMT", got "TYPE_FMT"\n", - rank, j, c, i, (TYPE_C) i*rank, res_ptr[j*COUNT+c]); ); + if (res_ptr[j * COUNT + c] != i * rank) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (FENCE) [%d]: iter %d, expected result " TYPE_FMT + ", got " TYPE_FMT "\n", rank, j, c, i, (TYPE_C) i * rank, + res_ptr[j * COUNT + c]);); errors++; } } @@ -188,9 +193,10 @@ int main(int argc, char **argv) { for (i = 0; i < nproc; i++) { int c; for (c = 0; c < COUNT; c++) { - if (win_ptr[i*COUNT+c] != ITER*i) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE): expected "TYPE_FMT", got "TYPE_FMT"\n", - i, rank, (TYPE_C) ITER*i, win_ptr[i*COUNT+c]); ); + if (win_ptr[i * COUNT + c] != ITER * i) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (FENCE): expected " TYPE_FMT ", got " TYPE_FMT "\n", + i, rank, (TYPE_C) ITER * i, win_ptr[i * COUNT + c]);); errors++; } } @@ -206,8 +212,8 @@ int main(int argc, char **argv) { MPI_Win_lock_all(0, win); for (j = 0; j < nproc; j++) { - MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j*COUNT], COUNT, TYPE_MPI, - j, rank*COUNT, COUNT, TYPE_MPI, MPI_SUM, win); + MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j * COUNT], COUNT, TYPE_MPI, + j, rank * COUNT, COUNT, TYPE_MPI, MPI_SUM, win); } MPI_Win_unlock_all(win); MPI_Barrier(MPI_COMM_WORLD); @@ -215,9 +221,11 @@ int main(int argc, char **argv) { for (j = 0; j < nproc; j++) { int c; for (c = 0; c < COUNT; c++) { - if (res_ptr[j*COUNT+c] != i*rank) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: iter %d, expected result "TYPE_FMT", got "TYPE_FMT"\n", - rank, j, c, i, (TYPE_C) i*rank, res_ptr[j*COUNT+c]); ); + if (res_ptr[j * COUNT + c] != i * rank) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: iter %d, expected result " + TYPE_FMT ", got " TYPE_FMT "\n", rank, j, c, i, (TYPE_C) i * rank, + res_ptr[j * COUNT + c]);); errors++; } } @@ -229,9 +237,10 @@ int main(int argc, char **argv) { for (i = 0; i < nproc; i++) { int c; for (c = 0; c < COUNT; c++) { - if (win_ptr[i*COUNT+c] != ITER*i) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected "TYPE_FMT", got "TYPE_FMT"\n", - i, rank, (TYPE_C) ITER*i, win_ptr[i*COUNT+c]); ); + if (win_ptr[i * COUNT + c] != ITER * i) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected " TYPE_FMT ", got " TYPE_FMT + "\n", i, rank, (TYPE_C) ITER * i, win_ptr[i * COUNT + c]);); errors++; } } @@ -247,8 +256,8 @@ int main(int argc, char **argv) { MPI_Win_lock_all(0, win); for (j = 0; j < nproc; j++) { - MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j*COUNT], COUNT, TYPE_MPI, - j, rank*COUNT, COUNT, TYPE_MPI, MPI_SUM, win); + MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j * COUNT], COUNT, TYPE_MPI, + j, rank * COUNT, COUNT, TYPE_MPI, MPI_SUM, win); MPI_Win_flush(j, win); } MPI_Win_unlock_all(win); @@ -257,9 +266,11 @@ int main(int argc, char **argv) { for (j = 0; j < nproc; j++) { int c; for (c = 0; c < COUNT; c++) { - if (res_ptr[j*COUNT+c] != i*rank) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: iter %d, expected result "TYPE_FMT", got "TYPE_FMT"\n", - rank, j, c, i, (TYPE_C) i*rank, res_ptr[j*COUNT+c]); ); + if (res_ptr[j * COUNT + c] != i * rank) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: iter %d, expected result " + TYPE_FMT ", got " TYPE_FMT "\n", rank, j, c, i, (TYPE_C) i * rank, + res_ptr[j * COUNT + c]);); errors++; } } @@ -271,9 +282,10 @@ int main(int argc, char **argv) { for (i = 0; i < nproc; i++) { int c; for (c = 0; c < COUNT; c++) { - if (win_ptr[i*COUNT+c] != ITER*i) { - SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected "TYPE_FMT", got "TYPE_FMT"\n", - i, rank, (TYPE_C) ITER*i, win_ptr[i*COUNT+c]); ); + if (win_ptr[i * COUNT + c] != ITER * i) { + SQUELCH(printf + ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected " TYPE_FMT ", got " + TYPE_FMT "\n", i, rank, (TYPE_C) ITER * i, win_ptr[i * COUNT + c]);); errors++; } } @@ -285,52 +297,58 @@ int main(int argc, char **argv) { reset_bufs(win_ptr, res_ptr, val_ptr, 1, win); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); - for (i = 0; i < COUNT*nproc; i++) + for (i = 0; i < COUNT * nproc; i++) win_ptr[i] = (TYPE_C) rank; MPI_Win_unlock(rank, win); MPI_Barrier(MPI_COMM_WORLD); for (i = 0; i < ITER; i++) { - int j, target = (rank+1) % nproc; + int j, target = (rank + 1) % nproc; /* Test: origin_buf = NULL */ + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); /* reset result buffer. */ + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Get_accumulate(NULL, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); + target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); MPI_Win_unlock(target, win); for (j = 0; j < COUNT; j++) { if (res_ptr[j] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP(1)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[i]); ); + SQUELCH(printf("%d->%d -- NOP(1)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[i]);); errors++; } } /* Test: origin_buf = NULL, origin_count = 0 */ + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Get_accumulate(NULL, 0, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); + target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); MPI_Win_unlock(target, win); for (j = 0; j < COUNT; j++) { if (res_ptr[j] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[i]); ); + SQUELCH(printf("%d->%d -- NOP(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[i]);); errors++; } } /* Test: origin_buf = NULL, origin_count = 0, origin_dtype = NULL */ + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, res_ptr, COUNT, TYPE_MPI, - target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); + target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); MPI_Win_unlock(target, win); for (j = 0; j < COUNT; j++) { if (res_ptr[j] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[i]); ); + SQUELCH(printf("%d->%d -- NOP(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[i]);); errors++; } } @@ -341,7 +359,7 @@ int main(int argc, char **argv) { reset_bufs(win_ptr, res_ptr, val_ptr, 1, win); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); - for (i = 0; i < COUNT*nproc; i++) + for (i = 0; i < COUNT * nproc; i++) win_ptr[i] = (TYPE_C) rank; MPI_Win_unlock(rank, win); MPI_Barrier(MPI_COMM_WORLD); @@ -350,43 +368,52 @@ int main(int argc, char **argv) { int j, target = rank; /* Test: origin_buf = NULL */ + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Get_accumulate(NULL, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); + target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); MPI_Win_unlock(target, win); for (j = 0; j < COUNT; j++) { if (res_ptr[j] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP_SELF(1)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[i]); ); + SQUELCH(printf + ("%d->%d -- NOP_SELF(1)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[i]);); errors++; } } /* Test: origin_buf = NULL, origin_count = 0 */ + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Get_accumulate(NULL, 0, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, - target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); + target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); MPI_Win_unlock(target, win); for (j = 0; j < COUNT; j++) { if (res_ptr[j] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP_SELF(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[i]); ); + SQUELCH(printf + ("%d->%d -- NOP_SELF(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[i]);); errors++; } } /* Test: origin_buf = NULL, origin_count = 0, origin_dtype = NULL */ + memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, res_ptr, COUNT, TYPE_MPI, - target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); + target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win); MPI_Win_unlock(target, win); for (j = 0; j < COUNT; j++) { if (res_ptr[j] != (TYPE_C) target) { - SQUELCH( printf("%d->%d -- NOP_SELF(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n", - target, rank, i, (TYPE_C) target, res_ptr[i]); ); + SQUELCH(printf + ("%d->%d -- NOP_SELF(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n", + target, rank, i, (TYPE_C) target, res_ptr[i]);); errors++; } } diff --git a/teshsuite/smpi/mpich3-test/rma/getfence1.c b/teshsuite/smpi/mpich3-test/rma/getfence1.c index 2aaba8229e..6b068930f7 100644 --- a/teshsuite/smpi/mpich3-test/rma/getfence1.c +++ b/teshsuite/smpi/mpich3-test/rma/getfence1.c @@ -6,94 +6,136 @@ */ #include "mpi.h" #include +#include +#include #include "mpitest.h" +#define LARGE_CNT_CONTIG 5500000 +#define LARGE_CNT_NONCONTIG 1500000 + /* static char MTEST_Descrip[] = "Get with Fence"; */ -int main( int argc, char *argv[] ) +static inline int test(MPI_Comm comm, int rank, int source, int dest, + MTestDatatype * sendtype, MTestDatatype * recvtype) { int errs = 0, err; + int disp_unit; + MPI_Aint extent, lb; + MPI_Win win; + + MTestPrintfMsg(1, + "Getting count = %ld of sendtype %s - count = %ld receive type %s\n", + sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count, + MTestGetDatatypeName(recvtype)); + /* Make sure that everyone has a recv buffer */ + recvtype->InitBuf(recvtype); + sendtype->InitBuf(sendtype); + /* By default, print information about errors */ + recvtype->printErrors = 1; + sendtype->printErrors = 1; + + MPI_Type_extent(sendtype->datatype, &extent); + MPI_Type_lb(sendtype->datatype, &lb); + disp_unit = extent < INT_MAX ? extent : 1; + MPI_Win_create(sendtype->buf, sendtype->count * extent + lb, disp_unit, MPI_INFO_NULL, comm, &win); + MPI_Win_fence(0, win); + if (rank == source) { + /* The source does not need to do anything besides the + * fence */ + MPI_Win_fence(0, win); + } + else if (rank == dest) { + /* To improve reporting of problems about operations, we + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); + + /* This should have the same effect, in terms of + * transfering data, as a send/recv pair */ + err = MPI_Get(recvtype->buf, recvtype->count, + recvtype->datatype, source, 0, sendtype->count, sendtype->datatype, win); + if (err) { + errs++; + if (errs < 10) { + MTestPrintError(err); + } + } + err = MPI_Win_fence(0, win); + if (err) { + errs++; + if (errs < 10) { + MTestPrintError(err); + } + } + err = MTestCheckRecv(0, recvtype); + if (err) { + errs += err; + } + } + else { + MPI_Win_fence(0, win); + } + MPI_Win_free(&win); + + return errs; +} + + +int main(int argc, char *argv[]) +{ + int errs = 0; int rank, size, source, dest; - int minsize = 2, count; - MPI_Comm comm; - MPI_Win win; - MPI_Aint extent; + int minsize = 2, count; + MPI_Comm comm; MTestDatatype sendtype, recvtype; - MTest_Init( &argc, &argv ); - - /* The following illustrates the use of the routines to - run through a selection of communicators and datatypes. - Use subsets of these for tests that do not involve combinations - of communicators, datatypes, and counts of datatypes */ - while (MTestGetIntracommGeneral( &comm, minsize, 1 )) { - if (comm == MPI_COMM_NULL) continue; - /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); - source = 0; - dest = size - 1; - - for (count = 1; count < 65000; count = count * 2) { - while (MTestGetDatatypes( &sendtype, &recvtype, count )) { - /* Make sure that everyone has a recv buffer */ - recvtype.InitBuf( &recvtype ); - sendtype.InitBuf( &sendtype ); - /* By default, print information about errors */ - recvtype.printErrors = 1; - sendtype.printErrors = 1; - - MPI_Type_extent( sendtype.datatype, &extent ); - MPI_Win_create( sendtype.buf, sendtype.count * extent, - (int)extent, MPI_INFO_NULL, comm, &win ); - MPI_Win_fence( 0, win ); - if (rank == source) { - /* The source does not need to do anything besides the - fence */ - MPI_Win_fence( 0, win ); - } - else if (rank == dest) { - /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); - - /* This should have the same effect, in terms of - transfering data, as a send/recv pair */ - err = MPI_Get( recvtype.buf, recvtype.count, - recvtype.datatype, source, 0, - sendtype.count, sendtype.datatype, win ); - if (err) { - errs++; - if (errs < 10) { - MTestPrintError( err ); - } - } - err = MPI_Win_fence( 0, win ); - if (err) { - errs++; - if (errs < 10) { - MTestPrintError( err ); - } - } - err = MTestCheckRecv( 0, &recvtype ); - if (err) { - errs += err; - } - } - else { - MPI_Win_fence( 0, win ); - } - MPI_Win_free( &win ); - MTestFreeDatatype( &recvtype ); - MTestFreeDatatype( &sendtype ); - } - } + MTest_Init(&argc, &argv); + + /* The following illustrates the use of the routines to + * run through a selection of communicators and datatypes. + * Use subsets of these for tests that do not involve combinations + * of communicators, datatypes, and counts of datatypes */ + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + errs += test(comm, rank, source, dest, &sendtype, &recvtype); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } MTestFreeComm(&comm); } - MTest_Finalize( errs ); + /* Part #2: simple large size test - contiguous and noncontiguous */ + if (sizeof(void *) > 4) { /* Only if > 32-bit architecture */ + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + source = 0; + dest = size - 1; + + MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG); + errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype); + + do { + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_NONCONTIG); + } while (strstr(MTestGetDatatypeName(&sendtype), "vector") == NULL); + errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/getgroup.c b/teshsuite/smpi/mpich3-test/rma/getgroup.c index 4dd0c0db93..051bb5f561 100644 --- a/teshsuite/smpi/mpich3-test/rma/getgroup.c +++ b/teshsuite/smpi/mpich3-test/rma/getgroup.c @@ -12,41 +12,41 @@ static char MTEST_Descrip[] = "Test of Win_get_group"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int result; int buf[10]; - MPI_Win win; + MPI_Win win; MPI_Group group, wingroup; int minsize = 2; - MPI_Comm comm; + MPI_Comm comm; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); - /* The following illustrates the use of the routines to - run through a selection of communicators and datatypes. - Use subsets of these for tests that do not involve combinations - of communicators, datatypes, and counts of datatypes */ - while (MTestGetIntracommGeneral( &comm, minsize, 1 )) { - if (comm == MPI_COMM_NULL) continue; + /* The following illustrates the use of the routines to + * run through a selection of communicators and datatypes. + * Use subsets of these for tests that do not involve combinations + * of communicators, datatypes, and counts of datatypes */ + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; - MPI_Win_create( buf, sizeof(int) * 10, sizeof(int), - MPI_INFO_NULL, comm, &win ); - MPI_Win_get_group( win, &wingroup ); - MPI_Comm_group( comm, &group ); - MPI_Group_compare( group, wingroup, &result ); - if (result != MPI_IDENT) { - errs++; - fprintf( stderr, "Group returned by Win_get_group not the same as the input group\n" ); - } - MPI_Group_free( &wingroup ); - MPI_Group_free( &group ); - MPI_Win_free( &win ); + MPI_Win_create(buf, sizeof(int) * 10, sizeof(int), MPI_INFO_NULL, comm, &win); + MPI_Win_get_group(win, &wingroup); + MPI_Comm_group(comm, &group); + MPI_Group_compare(group, wingroup, &result); + if (result != MPI_IDENT) { + errs++; + fprintf(stderr, "Group returned by Win_get_group not the same as the input group\n"); + } + MPI_Group_free(&wingroup); + MPI_Group_free(&group); + MPI_Win_free(&win); MTestFreeComm(&comm); } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/ircpi.c b/teshsuite/smpi/mpich3-test/rma/ircpi.c deleted file mode 100644 index 99a83ed9a4..0000000000 --- a/teshsuite/smpi/mpich3-test/rma/ircpi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ -/* - * (C) 2001 by Argonne National Laboratory. - * See COPYRIGHT in top-level directory. - */ -#include "mpi.h" -#include "stdio.h" -#include - -/* From Using MPI-2 */ - -int main(int argc, char *argv[]) -{ - int n, myid, numprocs, i, ierr; - double PI25DT = 3.141592653589793238462643; - double mypi, pi, h, sum, x; - MPI_Win nwin, piwin; - - MPI_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&numprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&myid); - - if (myid == 0) { - MPI_Win_create(&n, sizeof(int), 1, MPI_INFO_NULL, - MPI_COMM_WORLD, &nwin); - MPI_Win_create(&pi, sizeof(double), 1, MPI_INFO_NULL, - MPI_COMM_WORLD, &piwin); - } - else { - MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL, - MPI_COMM_WORLD, &nwin); - MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL, - MPI_COMM_WORLD, &piwin); - } - while (1) { - if (myid == 0) { - fprintf(stdout, "Enter the number of intervals: (0 quits) "); - fflush(stdout); - ierr=scanf("%d",&n); - pi = 0.0; - } - MPI_Win_fence(0, nwin); - if (myid != 0) - MPI_Get(&n, 1, MPI_INT, 0, 0, 1, MPI_INT, nwin); - MPI_Win_fence(0, nwin); - if (n == 0) - break; - else { - h = 1.0 / (double) n; - sum = 0.0; - for (i = myid + 1; i <= n; i += numprocs) { - x = h * ((double)i - 0.5); - sum += (4.0 / (1.0 + x*x)); - } - mypi = h * sum; - MPI_Win_fence( 0, piwin); - MPI_Accumulate(&mypi, 1, MPI_DOUBLE, 0, 0, 1, MPI_DOUBLE, - MPI_SUM, piwin); - MPI_Win_fence(0, piwin); - if (myid == 0) { - fprintf(stdout, "pi is approximately %.16f, Error is %.16f\n", - pi, fabs(pi - PI25DT)); - fflush(stdout); - } - } - } - MPI_Win_free(&nwin); - MPI_Win_free(&piwin); - MPI_Finalize(); - return 0; -} diff --git a/teshsuite/smpi/mpich3-test/rma/large-acc-flush_local.c b/teshsuite/smpi/mpich3-test/rma/large-acc-flush_local.c new file mode 100644 index 0000000000..fd0a4fa99d --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/large-acc-flush_local.c @@ -0,0 +1,73 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This code tests the case when origin process issues 10 ACC + * operations for each data size to the target process, and each + * operation is followed by a MPI_Win_flush_local. */ + +/* FIXME: we should merge this into a comprehensive test for RMA + * operations + MPI_Win_flush_local. */ + +#include "mpi.h" +#include +#include +#include + +#define MIN_DATA_SIZE (262144) +#define MAX_DATA_SIZE (8 * 262144) +#define OPS_NUM 10 +#define LOOP 500 + +int main(int argc, char *argv[]) +{ + int rank, nproc, i, j; + MPI_Win win; + int *tar_buf = NULL; + int *orig_buf = NULL; + int data_size; + + MPI_Init(&argc, &argv); + + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Alloc_mem(MAX_DATA_SIZE, MPI_INFO_NULL, &orig_buf); + MPI_Alloc_mem(MAX_DATA_SIZE, MPI_INFO_NULL, &tar_buf); + + /* run this test for LOOP times */ + + for (j = 0; j < LOOP; j++) { + + MPI_Win_create(tar_buf, MAX_DATA_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + MPI_Win_lock_all(0, win); + + if (rank != 0) { + for (data_size = MIN_DATA_SIZE; data_size <= MAX_DATA_SIZE; data_size *= 2) { + for (i = 0; i < OPS_NUM; i++) { + MPI_Accumulate(orig_buf, data_size, MPI_BYTE, + 0, 0, data_size, MPI_BYTE, MPI_SUM, win); + MPI_Win_flush_local(0, win); + } + MPI_Win_flush(0, win); + } + } + + MPI_Win_unlock_all(win); + + MPI_Win_free(&win); + } + + if (rank == 0) + printf(" No Errors\n"); + + MPI_Free_mem(orig_buf); + MPI_Free_mem(tar_buf); + + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/large-small-acc.c b/teshsuite/smpi/mpich3-test/rma/large-small-acc.c new file mode 100644 index 0000000000..de5b08f737 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/large-small-acc.c @@ -0,0 +1,88 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +/* This code tests the case when a large ACC is issued, and then + * several small ACCs is issued between the same origin and target. + * The purpose of this test is to check if the ordering of ACCs + * is guaranteed. */ + +#include "mpi.h" +#include +#include + +#define LOOP 5 +#define DATA_COUNT 8192 + +int main(int argc, char *argv[]) +{ + int rank, nprocs; + MPI_Win win; + uint64_t buf[DATA_COUNT], orig_buf[DATA_COUNT]; + uint64_t small_orig_buf_1 = 2, small_orig_buf_2[2] = { 3, 3 }; + int i, j, error = 0; + + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + for (j = 0; j < LOOP; j++) { + + error = 0; + + for (i = 0; i < DATA_COUNT; i++) { + buf[i] = 0; + orig_buf[i] = 1; + } + + MPI_Win_create(buf, sizeof(uint64_t) * DATA_COUNT, sizeof(uint64_t), + MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + MPI_Win_fence(0, win); + + if (rank == 0) { + /* ACC (atomic PUT) to win_buf[0...DATA_COUNT-1] */ + MPI_Accumulate(orig_buf, DATA_COUNT, MPI_UINT64_T, 1, 0, DATA_COUNT, MPI_UINT64_T, + MPI_REPLACE, win); + /* ACC (atomic PUT) to win_buf[0] */ + MPI_Accumulate(&small_orig_buf_1, 1, MPI_UINT64_T, 1, 0, 1, MPI_UINT64_T, MPI_REPLACE, + win); + /* ACC (atomic PUT) to win_buf[1,2] */ + MPI_Accumulate(&small_orig_buf_2, 2, MPI_UINT64_T, 1, 1, 2, MPI_UINT64_T, MPI_REPLACE, + win); + } + + MPI_Win_fence(0, win); + + if (rank == 1) { + for (i = 0; i < DATA_COUNT; i++) { + if (i == 0) { + if (buf[i] != 2) { + error++; + } + } + else if (i == 1 || i == 2) { + if (buf[i] != 3) { + error++; + } + } + else { + if (buf[i] != 1) { + error++; + } + } + } + } + + MPI_Win_free(&win); + } + + if (rank == 1 && error == 0) { + printf(" No Errors\n"); + } + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list.c b/teshsuite/smpi/mpich3-test/rma/linked_list.c index 7b59c904e0..126ab62ca0 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list.c @@ -7,7 +7,7 @@ /* MPI-3 distributed linked list construction example * -------------------------------------------------- - * + * * Construct a distributed shared linked list using proposed MPI-3 dynamic * windows. Initially process 0 creates the head of the list, attaches it to * the window, and broadcasts the pointer to all processes. All processes then @@ -23,7 +23,7 @@ #include #include "mpitest.h" -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -33,7 +33,7 @@ /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,28 +44,30 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; /* List of locally allocated list elements. */ static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; +static int my_elems_size = 0; static int my_elems_count = 0; /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +MPI_Aint alloc_elem(int value, MPI_Win win) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ if (my_elems_size == my_elems_count) { my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + my_elems = realloc(my_elems, my_elems_size * sizeof(void *)); } my_elems[my_elems_count] = elem_ptr; my_elems_count++; @@ -74,10 +76,11 @@ MPI_Aint alloc_elem(int value, MPI_Win win) { return disp; } -int main(int argc, char **argv) { - int procid, nproc, i; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; +int main(int argc, char **argv) +{ + int procid, nproc, i; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; MPI_Init(&argc, &argv); @@ -105,15 +108,16 @@ int main(int argc, char **argv) { new_elem_ptr.disp = alloc_elem(procid, llist_win); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { llist_ptr_t next_tail_ptr = nil; MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win); - MPI_Compare_and_swap((void*) &new_elem_ptr.rank, (void*) &nil.rank, - (void*) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.rank), llist_win); + MPI_Compare_and_swap((void *) &new_elem_ptr.rank, (void *) &nil.rank, + (void *) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.rank), + llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); success = (next_tail_ptr.rank == nil.rank); @@ -124,26 +128,28 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win); MPI_Put(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), 1, MPI_AINT, llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); tail_ptr = new_elem_ptr; /* For implementations that use pt-to-pt messaging, force progress for other threads' - RMA operations. */ + * RMA operations. */ for (i = 0; i < NPROBE; i++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - } else { + } + else { /* Tail pointer is stale, fetch the displacement. May take multiple tries - if it is being updated. */ + * if it is being updated. */ do { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win); - MPI_Get( &next_tail_ptr.disp, 1, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), - 1, MPI_AINT, llist_win); + MPI_Get(&next_tail_ptr.disp, 1, MPI_AINT, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), + 1, MPI_AINT, llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); } while (next_tail_ptr.disp == nil.disp); @@ -155,13 +161,13 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int have_root = 0; - int errors = 0; + int have_root = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -204,14 +210,15 @@ int main(int argc, char **argv) { } if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected = NUM_ELEMS; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -223,8 +230,8 @@ int main(int argc, char **argv) { MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c index 304ac471d0..5e0dfa481e 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c @@ -19,7 +19,7 @@ #include #include "mpitest.h" -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -33,7 +33,7 @@ /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,29 +44,31 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; static const int print_perf = 0; /* List of locally allocated list elements. */ static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; +static int my_elems_size = 0; static int my_elems_count = 0; /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +MPI_Aint alloc_elem(int value, MPI_Win win) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ if (my_elems_size == my_elems_count) { my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + my_elems = realloc(my_elems, my_elems_size * sizeof(void *)); } my_elems[my_elems_count] = elem_ptr; my_elems_count++; @@ -75,12 +77,13 @@ MPI_Aint alloc_elem(int value, MPI_Win win) { return disp; } -int main(int argc, char **argv) { - int procid, nproc, i, j, my_nelem; - int pollint = 0; - double time; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; +int main(int argc, char **argv) +{ + int procid, nproc, i, j, my_nelem; + int pollint = 0; + double time; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; MPI_Init(&argc, &argv); @@ -105,7 +108,7 @@ int main(int argc, char **argv) { else i = 0; - my_nelem = NUM_ELEMS/nproc; + my_nelem = NUM_ELEMS / nproc; if (procid < NUM_ELEMS % nproc) my_nelem++; @@ -115,31 +118,33 @@ int main(int argc, char **argv) { /* Lock the window for shared access to all targets */ MPI_Win_lock_all(0, llist_win); - for ( ; i < my_nelem; i++) { + for (; i < my_nelem; i++) { llist_ptr_t new_elem_ptr; int success = 0; + MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t)); + /* Create a new list element and register it with the window */ new_elem_ptr.rank = procid; new_elem_ptr.disp = alloc_elem(procid, llist_win); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { int flag; /* The tail is at my left neighbor, append my element. */ - if (tail_ptr.rank == (procid + nproc-1) % nproc) - { + if (tail_ptr.rank == (procid + nproc - 1) % nproc) { if (verbose) - printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp); + printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, + (void *) tail_ptr.disp); #if 1 MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), - MPI_BYTE, MPI_REPLACE, llist_win); + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win); #else MPI_Put(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), sizeof(llist_ptr_t), MPI_BYTE, llist_win); #endif MPI_Win_flush(tail_ptr.rank, llist_win); @@ -149,28 +154,29 @@ int main(int argc, char **argv) { } /* Otherwise, chase the tail. */ - else - { + else { llist_ptr_t next_tail_ptr; - MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, - sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), - sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); + MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, + sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); MPI_Win_flush(tail_ptr.rank, llist_win); if (next_tail_ptr.rank != nil.rank) { if (verbose) - printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp); + printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, + (void *) next_tail_ptr.disp); tail_ptr = next_tail_ptr; - pollint = MAX(MIN_NPROBE, pollint/2); + pollint = MAX(MIN_NPROBE, pollint / 2); } else { for (j = 0; j < pollint; j++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - pollint = MIN(MAX_NPROBE, pollint*2); + pollint = MIN(MAX_NPROBE, pollint * 2); } } } while (!success); @@ -181,12 +187,12 @@ int main(int argc, char **argv) { time = MPI_Wtime() - time; /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int errors = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -222,18 +228,19 @@ int main(int argc, char **argv) { MPI_Win_unlock_all(llist_win); if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected; - expected = NUM_ELEMS/nproc; + expected = NUM_ELEMS / nproc; if (i < NUM_ELEMS % nproc) expected++; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -248,15 +255,16 @@ int main(int argc, char **argv) { MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (procid == 0) { - printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6); + printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, + NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6); } } MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_excl.c b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_excl.c index 288be5d0bd..c52208e2ac 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_excl.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_excl.c @@ -19,7 +19,7 @@ #include #include "mpitest.h" -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -33,7 +33,7 @@ /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,29 +44,31 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; static const int print_perf = 0; /* List of locally allocated list elements. */ static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; +static int my_elems_size = 0; static int my_elems_count = 0; /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +MPI_Aint alloc_elem(int value, MPI_Win win) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ if (my_elems_size == my_elems_count) { my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + my_elems = realloc(my_elems, my_elems_size * sizeof(void *)); } my_elems[my_elems_count] = elem_ptr; my_elems_count++; @@ -75,12 +77,13 @@ MPI_Aint alloc_elem(int value, MPI_Win win) { return disp; } -int main(int argc, char **argv) { - int procid, nproc, i, j, my_nelem; - int pollint = 0; - double time; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; +int main(int argc, char **argv) +{ + int procid, nproc, i, j, my_nelem; + int pollint = 0; + double time; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; MPI_Init(&argc, &argv); @@ -104,40 +107,42 @@ int main(int argc, char **argv) { i = 1; else i = 0; - my_nelem = NUM_ELEMS/nproc; + my_nelem = NUM_ELEMS / nproc; if (procid < NUM_ELEMS % nproc) my_nelem++; MPI_Barrier(MPI_COMM_WORLD); time = MPI_Wtime(); - for ( ; i < my_nelem; i++) { + for (; i < my_nelem; i++) { llist_ptr_t new_elem_ptr; int success = 0; + MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t)); + /* Create a new list element and register it with the window */ new_elem_ptr.rank = procid; new_elem_ptr.disp = alloc_elem(procid, llist_win); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { int flag; /* The tail is at my left neighbor, append my element. */ - if (tail_ptr.rank == (procid + nproc-1) % nproc) - { + if (tail_ptr.rank == (procid + nproc - 1) % nproc) { if (verbose) - printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp); + printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, + (void *) tail_ptr.disp); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win); #if USE_ACC MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), - MPI_BYTE, MPI_REPLACE, llist_win); + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win); #else MPI_Put(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), sizeof(llist_ptr_t), MPI_BYTE, llist_win); #endif MPI_Win_unlock(tail_ptr.rank, llist_win); @@ -147,34 +152,35 @@ int main(int argc, char **argv) { } /* Otherwise, chase the tail. */ - else - { + else { llist_ptr_t next_tail_ptr; MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win); #if USE_ACC - MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, - sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), - sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); + MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, + sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); #else MPI_Get(&next_tail_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), sizeof(llist_ptr_t), MPI_BYTE, llist_win); #endif MPI_Win_unlock(tail_ptr.rank, llist_win); if (next_tail_ptr.rank != nil.rank) { if (verbose) - printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp); + printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, + (void *) next_tail_ptr.disp); tail_ptr = next_tail_ptr; - pollint = MAX(MIN_NPROBE, pollint/2); + pollint = MAX(MIN_NPROBE, pollint / 2); } else { for (j = 0; j < pollint; j++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - pollint = MIN(MAX_NPROBE, pollint*2); + pollint = MIN(MAX_NPROBE, pollint * 2); } } } while (!success); @@ -184,12 +190,12 @@ int main(int argc, char **argv) { time = MPI_Wtime() - time; /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int errors = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -225,18 +231,19 @@ int main(int argc, char **argv) { MPI_Win_unlock_all(llist_win); if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected; - expected = NUM_ELEMS/nproc; + expected = NUM_ELEMS / nproc; if (i < NUM_ELEMS % nproc) expected++; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -251,15 +258,16 @@ int main(int argc, char **argv) { MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (procid == 0) { - printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6); + printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, + NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6); } } MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_shr.c b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_shr.c index 662cbc81c5..9577b16387 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_shr.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_shr.c @@ -19,7 +19,7 @@ #include #include "mpitest.h" -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -33,7 +33,7 @@ /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,29 +44,31 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; static const int print_perf = 0; /* List of locally allocated list elements. */ static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; +static int my_elems_size = 0; static int my_elems_count = 0; /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +MPI_Aint alloc_elem(int value, MPI_Win win) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ if (my_elems_size == my_elems_count) { my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + my_elems = realloc(my_elems, my_elems_size * sizeof(void *)); } my_elems[my_elems_count] = elem_ptr; my_elems_count++; @@ -75,12 +77,13 @@ MPI_Aint alloc_elem(int value, MPI_Win win) { return disp; } -int main(int argc, char **argv) { - int procid, nproc, i, j, my_nelem; - int pollint = 0; - double time; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; +int main(int argc, char **argv) +{ + int procid, nproc, i, j, my_nelem; + int pollint = 0; + double time; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; MPI_Init(&argc, &argv); @@ -105,31 +108,33 @@ int main(int argc, char **argv) { else i = 0; - my_nelem = NUM_ELEMS/nproc; + my_nelem = NUM_ELEMS / nproc; if (procid < NUM_ELEMS % nproc) my_nelem++; MPI_Barrier(MPI_COMM_WORLD); time = MPI_Wtime(); - for ( ; i < my_nelem; i++) { + for (; i < my_nelem; i++) { llist_ptr_t new_elem_ptr; int success = 0; + MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t)); + /* Create a new list element and register it with the window */ new_elem_ptr.rank = procid; new_elem_ptr.disp = alloc_elem(procid, llist_win); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { int flag; /* The tail is at my left neighbor, append my element. */ - if (tail_ptr.rank == (procid + nproc-1) % nproc) - { + if (tail_ptr.rank == (procid + nproc - 1) % nproc) { if (verbose) - printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp); + printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, + (void *) tail_ptr.disp); #ifdef USE_MODE_NOCHECK MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win); @@ -137,8 +142,8 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, 0, llist_win); #endif MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), - MPI_BYTE, MPI_REPLACE, llist_win); + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); success = 1; @@ -146,8 +151,7 @@ int main(int argc, char **argv) { } /* Otherwise, chase the tail. */ - else - { + else { llist_ptr_t next_tail_ptr; #ifdef USE_MODE_NOCHECK @@ -155,23 +159,25 @@ int main(int argc, char **argv) { #else MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, 0, llist_win); #endif - MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, - sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), - sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); + MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, + sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); if (next_tail_ptr.rank != nil.rank) { if (verbose) - printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp); + printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, + (void *) next_tail_ptr.disp); tail_ptr = next_tail_ptr; - pollint = MAX(MIN_NPROBE, pollint/2); + pollint = MAX(MIN_NPROBE, pollint / 2); } else { for (j = 0; j < pollint; j++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - pollint = MIN(MAX_NPROBE, pollint*2); + pollint = MIN(MAX_NPROBE, pollint * 2); } } } while (!success); @@ -181,12 +187,12 @@ int main(int argc, char **argv) { time = MPI_Wtime() - time; /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int errors = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -222,18 +228,19 @@ int main(int argc, char **argv) { MPI_Win_unlock_all(llist_win); if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected; - expected = NUM_ELEMS/nproc; + expected = NUM_ELEMS / nproc; if (i < NUM_ELEMS % nproc) expected++; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -248,15 +255,16 @@ int main(int argc, char **argv) { MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (procid == 0) { - printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6); + printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, + NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6); } } MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list_fop.c b/teshsuite/smpi/mpich3-test/rma/linked_list_fop.c index 82a3ec28ea..61b7618487 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list_fop.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list_fop.c @@ -7,7 +7,7 @@ /* MPI-3 distributed linked list construction example * -------------------------------------------------- - * + * * Construct a distributed shared linked list using proposed MPI-3 dynamic * windows. Initially process 0 creates the head of the list, attaches it to * the window, and broadcasts the pointer to all processes. All processes then @@ -23,7 +23,7 @@ #include #include "mpitest.h" -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -33,7 +33,7 @@ /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,28 +44,30 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; /* List of locally allocated list elements. */ static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; +static int my_elems_size = 0; static int my_elems_count = 0; /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +MPI_Aint alloc_elem(int value, MPI_Win win) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ if (my_elems_size == my_elems_count) { my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + my_elems = realloc(my_elems, my_elems_size * sizeof(void *)); } my_elems[my_elems_count] = elem_ptr; my_elems_count++; @@ -74,10 +76,11 @@ MPI_Aint alloc_elem(int value, MPI_Win win) { return disp; } -int main(int argc, char **argv) { - int procid, nproc, i; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; +int main(int argc, char **argv) +{ + int procid, nproc, i; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; MPI_Init(&argc, &argv); @@ -105,15 +108,16 @@ int main(int argc, char **argv) { new_elem_ptr.disp = alloc_elem(procid, llist_win); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { llist_ptr_t next_tail_ptr = nil; MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win); - MPI_Compare_and_swap((void*) &new_elem_ptr.rank, (void*) &nil.rank, - (void*) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.rank), llist_win); + MPI_Compare_and_swap((void *) &new_elem_ptr.rank, (void *) &nil.rank, + (void *) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.rank), + llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); success = (next_tail_ptr.rank == nil.rank); @@ -125,36 +129,36 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win); MPI_Fetch_and_op(&new_elem_ptr.disp, &result, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), - MPI_REPLACE, llist_win); + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), + MPI_REPLACE, llist_win); /* Note: accumulate is faster, since we don't need the result. Replacing with - Fetch_and_op to create a more complete test case. */ + * Fetch_and_op to create a more complete test case. */ /* - MPI_Accumulate(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1, - MPI_AINT, MPI_REPLACE, llist_win); - */ + * MPI_Accumulate(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank, + * (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1, + * MPI_AINT, MPI_REPLACE, llist_win); + */ MPI_Win_unlock(tail_ptr.rank, llist_win); tail_ptr = new_elem_ptr; /* For implementations that use pt-to-pt messaging, force progress for other threads' - RMA operations. */ + * RMA operations. */ for (i = 0; i < NPROBE; i++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - } else { + } + else { /* Tail pointer is stale, fetch the displacement. May take multiple tries - if it is being updated. */ + * if it is being updated. */ do { - MPI_Aint junk = 0; - MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win); MPI_Fetch_and_op(NULL, &next_tail_ptr.disp, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), - MPI_NO_OP, llist_win); + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), + MPI_NO_OP, llist_win); MPI_Win_unlock(tail_ptr.rank, llist_win); } while (next_tail_ptr.disp == nil.disp); @@ -166,13 +170,13 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int have_root = 0; - int errors = 0; + int have_root = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -215,14 +219,15 @@ int main(int argc, char **argv) { } if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected = NUM_ELEMS; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -234,8 +239,8 @@ int main(int argc, char **argv) { MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list_lockall.c b/teshsuite/smpi/mpich3-test/rma/linked_list_lockall.c index 2690692133..699623c6f2 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list_lockall.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list_lockall.c @@ -23,7 +23,7 @@ #include #include "mpitest.h" -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -33,7 +33,7 @@ /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,28 +44,30 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; /* List of locally allocated list elements. */ static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; +static int my_elems_size = 0; static int my_elems_count = 0; /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +MPI_Aint alloc_elem(int value, MPI_Win win) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ if (my_elems_size == my_elems_count) { my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + my_elems = realloc(my_elems, my_elems_size * sizeof(void *)); } my_elems[my_elems_count] = elem_ptr; my_elems_count++; @@ -74,10 +76,11 @@ MPI_Aint alloc_elem(int value, MPI_Win win) { return disp; } -int main(int argc, char **argv) { - int procid, nproc, i; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; +int main(int argc, char **argv) +{ + int procid, nproc, i; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; MPI_Init(&argc, &argv); @@ -108,13 +111,14 @@ int main(int argc, char **argv) { new_elem_ptr.disp = alloc_elem(procid, llist_win); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { llist_ptr_t next_tail_ptr = nil; - MPI_Compare_and_swap((void*) &new_elem_ptr.rank, (void*) &nil.rank, - (void*) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.rank), llist_win); + MPI_Compare_and_swap((void *) &new_elem_ptr.rank, (void *) &nil.rank, + (void *) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.rank), + llist_win); MPI_Win_flush(tail_ptr.rank, llist_win); success = (next_tail_ptr.rank == nil.rank); @@ -123,25 +127,27 @@ int main(int argc, char **argv) { int i, flag; MPI_Accumulate(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), 1, MPI_AINT, MPI_REPLACE, llist_win); MPI_Win_flush(tail_ptr.rank, llist_win); tail_ptr = new_elem_ptr; /* For implementations that use pt-to-pt messaging, force progress for other threads' - RMA operations. */ + * RMA operations. */ for (i = 0; i < NPROBE; i++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - } else { + } + else { /* Tail pointer is stale, fetch the displacement. May take multiple tries - if it is being updated. */ + * if it is being updated. */ do { - MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr.disp, - 1, MPI_AINT, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), - 1, MPI_AINT, MPI_NO_OP, llist_win); + MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr.disp, + 1, MPI_AINT, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), + 1, MPI_AINT, MPI_NO_OP, llist_win); MPI_Win_flush(tail_ptr.rank, llist_win); } while (next_tail_ptr.disp == nil.disp); tail_ptr = next_tail_ptr; @@ -153,13 +159,13 @@ int main(int argc, char **argv) { MPI_Barrier(MPI_COMM_WORLD); /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int have_root = 0; - int errors = 0; + int have_root = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -204,14 +210,15 @@ int main(int argc, char **argv) { MPI_Win_unlock_all(llist_win); if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected = NUM_ELEMS; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -223,8 +230,8 @@ int main(int argc, char **argv) { MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/lock_contention_dt.c b/teshsuite/smpi/mpich3-test/rma/lock_contention_dt.c new file mode 100644 index 0000000000..394f7992e6 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lock_contention_dt.c @@ -0,0 +1,99 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test lock contention while streaming ACC-like operations"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size; + int target = 1; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank != target) { + sendtype.InitBuf(&sendtype); + + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, target, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + MPI_Win_unlock(target, win); + MPI_Barrier(comm); + + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destination to finish checking and reinitializing the buffer */ + MPI_Barrier(comm); + + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win); + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, recvtype.datatype, + target, 0, recvtype.count, recvtype.datatype, MPI_REPLACE, + win); + MPI_Win_unlock(target, win); + MPI_Barrier(comm); + free(resbuf); + } + else { /* Target checks the result */ + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Win_unlock(rank, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Win_unlock(rank, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lock_dt.c b/teshsuite/smpi/mpich3-test/rma/lock_dt.c new file mode 100644 index 0000000000..f98d4f4fba --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lock_dt.c @@ -0,0 +1,101 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size, source, dest; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + /* Make sure that everyone has a recv buffer */ + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + sendtype.InitBuf(&sendtype); + + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + MPI_Win_unlock(dest, win); + MPI_Barrier(comm); + + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destination to finish checking and reinitializing the buffer */ + MPI_Barrier(comm); + + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, recvtype.datatype, + dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE, + win); + MPI_Win_unlock(dest, win); + MPI_Barrier(comm); + free(resbuf); + } + else if (rank == dest) { + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Win_unlock(dest, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Win_unlock(dest, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lock_dt_flush.c b/teshsuite/smpi/mpich3-test/rma/lock_dt_flush.c new file mode 100644 index 0000000000..336da0494f --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lock_dt_flush.c @@ -0,0 +1,110 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock+flush"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int err = 0; + int rank, size, source, dest; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + sendtype.InitBuf(&sendtype); + + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + MPI_Win_flush(dest, win); + /*signal to dest that the ops are flushed so that it starts checking the result */ + MPI_Barrier(comm); + /*make sure dest finishes checking the result before issuing unlock */ + MPI_Barrier(comm); + MPI_Win_unlock(dest, win); + + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destination to finish checking and reinitializing the buffer */ + MPI_Barrier(comm); + + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, recvtype.datatype, + dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE, + win); + MPI_Win_flush(dest, win); + /*signal to dest that the ops are flushed so that it starts checking the result */ + MPI_Barrier(comm); + /*make sure dest finishes checking the result before issuing unlock */ + MPI_Barrier(comm); + MPI_Win_unlock(dest, win); + free(resbuf); + } + else if (rank == dest) { + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Barrier(comm); + MPI_Win_unlock(dest, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Barrier(comm); + MPI_Win_unlock(dest, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lock_dt_flushlocal.c b/teshsuite/smpi/mpich3-test/rma/lock_dt_flushlocal.c new file mode 100644 index 0000000000..fe6db8ad3b --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lock_dt_flushlocal.c @@ -0,0 +1,111 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock+flush_local"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int err = 0; + int rank, size, source, dest; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + MPI_Aint slb, sextent; + MPI_Type_get_extent(sendtype.datatype, &slb, &sextent); + sendtype.InitBuf(&sendtype); + + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + MPI_Win_flush_local(dest, win); + /* reset the send buffer to test local completion */ + memset(sendtype.buf, 0, slb + sextent * sendtype.count); + MPI_Win_unlock(dest, win); + MPI_Barrier(comm); + + sendtype.InitBuf(&sendtype); + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destination to finish checking and reinitializing the buffer */ + MPI_Barrier(comm); + + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, recvtype.datatype, + dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE, + win); + MPI_Win_flush_local(dest, win); + /* reset the send buffer to test local completion */ + memset(sendtype.buf, 0, slb + sextent * sendtype.count); + MPI_Win_unlock(dest, win); + MPI_Barrier(comm); + free(resbuf); + } + else if (rank == dest) { + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Win_unlock(dest, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Win_unlock(dest, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lock_nested.c b/teshsuite/smpi/mpich3-test/rma/lock_nested.c new file mode 100644 index 0000000000..58d03fa76f --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lock_nested.c @@ -0,0 +1,52 @@ +/* -*- Mode: C; c-basic-offset:4 ; -*- */ +/* + * (C) 2016 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +#include +#include +#include +#include + +#define BUFSIZE 4 + +/* This program tests nested lock. Process 0 locks the other processes + * one by one, then unlock each of them.*/ + +int main(int argc, char *argv[]) +{ + int rank = 0, nprocs = 0, dst = 0; + int winbuf[BUFSIZE]; + MPI_Win win = MPI_WIN_NULL; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + + memset(winbuf, 0, sizeof(int) * BUFSIZE); + MPI_Win_create(winbuf, sizeof(int) * BUFSIZE, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + if (rank == 0) { + /* lock each process */ + for (dst = 0; dst < nprocs; dst++) { + MPI_Win_lock(MPI_LOCK_SHARED, dst, 0, win); + } + + /* unlock each process */ + for (dst = nprocs - 1; dst >= 0; dst--) { + MPI_Win_unlock(dst, win); + } + } + + MPI_Barrier(MPI_COMM_WORLD); + MPI_Win_free(&win); + + if (rank == 0) { + fprintf(stdout, " No Errors\n"); + fflush(stdout); + } + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt.c new file mode 100644 index 0000000000..bdb7e97128 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lockall_dt.c @@ -0,0 +1,107 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + int source = 0; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + int dest; + sendtype.InitBuf(&sendtype); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + } + MPI_Win_unlock_all(win); + MPI_Barrier(comm); + + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destinations to finish checking and reinitializing the buffers */ + MPI_Barrier(comm); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, + recvtype.datatype, dest, 0, recvtype.count, + recvtype.datatype, MPI_REPLACE, win); + + } + MPI_Win_unlock_all(win); + MPI_Barrier(comm); + free(resbuf); + } + else { + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Win_unlock(rank, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Win_unlock(rank, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flush.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flush.c new file mode 100644 index 0000000000..f6ddde3cf2 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flush.c @@ -0,0 +1,117 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + int source = 0; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + int dest; + sendtype.InitBuf(&sendtype); + + MPI_Win_lock_all(0, win); + + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + MPI_Win_flush(dest, win); + } + /*signal to dest that the ops are flushed so that it starts checking the result */ + MPI_Barrier(comm); + /*make sure dest finishes checking the result before issuing unlock */ + MPI_Barrier(comm); + MPI_Win_unlock_all(win); + + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destinations to finish checking and reinitializing the buffers */ + MPI_Barrier(comm); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, + recvtype.datatype, dest, 0, recvtype.count, + recvtype.datatype, MPI_REPLACE, win); + MPI_Win_flush(dest, win); + } + /*signal to dest that the ops are flushed so that it starts checking the result */ + MPI_Barrier(comm); + /*make sure dest finishes checking the result before issuing unlock */ + MPI_Barrier(comm); + MPI_Win_unlock_all(win); + free(resbuf); + } + else { + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Barrier(comm); + MPI_Win_unlock(rank, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Barrier(comm); + MPI_Win_unlock(rank, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushall.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushall.c new file mode 100644 index 0000000000..9fdf416c58 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushall.c @@ -0,0 +1,118 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_all"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + int source = 0; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + int dest; + sendtype.InitBuf(&sendtype); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + } + + MPI_Win_flush_all(win); + /*signal to dest that the ops are flushed so that it starts checking the result */ + MPI_Barrier(comm); + /*make sure dest finishes checking the result before issuing unlock */ + MPI_Barrier(comm); + MPI_Win_unlock_all(win); + + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destination to finish checking and reinitializing the buffer */ + MPI_Barrier(comm); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, + recvtype.datatype, dest, 0, recvtype.count, + recvtype.datatype, MPI_REPLACE, win); + + } + MPI_Win_flush_all(win); + /*signal to dest that the ops are flushed so that it starts checking the result */ + MPI_Barrier(comm); + /*make sure dest finishes checking the result before issuing unlock */ + MPI_Barrier(comm); + MPI_Win_unlock_all(win); + free(resbuf); + } + else { + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Barrier(comm); + MPI_Win_unlock(rank, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Barrier(comm); + MPI_Win_unlock(rank, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocal.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocal.c new file mode 100644 index 0000000000..a3726b6491 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocal.c @@ -0,0 +1,117 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_local"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + int source = 0; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + int dest; + MPI_Aint slb, sextent; + MPI_Type_get_extent(sendtype.datatype, &slb, &sextent); + sendtype.InitBuf(&sendtype); + + MPI_Win_lock_all(0, win); + + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + MPI_Win_flush_local(dest, win); + } + /* reset the send buffer to test local completion */ + memset(sendtype.buf, 0, slb + sextent * sendtype.count); + MPI_Win_unlock_all(win); + MPI_Barrier(comm); + + sendtype.InitBuf(&sendtype); + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destinations to finish checking and reinitializing the buffers */ + MPI_Barrier(comm); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, + recvtype.datatype, dest, 0, recvtype.count, + recvtype.datatype, MPI_REPLACE, win); + MPI_Win_flush_local(dest, win); + } + /* reset the send buffer to test local completion */ + memset(sendtype.buf, 0, slb + sextent * sendtype.count); + MPI_Win_unlock_all(win); + MPI_Barrier(comm); + free(resbuf); + } + else { + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Win_unlock(rank, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Win_unlock(rank, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocalall.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocalall.c new file mode 100644 index 0000000000..9d662fa98b --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocalall.c @@ -0,0 +1,118 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2015 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include "mpi.h" +#include +#include +#include +#include "mpitest.h" + +/* +static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_local_all"; +*/ + +int main(int argc, char *argv[]) +{ + int errs = 0; + int rank, size; + int minsize = 2, count; + MPI_Comm comm; + MPI_Win win; + MPI_Aint lb, extent; + MTestDatatype sendtype, recvtype; + + MTest_Init(&argc, &argv); + + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + int source = 0; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + recvtype.printErrors = 1; + recvtype.InitBuf(&recvtype); + MPI_Type_get_extent(recvtype.datatype, &lb, &extent); + + MPI_Win_create(recvtype.buf, lb + recvtype.count * extent, + (int) extent, MPI_INFO_NULL, comm, &win); + if (rank == source) { + int dest; + MPI_Aint slb, sextent; + MPI_Type_get_extent(sendtype.datatype, &slb, &sextent); + sendtype.InitBuf(&sendtype); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, dest, 0, + recvtype.count, recvtype.datatype, MPI_REPLACE, win); + } + + MPI_Win_flush_local_all(win); + /* reset the send buffer to test local completion */ + memset(sendtype.buf, 0, slb + sextent * sendtype.count); + MPI_Win_unlock_all(win); + MPI_Barrier(comm); + + sendtype.InitBuf(&sendtype); + char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char)); + + /*wait for the destination to finish checking and reinitializing the buffer */ + MPI_Barrier(comm); + + MPI_Win_lock_all(0, win); + for (dest = 0; dest < size; dest++) + if (dest != source) { + MPI_Get_accumulate(sendtype.buf, sendtype.count, + sendtype.datatype, resbuf, recvtype.count, + recvtype.datatype, dest, 0, recvtype.count, + recvtype.datatype, MPI_REPLACE, win); + + } + MPI_Win_flush_local_all(win); + /* reset the send buffer to test local completion */ + memset(sendtype.buf, 0, slb + sextent * sendtype.count); + MPI_Win_unlock_all(win); + MPI_Barrier(comm); + free(resbuf); + } + else { + int err; + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + recvtype.InitBuf(&recvtype); + MPI_Win_unlock(rank, win); + + /*signal the source that checking and reinitialization is done */ + MPI_Barrier(comm); + + MPI_Barrier(comm); + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + err = MTestCheckRecv(0, &recvtype); + if (err) + errs++; + MPI_Win_unlock(rank, win); + } + + MPI_Win_free(&win); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } + MTestFreeComm(&comm); + } + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/lockcontention.c b/teshsuite/smpi/mpich3-test/rma/lockcontention.c index 8fbce4ba70..81651194c1 100644 --- a/teshsuite/smpi/mpich3-test/rma/lockcontention.c +++ b/teshsuite/smpi/mpich3-test/rma/lockcontention.c @@ -25,9 +25,9 @@ int main(int argc, char *argv[]) int errs = 0; int trank = 1; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 3) { fprintf(stderr, "Run this program with 3 or more processes\n"); @@ -38,54 +38,54 @@ int main(int argc, char *argv[]) if (rank < 3) { if (rank == 0) { - for (i=0; i= wsize) { - next = 0; - if (next == partner) next++; + next = 0; + if (next == partner) + next++; } /* Determine the last test to run (by default, run them all) */ - for (i=1; i +#include +#include +#include "mpitest.h" + +#define BUFSIZE (32*1024) + +int main(int argc, char *argv[]) +{ + int i, rank, size; + int *buf; + MPI_Win win; + + MPI_Init(&argc, &argv); + + buf = malloc(BUFSIZE); + MTEST_VG_MEM_INIT(buf, BUFSIZE); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (size != 2) { + printf("test must be run with 2 processes!\n"); + MPI_Abort(MPI_COMM_WORLD, 1); + } + + if (rank == 0) + MPI_Win_create(buf, BUFSIZE, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); + else + MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + MPI_Win_fence(0, win); + + if (rank == 1) { + for (i = 0; i < 1000; i++) + MPI_Get(buf, BUFSIZE / sizeof(int), MPI_INT, 0, 0, BUFSIZE / sizeof(int), MPI_INT, win); + } + + MPI_Win_fence(0, win); + MPI_Win_free(&win); + + if (rank == 0) + printf(" No Errors\n"); + + free(buf); + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/manyrma2.c b/teshsuite/smpi/mpich3-test/rma/manyrma2.c index 571d29e950..67739199a0 100644 --- a/teshsuite/smpi/mpich3-test/rma/manyrma2.c +++ b/teshsuite/smpi/mpich3-test/rma/manyrma2.c @@ -17,7 +17,7 @@ #define MAX_COUNT 65536*4/16 #define MAX_RMA_SIZE 2 /* 16 in manyrma performance test */ -#define MAX_RUNS 10 +#define MAX_RUNS 8 #define MAX_ITER_TIME 5.0 /* seconds */ typedef enum { SYNC_NONE = 0, @@ -112,6 +112,14 @@ int main(int argc, char *argv[]) MPI_Group_free(&wgroup); arraysize = maxSz * MAX_COUNT; +#ifdef USE_WIN_ALLOCATE + MPI_Win_allocate(arraysize * sizeof(int), (int) sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &arraybuffer, &win); + if (!arraybuffer) { + fprintf(stderr, "Unable to allocate %d words\n", arraysize); + MPI_Abort(MPI_COMM_WORLD, 1); + } +#else arraybuffer = (int *) malloc(arraysize * sizeof(int)); if (!arraybuffer) { fprintf(stderr, "Unable to allocate %d words\n", arraysize); @@ -120,6 +128,7 @@ int main(int argc, char *argv[]) MPI_Win_create(arraybuffer, arraysize * sizeof(int), (int) sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); +#endif if (maxCount > MAX_COUNT) { fprintf(stderr, "MaxCount must not exceed %d\n", MAX_COUNT); @@ -212,6 +221,10 @@ int main(int argc, char *argv[]) MPI_Win_free(&win); +#ifndef USE_WIN_ALLOCATE + free(arraybuffer); +#endif + MPI_Group_free(&accessGroup); MPI_Group_free(&exposureGroup); diff --git a/teshsuite/smpi/mpich3-test/rma/mcs-mutex.c b/teshsuite/smpi/mpich3-test/rma/mcs-mutex.c index 52a3bbf310..a972a55c44 100644 --- a/teshsuite/smpi/mpich3-test/rma/mcs-mutex.c +++ b/teshsuite/smpi/mpich3-test/rma/mcs-mutex.c @@ -39,7 +39,7 @@ int MCS_Mutex_create(int tail_rank, MPI_Comm comm, MCS_Mutex * hdl_out) hdl->tail_rank = tail_rank; #ifdef USE_WIN_SHARED - MPI_Win_allocate_shared(2*sizeof(int), sizeof(int), MPI_INFO_NULL, + MPI_Win_allocate_shared(2 * sizeof(int), sizeof(int), MPI_INFO_NULL, hdl->comm, &hdl->base, &hdl->window); #else #ifdef USE_WIN_ALLOC_SHM @@ -49,7 +49,7 @@ int MCS_Mutex_create(int tail_rank, MPI_Comm comm, MCS_Mutex * hdl_out) MPI_Info_create(&hdl->win_info); MPI_Info_set(hdl->win_info, "alloc_shm", "false"); #endif - MPI_Win_allocate(2*sizeof(int), sizeof(int), hdl->win_info, hdl->comm, + MPI_Win_allocate(2 * sizeof(int), sizeof(int), hdl->win_info, hdl->comm, &hdl->base, &hdl->window); #endif @@ -119,7 +119,8 @@ int MCS_Mutex_lock(MCS_Mutex hdl) /* Wait for notification */ MPI_Status status; - MPI_Accumulate(&rank, 1, MPI_INT, prev, MCS_MTX_ELEM_DISP, 1, MPI_INT, MPI_REPLACE, hdl->window); + MPI_Accumulate(&rank, 1, MPI_INT, prev, MCS_MTX_ELEM_DISP, 1, MPI_INT, MPI_REPLACE, + hdl->window); MPI_Win_flush(prev, hdl->window); debug_print("%2d: LOCK - waiting for notification from %d\n", rank, prev); @@ -181,11 +182,10 @@ int MCS_Mutex_unlock(MCS_Mutex hdl) /* Read my next pointer. FOP is used since another process may write to * this location concurrent with this read. */ - MPI_Fetch_and_op(NULL, &next, MPI_INT, rank, MCS_MTX_ELEM_DISP, MPI_NO_OP, - hdl->window); + MPI_Fetch_and_op(NULL, &next, MPI_INT, rank, MCS_MTX_ELEM_DISP, MPI_NO_OP, hdl->window); MPI_Win_flush(rank, hdl->window); - if ( next == MPI_PROC_NULL) { + if (next == MPI_PROC_NULL) { int tail; int nil = MPI_PROC_NULL; @@ -206,10 +206,10 @@ int MCS_Mutex_unlock(MCS_Mutex hdl) MPI_NO_OP, hdl->window); MPI_Win_flush(rank, hdl->window); - if (next != MPI_PROC_NULL) break; + if (next != MPI_PROC_NULL) + break; - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, - MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); } } } diff --git a/teshsuite/smpi/mpich3-test/rma/mixedsync.c b/teshsuite/smpi/mpich3-test/rma/mixedsync.c index c558516c9d..0bf63c3c5b 100644 --- a/teshsuite/smpi/mpich3-test/rma/mixedsync.c +++ b/teshsuite/smpi/mpich3-test/rma/mixedsync.c @@ -14,24 +14,24 @@ static char MTEST_Descrip[] = "Mix synchronization types"; */ -void delay( double time ); -void delay( double time ) +void delay(double time); +void delay(double time) { double t1; t1 = MPI_Wtime(); - while (MPI_Wtime() - t1 < time) ; + while (MPI_Wtime() - t1 < time); } -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { - int errs = 0; - int crank, csize, source, dest, loop; - int *buf0, *buf1, *buf2, *inbuf2, count0, count1, count2, count, i; + int errs = 0; + int crank, csize, source, dest, loop; + int *buf0, *buf1, *buf2, *inbuf2, count0, count1, count2, count, i; MPI_Comm comm; - MPI_Win win; - int *winbuf; + MPI_Win win; + int *winbuf; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); comm = MPI_COMM_WORLD; @@ -40,205 +40,189 @@ int main( int argc, char *argv[] ) count2 = 100; count = count0 + count1 + count2 + 2; - + /* Allocate and initialize the local buffers */ - buf0 = (int *)malloc( count0 * sizeof(int) ); - buf1 = (int *)malloc( count1 * sizeof(int) ); - buf2 = (int *)malloc( count2 * sizeof(int) ); - inbuf2 = (int *)malloc( count2 * sizeof(int) ); + buf0 = (int *) malloc(count0 * sizeof(int)); + buf1 = (int *) malloc(count1 * sizeof(int)); + buf2 = (int *) malloc(count2 * sizeof(int)); + inbuf2 = (int *) malloc(count2 * sizeof(int)); if (!buf0 || !buf1 || !buf2 || !inbuf2) { - fprintf( stderr, "Unable to allocated buf0-2\n" ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated buf0-2\n"); + MPI_Abort(MPI_COMM_WORLD, 1); } - for (i=0; i - * - * All processes create a mutex then lock+unlock it N times. - */ - #include #include #include @@ -24,60 +19,64 @@ const int verbose = 0; double delay_ctr = 0.0; -int main(int argc, char ** argv) { - int rank, nproc, i; - double t_mpix_mtx, t_mcs_mtx; - MPI_Comm mtx_comm; - MCS_Mutex mcs_mtx; +int main(int argc, char **argv) +{ + int rank, nproc, i; + double t_mcs_mtx; + MPI_Comm mtx_comm; + MCS_Mutex mcs_mtx; - MPI_Init(&argc, &argv); + MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); #ifdef USE_WIN_SHARED - MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, - MPI_INFO_NULL, &mtx_comm); + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &mtx_comm); #else - mtx_comm = MPI_COMM_WORLD; + mtx_comm = MPI_COMM_WORLD; #endif - MCS_Mutex_create(0, mtx_comm, &mcs_mtx); + MCS_Mutex_create(0, mtx_comm, &mcs_mtx); - MPI_Barrier(MPI_COMM_WORLD); - t_mcs_mtx = MPI_Wtime(); + MPI_Barrier(MPI_COMM_WORLD); + t_mcs_mtx = MPI_Wtime(); - for (i = 0; i < NUM_ITER; i++) { - /* Combining trylock and lock here is helpful for testing because it makes - * CAS and Fetch-and-op contend for the tail pointer. */ - if (rank % 2) { - int success = 0; - while (!success) { - MCS_Mutex_trylock(mcs_mtx, &success); - } - } - else { - MCS_Mutex_lock(mcs_mtx); + for (i = 0; i < NUM_ITER; i++) { + /* Combining trylock and lock here is helpful for testing because it makes + * CAS and Fetch-and-op contend for the tail pointer. */ +#ifdef USE_CONTIGUOUS_RANK + if (rank < nproc / 2) { +#else + if (rank % 2) { +#endif + int success = 0; + while (!success) { + MCS_Mutex_trylock(mcs_mtx, &success); + } + } + else { + MCS_Mutex_lock(mcs_mtx); + } + MCS_Mutex_unlock(mcs_mtx); } - MCS_Mutex_unlock(mcs_mtx); - } - MPI_Barrier(MPI_COMM_WORLD); - t_mcs_mtx = MPI_Wtime() - t_mcs_mtx; + MPI_Barrier(MPI_COMM_WORLD); + t_mcs_mtx = MPI_Wtime() - t_mcs_mtx; - MCS_Mutex_free(&mcs_mtx); + MCS_Mutex_free(&mcs_mtx); - if (rank == 0) { - if (verbose) { - printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx/NUM_ITER*1.0e6); - } - } + if (rank == 0) { + if (verbose) { + printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx / NUM_ITER * 1.0e6); + } + } - if (mtx_comm != MPI_COMM_WORLD) - MPI_Comm_free(&mtx_comm); + if (mtx_comm != MPI_COMM_WORLD) + MPI_Comm_free(&mtx_comm); - MTest_Finalize(0); - MPI_Finalize(); + MTest_Finalize(0); + MPI_Finalize(); - return 0; + return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/nb_test.c b/teshsuite/smpi/mpich3-test/rma/nb_test.c new file mode 100644 index 0000000000..5cebc68c1b --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/nb_test.c @@ -0,0 +1,42 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * (C) 2001 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + MPI_Win win; + int flag, tmp, rank; + int base[1024], errs = 0; + MPI_Request req; + + MTest_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Win_create(base, 1024 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + if (rank == 0) { + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Win_unlock(0, win); + } + else { + MPI_Barrier(MPI_COMM_WORLD); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win); + MPI_Rput(&tmp, 1, MPI_INT, 0, 0, 1, MPI_INT, win, &req); + MPI_Test(&req, &flag, MPI_STATUS_IGNORE); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Win_unlock(0, win); + } + + MPI_Win_free(&win); + + MTest_Finalize(errs); + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/nullpscw.c b/teshsuite/smpi/mpich3-test/rma/nullpscw.c index c5b134257f..fa870004b3 100644 --- a/teshsuite/smpi/mpich3-test/rma/nullpscw.c +++ b/teshsuite/smpi/mpich3-test/rma/nullpscw.c @@ -7,28 +7,33 @@ #include #include "mpitest.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - MPI_Win win; - MPI_Group group; - int errs = 0; - - MTest_Init(&argc,&argv); - - MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); - MPI_Win_get_group(win, &group); - - MPI_Win_post(group, 0, win); - MPI_Win_start(group, 0, win); - - MPI_Win_complete(win); - - MPI_Win_wait(win); - - MPI_Group_free( &group ); - MPI_Win_free(&win); - - MTest_Finalize(errs); - MPI_Finalize(); - return 0; + MPI_Win win; + MPI_Group group; + int errs = 0; + + MTest_Init(&argc, &argv); + +#ifdef USE_WIN_ALLOCATE + char *baseptr; + MPI_Win_allocate(0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &baseptr, &win); +#else + MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); +#endif + MPI_Win_get_group(win, &group); + + MPI_Win_post(group, 0, win); + MPI_Win_start(group, 0, win); + + MPI_Win_complete(win); + + MPI_Win_wait(win); + + MPI_Group_free(&group); + MPI_Win_free(&win); + + MTest_Finalize(errs); + MPI_Finalize(); + return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/overlap_wins_rma.c b/teshsuite/smpi/mpich3-test/rma/overlap_wins_rma.c new file mode 100644 index 0000000000..9ccdeef116 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/overlap_wins_rma.c @@ -0,0 +1,304 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2016 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +#include +#include +#include +#include + +/* This test checks the remote completion of flush with RMA write-like operations + * (PUT, ACC, GET_ACC, FOP, CAS) concurrently issued from different origin processes + * to the same target over overlapping windows (i.e., two windows exposing the same + * memory region) + * 1. The first [nprocs-1] processes perform as origin, and the last process + * performs as target. + * 2. Everyone allocates a buffer and creates [nprocs-1] windows over the same buffer. + * 3. Every origin P[i] issues RMA operations and flush to target through + * wins[i] respectively, to different location winbuf[i] on target. + * 4. Finally, every origin P[i] issues GET and flush to obtain winbuf[i] on + * target and checks the correctness. */ + +#define ITER 10 +#define BUF_CNT 2 + +#if defined(TEST_CAS) +#define MPI_DATATYPE MPI_INT +#define DATATYPE int +#define DATATYPE_FORMAT "%d" +#else +#define MPI_DATATYPE MPI_DOUBLE +#define DATATYPE double +#define DATATYPE_FORMAT "%.1f" +#endif + +DATATYPE local_buf[BUF_CNT], result_buf[BUF_CNT], compare_buf[BUF_CNT]; +DATATYPE exp_target_val = 0.0; + +const int verbose = 0; + +int rank = -1, nprocs = 0; +int norigins, target; +MPI_Win *wins; +int win_size = 0, win_cnt = 0; + +DATATYPE *winbuf = NULL, *my_base = NULL; + +#define verbose_print(str,...) { \ + if (verbose) { \ + fprintf(stdout, str, ## __VA_ARGS__); \ + fflush(stdout); \ + } \ + } +#define error_print(str,...) { \ + fprintf(stderr, str, ## __VA_ARGS__); \ + fflush(stderr); \ + } + +/* Define operation name for error message */ +#ifdef TEST_PUT +const char *rma_name = "Put"; +#elif defined(TEST_ACC) +const char *rma_name = "Accumulate"; +#elif defined(TEST_GACC) +const char *rma_name = "Get_accumulate"; +#elif defined(TEST_FOP) +const char *rma_name = "Fetch_and_op"; +#elif defined(TEST_CAS) +const char *rma_name = "Compare_and_swap"; +#else +const char *rma_name = "None"; +#endif + +/* Issue functions for different RMA operations */ +#ifdef TEST_PUT +static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr /* NULL */ , + DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp, + MPI_Win win) +{ + MPI_Put(origin_addr, 1, MPI_DATATYPE, dst, target_disp, 1, MPI_DATATYPE, win); +} +#elif defined(TEST_ACC) +static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr /* NULL */ , + DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp, + MPI_Win win) +{ + MPI_Accumulate(origin_addr, 1, MPI_DATATYPE, dst, target_disp, 1, MPI_DATATYPE, MPI_SUM, win); +} +#elif defined(TEST_GACC) +static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr, + DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp, + MPI_Win win) +{ + MPI_Get_accumulate(origin_addr, 1, MPI_DATATYPE, result_addr, 1, MPI_DATATYPE, dst, target_disp, + 1, MPI_DATATYPE, MPI_SUM, win); +} +#elif defined(TEST_FOP) +static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr, + DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp, + MPI_Win win) +{ + MPI_Fetch_and_op(origin_addr, result_addr, MPI_DATATYPE, dst, target_disp, MPI_SUM, win); +} +#elif defined(TEST_CAS) +static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr, + DATATYPE * compare_addr, int dst, MPI_Aint target_disp, MPI_Win win) +{ + MPI_Compare_and_swap(origin_addr, compare_addr, result_addr, MPI_DATATYPE, dst, target_disp, + win); +} +#else +#define issue_rma_op(loc_addr, result_addr, compare_addr, dst, target_disp, win) +#endif + +static inline void set_iteration_data(int x) +{ + int i; + +#if defined(TEST_CAS) + for (i = 0; i < BUF_CNT; i++) + compare_buf[i] = local_buf[i]; /* always equal, thus swap happens */ +#endif + + for (i = 0; i < BUF_CNT; i++) { + local_buf[i] = rank + i + x; + +#if defined(TEST_CAS) || defined(TEST_PUT) + exp_target_val = local_buf[i]; /* swap */ +#else + exp_target_val += local_buf[i]; /* sum */ +#endif + } +} + +static void print_origin_data(void) +{ + int i; + + printf("[%d] local_buf: ", rank); + for (i = 0; i < BUF_CNT; i++) + printf(DATATYPE_FORMAT " ", local_buf[i]); + printf("\n"); + + printf("[%d] result_buf: ", rank); + for (i = 0; i < BUF_CNT; i++) + printf(DATATYPE_FORMAT " ", result_buf[i]); + printf("\n"); +} + +static void print_target_data(void) +{ + int i; + printf("[%d] winbuf: ", rank); + for (i = 0; i < win_cnt; i++) + printf(DATATYPE_FORMAT " ", winbuf[i]); + printf("\n"); + fflush(stdout); +} + +static int run_test() +{ + int errors = 0; + int i, x; + int dst = 0, target_disp = 0; + MPI_Win win = MPI_WIN_NULL; + DATATYPE target_val = 0.0; + + /* 1. Specify working window and displacement. + * - Target: no RMA issued, always check results on wins[0]. + * - Origins: issue RMA on different window and different memory location */ + if (rank == target) { + win = wins[0]; + } + else { + win = wins[rank]; + target_disp = rank; + } + dst = target; + + /* 2. Every one resets local data */ + memset(local_buf, 0, sizeof(local_buf)); + memset(result_buf, 0, sizeof(result_buf)); + memset(compare_buf, 0, sizeof(compare_buf)); + + MPI_Barrier(MPI_COMM_WORLD); + + if (rank != target) { + + /* 3. Origins issue RMA to target over its working window */ + MPI_Win_lock(MPI_LOCK_SHARED, dst, 0, win); + verbose_print("[%d] RMA start, test %s (dst=%d, target_disp=%d, win 0x%x) - flush\n", + rank, rma_name, dst, target_disp, win); + + for (x = 0; x < ITER; x++) { + /* update local buffers and expected value in every iteration */ + set_iteration_data(x); + + for (i = 0; i < BUF_CNT; i++) + issue_rma_op(&local_buf[i], &result_buf[i], &compare_buf[i], dst, target_disp, win); + MPI_Win_flush(dst, win); + + if (verbose) + print_origin_data(); + } + + /* 4. Check correctness of final target value */ + MPI_Get(&target_val, 1, MPI_DATATYPE, dst, target_disp, 1, MPI_DATATYPE, win); + MPI_Win_flush(dst, win); + if (target_val != exp_target_val) { + error_print("rank %d (iter %d) - check %s, got target_val = " + DATATYPE_FORMAT ", expected " DATATYPE_FORMAT "\n", rank, x, + rma_name, target_val, exp_target_val); + errors++; + } + + MPI_Win_unlock(dst, win); + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* 5. Every one prints window buffer */ + if (verbose && rank == target) { + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); + print_target_data(); + MPI_Win_unlock(rank, win); + } + + return errors; +} + +static void init_windows(void) +{ + int i = 0; + + /* Everyone creates norigins overlapping windows. */ + winbuf = malloc(win_size); + memset(winbuf, 0, win_size); + + wins = malloc(norigins * sizeof(MPI_Win)); + for (i = 0; i < norigins; i++) { + wins[i] = MPI_WIN_NULL; + MPI_Win_create(winbuf, win_size, sizeof(DATATYPE), MPI_INFO_NULL, MPI_COMM_WORLD, &wins[i]); + } +} + +static void destroy_windows(void) +{ + int i = 0; + for (i = 0; i < norigins; i++) { + if (wins[i] != MPI_WIN_NULL) + MPI_Win_free(&wins[i]); + } + free(wins); + free(winbuf); +} + +int main(int argc, char *argv[]) +{ + int errors = 0, all_errors = 0; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + + if (nprocs < 3) { + if (rank == 0) { + error_print("Error: must use at least 3 processes\n"); + } + MPI_Barrier(MPI_COMM_WORLD); + MPI_Abort(MPI_COMM_WORLD, 1); + } + + /* The last rank performs as target, all others are origin. + * Every origin accesses to a different memory location on the target. */ + target = nprocs - 1; + norigins = nprocs - 1; + win_cnt = nprocs - 1; + win_size = sizeof(DATATYPE) * win_cnt; + + if (rank == 0) { + verbose_print("[%d] %d origins, target rank = %d\n", rank, norigins, target); + } + + init_windows(); + MPI_Barrier(MPI_COMM_WORLD); + + /* start test */ + errors = run_test(); + + MPI_Barrier(MPI_COMM_WORLD); + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + if (rank == 0 && all_errors == 0) { + fprintf(stdout, " No Errors\n"); + fflush(stdout); + } + + destroy_windows(); + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/pscw_ordering.c b/teshsuite/smpi/mpich3-test/rma/pscw_ordering.c index 9cb1cee0e2..5df4126da1 100644 --- a/teshsuite/smpi/mpich3-test/rma/pscw_ordering.c +++ b/teshsuite/smpi/mpich3-test/rma/pscw_ordering.c @@ -18,7 +18,8 @@ #include "mpitest.h" #include "squelch.h" -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, rank, nproc, errors = 0; int *win_buf; @@ -42,16 +43,16 @@ int main(int argc, char **argv) { /* Set up odd/even groups and buffers */ odd_nproc = nproc / 2; - even_nproc = nproc / 2 + ( (nproc % 2 == 0) ? 0 : 1 ); + even_nproc = nproc / 2 + ((nproc % 2 == 0) ? 0 : 1); odd_ranks = malloc(sizeof(int) * odd_nproc); even_ranks = malloc(sizeof(int) * even_nproc); for (i = 0; i < even_nproc; i++) - even_ranks[i] = i*2; + even_ranks[i] = i * 2; for (i = 0; i < odd_nproc; i++) - odd_ranks[i] = i*2+1; + odd_ranks[i] = i * 2 + 1; MPI_Comm_group(MPI_COMM_WORLD, &world_group); MPI_Group_incl(world_group, odd_nproc, odd_ranks, &odd_group); @@ -59,27 +60,31 @@ int main(int argc, char **argv) { /* Create the window */ - MPI_Alloc_mem(nproc*sizeof(int), MPI_INFO_NULL, &win_buf); - +#ifdef USE_WIN_ALLOCATE + MPI_Win_allocate(nproc * sizeof(int), sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &win_buf, &win); +#else + MPI_Alloc_mem(nproc * sizeof(int), MPI_INFO_NULL, &win_buf); + MPI_Win_create(win_buf, nproc * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); +#endif + MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win); for (i = 0; i < nproc; i++) win_buf[i] = -1; - - MPI_Win_create(win_buf, nproc*sizeof(int), sizeof(int), MPI_INFO_NULL, - MPI_COMM_WORLD, &win); + MPI_Win_unlock(rank, win); /* Perform PSCW communication: Odd/even matchup */ if (rank % 2 == 0) { - MPI_Win_start(odd_group, 0, win); /* Even-numbered procs target odd procs */ - MPI_Win_post(odd_group, 0, win); /* Even procs are targeted by odd procs */ + MPI_Win_start(odd_group, 0, win); /* Even-numbered procs target odd procs */ + MPI_Win_post(odd_group, 0, win); /* Even procs are targeted by odd procs */ /* Write to my slot at each target */ for (i = 0; i < odd_nproc; i++) MPI_Put(&rank, 1, MPI_INT, odd_ranks[i], rank, 1, MPI_INT, win); } else { - MPI_Win_post(even_group, 0, win); /* Odd procs are targeted by even procs */ - MPI_Win_start(even_group, 0, win); /* Odd-numbered procs target even procs */ + MPI_Win_post(even_group, 0, win); /* Odd procs are targeted by even procs */ + MPI_Win_start(even_group, 0, win); /* Odd-numbered procs target even procs */ /* Write to my slot at each target */ for (i = 0; i < even_nproc; i++) @@ -93,16 +98,16 @@ int main(int argc, char **argv) { /* Perform PSCW communication: Odd/odd and even/even matchup */ if (rank % 2 == 0) { - MPI_Win_post(even_group, 0, win); /* Even procs are targeted by even procs */ - MPI_Win_start(even_group, 0, win); /* Even-numbered procs target even procs */ + MPI_Win_post(even_group, 0, win); /* Even procs are targeted by even procs */ + MPI_Win_start(even_group, 0, win); /* Even-numbered procs target even procs */ /* Write to my slot at each target */ for (i = 0; i < even_nproc; i++) MPI_Put(&rank, 1, MPI_INT, even_ranks[i], rank, 1, MPI_INT, win); } else { - MPI_Win_post(odd_group, 0, win); /* Odd procs are targeted by odd procs */ - MPI_Win_start(odd_group, 0, win); /* Odd-numbered procs target odd procs */ + MPI_Win_post(odd_group, 0, win); /* Odd procs are targeted by odd procs */ + MPI_Win_start(odd_group, 0, win); /* Odd-numbered procs target odd procs */ /* Write to my slot at each target */ for (i = 0; i < odd_nproc; i++) @@ -117,14 +122,15 @@ int main(int argc, char **argv) { if (win_buf[i] != i) { errors++; - SQUELCH( printf("%d: Error -- win_buf[%d] = %d, expected %d\n", - rank, i, win_buf[i], i); - ); + SQUELCH(printf("%d: Error -- win_buf[%d] = %d, expected %d\n", rank, i, win_buf[i], i); +); } } MPI_Win_free(&win); +#ifndef USE_WIN_ALLOCATE MPI_Free_mem(win_buf); +#endif MPI_Group_free(&world_group); MPI_Group_free(&odd_group); @@ -133,7 +139,7 @@ int main(int argc, char **argv) { free(odd_ranks); free(even_ranks); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/put_base.c b/teshsuite/smpi/mpich3-test/rma/put_base.c index ba95a1cfc9..1c5c3d5ab8 100644 --- a/teshsuite/smpi/mpich3-test/rma/put_base.c +++ b/teshsuite/smpi/mpich3-test/rma/put_base.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Put Test * - * Author: James Dinan + * Author: James Dinan * Date : March, 2011 * * This code performs N strided put operations into a 2d patch of a shared @@ -32,9 +32,10 @@ #define SUB_YDIM 1024 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; - double *win_buf, *src_buf, *dst_buf; + double *win_buf, *src_buf, *dst_buf; MPI_Win buf_win; MTest_Init(&argc, &argv); @@ -44,52 +45,53 @@ int main(int argc, char **argv) { bufsize = XDIM * YDIM * sizeof(double); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf); - /* Alloc_mem is not required for the origin buffers for RMA operations - - just for the Win_create memory */ + /* Alloc_mem is not required for the origin buffers for RMA operations - + * just for the Win_create memory */ MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf); - for (i = 0; i < XDIM*YDIM; i++) { - *(win_buf + i) = 1.0 + rank; + for (i = 0; i < XDIM * YDIM; i++) { + *(win_buf + i) = 1.0 + rank; *(src_buf + i) = 1.0 + rank; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided put operations */ for (i = 0; i < ITERATIONS; i++) { - MPI_Aint idx_loc[SUB_YDIM]; - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; + MPI_Aint idx_loc[SUB_YDIM]; + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; - void *base_ptr = dst_buf; - MPI_Aint base_int; + void *base_ptr = dst_buf; + MPI_Aint base_int; - MPI_Get_address(base_ptr, &base_int); + MPI_Get_address(base_ptr, &base_int); - for (j = 0; j < SUB_YDIM; j++) { - MPI_Get_address(&src_buf[j*XDIM], &idx_loc[j]); - idx_loc[j] = idx_loc[j] - base_int; - idx_rem[j] = j*XDIM*sizeof(double); - blk_len[j] = SUB_XDIM*sizeof(double); - } + for (j = 0; j < SUB_YDIM; j++) { + MPI_Get_address(&src_buf[j * XDIM], &idx_loc[j]); + idx_loc[j] = idx_loc[j] - base_int; + idx_rem[j] = j * XDIM * sizeof(double); + blk_len[j] = SUB_XDIM * sizeof(double); + } - MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type); - MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM*sizeof(double), idx_rem, MPI_BYTE, &dst_type); + MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type); + MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM * sizeof(double), idx_rem, MPI_BYTE, + &dst_type); - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Put(base_ptr, 1, src_type, peer, 0, 1, dst_type, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Put(base_ptr, 1, src_type, peer, 0, 1, dst_type, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -99,40 +101,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = (1.0 + ((rank+nranks-1)%nranks)); - if (actual - expected > 1e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = (1.0 + ((rank + nranks - 1) % nranks)); + if (actual - expected > 1e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = 1.0 + rank; - if (actual - expected > 1e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = 1.0 + rank; + if (actual - expected > 1e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = 1.0 + rank; - if (actual - expected > 1e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = 1.0 + rank; + if (actual - expected > 1e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -141,7 +143,7 @@ int main(int argc, char **argv) { MPI_Free_mem(src_buf); MPI_Free_mem(dst_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/put_bottom.c b/teshsuite/smpi/mpich3-test/rma/put_bottom.c index 6634ea08b7..7d67bfd888 100644 --- a/teshsuite/smpi/mpich3-test/rma/put_bottom.c +++ b/teshsuite/smpi/mpich3-test/rma/put_bottom.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Put Test * - * Author: James Dinan + * Author: James Dinan * Date : March, 2011 * * This code performs N strided put operations into a 2d patch of a shared @@ -30,7 +30,8 @@ #define SUB_YDIM 1024 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; double *win_buf, *src_buf, *dst_buf; MPI_Win buf_win; @@ -45,41 +46,42 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf); - for (i = 0; i < XDIM*YDIM; i++) { - *(win_buf + i) = 1.0 + rank; + for (i = 0; i < XDIM * YDIM; i++) { + *(win_buf + i) = 1.0 + rank; *(src_buf + i) = 1.0 + rank; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided put operations */ for (i = 0; i < ITERATIONS; i++) { - MPI_Aint idx_loc[SUB_YDIM]; - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; - - for (j = 0; j < SUB_YDIM; j++) { - MPI_Get_address(&src_buf[j*XDIM], &idx_loc[j]); - idx_rem[j] = j*XDIM*sizeof(double); - blk_len[j] = SUB_XDIM*sizeof(double); - } + MPI_Aint idx_loc[SUB_YDIM]; + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; + + for (j = 0; j < SUB_YDIM; j++) { + MPI_Get_address(&src_buf[j * XDIM], &idx_loc[j]); + idx_rem[j] = j * XDIM * sizeof(double); + blk_len[j] = SUB_XDIM * sizeof(double); + } - MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type); - MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM*sizeof(double), idx_rem, MPI_BYTE, &dst_type); + MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type); + MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM * sizeof(double), idx_rem, MPI_BYTE, + &dst_type); - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Put(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Put(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -89,40 +91,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = (1.0 + ((rank+nranks-1)%nranks)); - if (actual - expected > 1e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = (1.0 + ((rank + nranks - 1) % nranks)); + if (actual - expected > 1e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = 1.0 + rank; - if (actual - expected > 1e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = 1.0 + rank; + if (actual - expected > 1e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = 1.0 + rank; - if (actual - expected > 1e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = 1.0 + rank; + if (actual - expected > 1e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -131,7 +133,7 @@ int main(int argc, char **argv) { MPI_Free_mem(src_buf); MPI_Free_mem(dst_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/mpich3-test/rma/putfence1.c b/teshsuite/smpi/mpich3-test/rma/putfence1.c index 1020063b6a..4f49bea9ff 100644 --- a/teshsuite/smpi/mpich3-test/rma/putfence1.c +++ b/teshsuite/smpi/mpich3-test/rma/putfence1.c @@ -6,104 +6,137 @@ */ #include "mpi.h" #include +#include #include "mpitest.h" +/* These counts allow reasonable sizes for the large tests */ +#define LARGE_CNT_CONTIG 5500000 +#define LARGE_CNT_NONCONTIG 1500000 + /* static char MTEST_Descrip[] = "Put with Fence"; */ -int main( int argc, char *argv[] ) +static inline int test(MPI_Comm comm, int rank, int source, int dest, + MTestDatatype * sendtype, MTestDatatype * recvtype) { int errs = 0, err; + MPI_Aint extent, lb; + MPI_Win win; + + MTestPrintfMsg(1, + "Putting count = %ld of sendtype %s - count = %ld receive type %s\n", + sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count, + MTestGetDatatypeName(recvtype)); + + /* Make sure that everyone has a recv buffer */ + recvtype->InitBuf(recvtype); + MPI_Type_extent(recvtype->datatype, &extent); + MPI_Type_lb(recvtype->datatype, &lb); + MPI_Win_create(recvtype->buf, recvtype->count * extent + lb, extent, MPI_INFO_NULL, comm, &win); + MPI_Win_fence(0, win); + if (rank == source) { + /* To improve reporting of problems about operations, we + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); + + sendtype->InitBuf(sendtype); + + err = MPI_Put(sendtype->buf, sendtype->count, + sendtype->datatype, dest, 0, recvtype->count, recvtype->datatype, win); + if (err) { + errs++; + if (errs < 10) { + MTestPrintError(err); + } + } + err = MPI_Win_fence(0, win); + if (err) { + errs++; + if (errs < 10) { + MTestPrintError(err); + } + } + } + else if (rank == dest) { + MPI_Win_fence(0, win); + /* This should have the same effect, in terms of + * transfering data, as a send/recv pair */ + err = MTestCheckRecv(0, recvtype); + if (err) { + if (errs < 10) { + printf + ("Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", + MTestGetDatatypeName(recvtype), MTestGetDatatypeName(sendtype)); + /* Redo the test, with the errors printed */ + recvtype->printErrors = 1; + (void) MTestCheckRecv(0, recvtype); + } + errs += err; + } + } + else { + MPI_Win_fence(0, win); + } + MPI_Win_free(&win); + + return errs; +} + + +int main(int argc, char *argv[]) +{ + int errs = 0; int rank, size, source, dest; - int minsize = 2, count; - MPI_Comm comm; - MPI_Win win; - MPI_Aint extent; + int minsize = 2, count; + MPI_Comm comm; MTestDatatype sendtype, recvtype; - MTest_Init( &argc, &argv ); - - /* The following illustrates the use of the routines to - run through a selection of communicators and datatypes. - Use subsets of these for tests that do not involve combinations - of communicators, datatypes, and counts of datatypes */ - while (MTestGetIntracommGeneral( &comm, minsize, 1 )) { - if (comm == MPI_COMM_NULL) continue; - /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); - source = 0; - dest = size - 1; - - for (count = 1; count < 65000; count = count * 2) { - while (MTestGetDatatypes( &sendtype, &recvtype, count )) { - - MTestPrintfMsg( 1, - "Putting count = %d of sendtype %s receive type %s\n", - count, MTestGetDatatypeName( &sendtype ), - MTestGetDatatypeName( &recvtype ) ); - - /* Make sure that everyone has a recv buffer */ - recvtype.InitBuf( &recvtype ); - - MPI_Type_extent( recvtype.datatype, &extent ); - MPI_Win_create( recvtype.buf, recvtype.count * extent, - extent, MPI_INFO_NULL, comm, &win ); - MPI_Win_fence( 0, win ); - if (rank == source) { - /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); - - sendtype.InitBuf( &sendtype ); - - err = MPI_Put( sendtype.buf, sendtype.count, - sendtype.datatype, dest, 0, - recvtype.count, recvtype.datatype, win ); - if (err) { - errs++; - if (errs < 10) { - MTestPrintError( err ); - } - } - err = MPI_Win_fence( 0, win ); - if (err) { - errs++; - if (errs < 10) { - MTestPrintError( err ); - } - } - } - else if (rank == dest) { - MPI_Win_fence( 0, win ); - /* This should have the same effect, in terms of - transfering data, as a send/recv pair */ - err = MTestCheckRecv( 0, &recvtype ); - if (err) { - if (errs < 10) { - printf( "Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", - MTestGetDatatypeName( &recvtype ), - MTestGetDatatypeName( &sendtype ) ); - /* Redo the test, with the errors printed */ - recvtype.printErrors = 1; - (void)MTestCheckRecv( 0, &recvtype ); - } - errs += err; - } - } - else { - MPI_Win_fence( 0, win ); - } - MPI_Win_free( &win ); - MTestFreeDatatype( &sendtype ); - MTestFreeDatatype( &recvtype ); - } - } + MTest_Init(&argc, &argv); + /* The following illustrates the use of the routines to + * run through a selection of communicators and datatypes. + * Use subsets of these for tests that do not involve combinations + * of communicators, datatypes, and counts of datatypes */ + while (MTestGetIntracommGeneral(&comm, minsize, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + source = 0; + dest = size - 1; + + MTEST_DATATYPE_FOR_EACH_COUNT(count) { + while (MTestGetDatatypes(&sendtype, &recvtype, count)) { + errs += test(comm, rank, source, dest, &sendtype, &recvtype); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + } MTestFreeComm(&comm); } - MTest_Finalize( errs ); + /* Part #2: simple large size test - contiguous and noncontiguous */ + if (sizeof(void *) > 4) { /* Only if > 32-bit architecture */ + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + source = 0; + dest = size - 1; + + MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG); + errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype); + + do { + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_NONCONTIG); + } while (strstr(MTestGetDatatypeName(&sendtype), "vector") == NULL); + errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype); + MTestFreeDatatype(&sendtype); + MTestFreeDatatype(&recvtype); + } + + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/putfidx.c b/teshsuite/smpi/mpich3-test/rma/putfidx.c index 6a23eb2d7e..8064d4adf5 100644 --- a/teshsuite/smpi/mpich3-test/rma/putfidx.c +++ b/teshsuite/smpi/mpich3-test/rma/putfidx.c @@ -15,111 +15,108 @@ static char MTEST_Descrip[] = "Put with Fence for an indexed datatype"; */ -int CheckMPIErr( int err ); +int CheckMPIErr(int err); -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { - int errs = 0, err; - int i, rank, size, source, dest; - int blksize, totsize; - int *recvBuf = 0, *srcBuf = 0; - MPI_Comm comm; - MPI_Win win; - MPI_Aint extent; - MPI_Datatype originType; - int counts[2]; - int displs[2]; - - MTest_Init( &argc, &argv ); + int errs = 0, err; + int i, rank, size, source, dest; + int blksize, totsize; + int *recvBuf = 0, *srcBuf = 0; + MPI_Comm comm; + MPI_Win win; + MPI_Aint extent; + MPI_Datatype originType; + int counts[2]; + int displs[2]; + + MTest_Init(&argc, &argv); /* Select the communicator and datatypes */ comm = MPI_COMM_WORLD; /* Create the datatype */ - /* One MPI Implementation fails this test with sufficiently large - values of blksize - it appears to convert this type to an - incorrect contiguous move */ + /* One MPI Implementation fails this test with sufficiently large + * values of blksize - it appears to convert this type to an + * incorrect contiguous move */ blksize = 2048; counts[0] = blksize; counts[1] = blksize; displs[0] = 0; displs[1] = blksize + 1; - MPI_Type_indexed( 2, counts, displs, MPI_INT, &originType ); - MPI_Type_commit( &originType ); + MPI_Type_indexed(2, counts, displs, MPI_INT, &originType); + MPI_Type_commit(&originType); totsize = 2 * blksize; /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); source = 0; - dest = size - 1; - - recvBuf = (int *) malloc( totsize * sizeof(int) ); - srcBuf = (int *) malloc( (totsize + 1) * sizeof(int) ) ; - + dest = size - 1; + + recvBuf = (int *) malloc(totsize * sizeof(int)); + srcBuf = (int *) malloc((totsize + 1) * sizeof(int)); + if (!recvBuf || !srcBuf) { - fprintf( stderr, "Could not allocate buffers\n" ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Could not allocate buffers\n"); + MPI_Abort(MPI_COMM_WORLD, 1); } - + /* Initialize the send and recv buffers */ - for (i=0; i +#include +#include +#include "mpitest.h" + +#define ITER 100 +#define MAX_SIZE 65536 + +int main(int argc, char *argv[]) +{ + int rank, nproc, i; + int errors = 0, all_errors = 0; + int *buf = NULL, *winbuf = NULL; + MPI_Win window; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + if (nproc < 2) { + if (rank == 0) + printf("Error: must be run with two or more processes\n"); + MPI_Abort(MPI_COMM_WORLD, 1); + } + + MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &buf); + MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &winbuf); + MPI_Win_create(winbuf, MAX_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &window); + + MPI_Win_lock_all(0, window); + + /* Test Raccumulate local completion with small data. + * Small data is always copied to header packet as immediate data. */ + if (rank == 1) { + for (i = 0; i < ITER; i++) { + MPI_Request acc_req; + int val = -1; + + buf[0] = rank * i; + MPI_Raccumulate(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_MAX, window, &acc_req); + MPI_Wait(&acc_req, MPI_STATUS_IGNORE); + + /* reset local buffer to check local completion */ + buf[0] = 0; + MPI_Win_flush(0, window); + + MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window); + MPI_Win_flush(0, window); + + if (val != rank * i) { + printf("%d - Got %d in small Raccumulate test, expected %d (%d * %d)\n", rank, val, + rank * i, rank, i); + errors++; + } + } + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* Test Raccumulate local completion with large data . + * Large data is not suitable for 1-copy optimization, and always sent out + * from user buffer. */ + if (rank == 1) { + for (i = 0; i < ITER; i++) { + MPI_Request acc_req; + int val0 = -1, val1 = -1, val2 = -1; + int j; + + /* initialize data */ + for (j = 0; j < MAX_SIZE; j++) { + buf[j] = rank + j + i; + } + + MPI_Raccumulate(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, MPI_REPLACE, window, + &acc_req); + MPI_Wait(&acc_req, MPI_STATUS_IGNORE); + + /* reset local buffer to check local completion */ + buf[0] = 0; + buf[MAX_SIZE - 1] = 0; + buf[MAX_SIZE / 2] = 0; + MPI_Win_flush(0, window); + + /* get remote values which are modified in local buffer after wait */ + MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window); + MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window); + MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window); + MPI_Win_flush(0, window); + + if (val0 != rank + i) { + printf("%d - Got %d in large Raccumulate test, expected %d\n", rank, + val0, rank + i); + errors++; + } + if (val1 != rank + MAX_SIZE - 1 + i) { + printf("%d - Got %d in large Raccumulate test, expected %d\n", rank, + val1, rank + MAX_SIZE - 1 + i); + errors++; + } + if (val2 != rank + MAX_SIZE / 2 + i) { + printf("%d - Got %d in large Raccumulate test, expected %d\n", rank, + val2, rank + MAX_SIZE / 2 + i); + errors++; + } + } + } + + MPI_Win_unlock_all(window); + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_free(&window); + if (buf) + MPI_Free_mem(buf); + if (winbuf) + MPI_Free_mem(winbuf); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/req_example.c b/teshsuite/smpi/mpich3-test/rma/req_example.c index 5788972d3e..38549fd3a6 100644 --- a/teshsuite/smpi/mpich3-test/rma/req_example.c +++ b/teshsuite/smpi/mpich3-test/rma/req_example.c @@ -26,14 +26,15 @@ * function. */ double junk = 0.0; -void compute(int step, double *data) { +void compute(int step, double *data) +{ int i; for (i = 0; i < N; i++) junk += data[i] * (double) step; } -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int i, rank, nproc; int errors = 0, all_errors = 0; @@ -41,7 +42,7 @@ int main( int argc, char *argv[] ) MPI_Request put_req[M] = { MPI_REQUEST_NULL }; MPI_Request get_req; double *baseptr; - double data[M][N]; /* M buffers of length N */ + double data[M][N]; /* M buffers of length N */ MPI_Info win_info; MPI_Init(&argc, &argv); @@ -58,29 +59,28 @@ int main( int argc, char *argv[] ) MPI_Info_set(win_info, "alloc_shm", "false"); #endif - MPI_Win_allocate(NSTEPS*N*sizeof(double), sizeof(double), win_info, + MPI_Win_allocate(NSTEPS * N * sizeof(double), sizeof(double), win_info, MPI_COMM_WORLD, &baseptr, &win); MPI_Win_lock_all(0, win); for (i = 0; i < NSTEPS; i++) { - int target = (rank+1) % nproc; + int target = (rank + 1) % nproc; int j; /* Find a free put request */ if (i < M) { j = i; - } else { + } + else { MPI_Waitany(M, put_req, &j, MPI_STATUS_IGNORE); } - MPI_Rget(data[j], N, MPI_DOUBLE, target, i*N, N, MPI_DOUBLE, win, - &get_req); - MPI_Wait(&get_req,MPI_STATUS_IGNORE); + MPI_Rget(data[j], N, MPI_DOUBLE, target, i * N, N, MPI_DOUBLE, win, &get_req); + MPI_Wait(&get_req, MPI_STATUS_IGNORE); compute(i, data[j]); - MPI_Rput(data[j], N, MPI_DOUBLE, target, i*N, N, MPI_DOUBLE, win, - &put_req[j]); + MPI_Rput(data[j], N, MPI_DOUBLE, target, i * N, N, MPI_DOUBLE, win, &put_req[j]); } diff --git a/teshsuite/smpi/mpich3-test/rma/reqops.c b/teshsuite/smpi/mpich3-test/rma/reqops.c index ef2636fb99..c24af56b51 100644 --- a/teshsuite/smpi/mpich3-test/rma/reqops.c +++ b/teshsuite/smpi/mpich3-test/rma/reqops.c @@ -11,7 +11,7 @@ #define ITER 100 -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int rank, nproc, i; int errors = 0, all_errors = 0; @@ -23,19 +23,22 @@ int main( int argc, char *argv[] ) MPI_Comm_size(MPI_COMM_WORLD, &nproc); if (nproc < 2) { - if (rank == 0) printf("Error: must be run with two or more processes\n"); + if (rank == 0) + printf("Error: must be run with two or more processes\n"); MPI_Abort(MPI_COMM_WORLD, 1); } /** Create using MPI_Win_create() **/ if (rank == 0) { - MPI_Alloc_mem(4*sizeof(int), MPI_INFO_NULL, &buf); - *buf = nproc-1; - } else - buf = NULL; + MPI_Alloc_mem(4 * sizeof(int), MPI_INFO_NULL, &buf); + *buf = nproc - 1; + } + else + buf = NULL; - MPI_Win_create(buf, 4*sizeof(int)*(rank == 0), 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window); + MPI_Win_create(buf, 4 * sizeof(int) * (rank == 0), sizeof(int), + MPI_INFO_NULL, MPI_COMM_WORLD, &window); /* PROC_NULL Communication */ { @@ -44,10 +47,12 @@ int main( int argc, char *argv[] ) MPI_Win_lock_all(0, window); - MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, MPI_PROC_NULL, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]); + MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, MPI_PROC_NULL, 0, 1, MPI_INT, + MPI_REPLACE, window, &pn_req[0]); MPI_Rget(&val[1], 1, MPI_INT, MPI_PROC_NULL, 1, 1, MPI_INT, window, &pn_req[1]); MPI_Rput(&val[2], 1, MPI_INT, MPI_PROC_NULL, 2, 1, MPI_INT, window, &pn_req[2]); - MPI_Raccumulate(&val[3], 1, MPI_INT, MPI_PROC_NULL, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]); + MPI_Raccumulate(&val[3], 1, MPI_INT, MPI_PROC_NULL, 3, 1, MPI_INT, MPI_REPLACE, window, + &pn_req[3]); assert(pn_req[0] != MPI_REQUEST_NULL); assert(pn_req[1] != MPI_REQUEST_NULL); @@ -72,22 +77,23 @@ int main( int argc, char *argv[] ) * to the right. Each process, in turn, performs third-party * communication via process 0's window. */ if (rank > 0) { - MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } - MPI_Rget_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window, &gacc_req); + MPI_Rget_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, + window, &gacc_req); assert(gacc_req != MPI_REQUEST_NULL); MPI_Wait(&gacc_req, MPI_STATUS_IGNORE); - exp = (rank + nproc-1) % nproc; + exp = (rank + nproc - 1) % nproc; if (val != exp) { printf("%d - Got %d, expected %d\n", rank, val, exp); errors++; } - if (rank < nproc-1) { - MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD); + if (rank < nproc - 1) { + MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); @@ -95,7 +101,8 @@ int main( int argc, char *argv[] ) MPI_Barrier(MPI_COMM_WORLD); - if (rank == 0) *buf = nproc-1; + if (rank == 0) + *buf = nproc - 1; MPI_Win_sync(window); /* GET+PUT: Test third-party communication, through rank 0. */ @@ -107,26 +114,26 @@ int main( int argc, char *argv[] ) * to the right. Each process, in turn, performs third-party * communication via process 0's window. */ if (rank > 0) { - MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } MPI_Rget(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window, &req); assert(req != MPI_REQUEST_NULL); MPI_Wait(&req, MPI_STATUS_IGNORE); - MPI_Rput(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, window, &req); - assert(req != MPI_REQUEST_NULL); - MPI_Wait(&req, MPI_STATUS_IGNORE); + /* Use flush to guarantee remote completion */ + MPI_Put(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, window); + MPI_Win_flush(0, window); - exp = (rank + nproc-1) % nproc; + exp = (rank + nproc - 1) % nproc; if (val != exp) { printf("%d - Got %d, expected %d\n", rank, val, exp); errors++; } - if (rank < nproc-1) { - MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD); + if (rank < nproc - 1) { + MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); @@ -134,7 +141,8 @@ int main( int argc, char *argv[] ) MPI_Barrier(MPI_COMM_WORLD); - if (rank == 0) *buf = nproc-1; + if (rank == 0) + *buf = nproc - 1; MPI_Win_sync(window); /* GET+ACC: Test third-party communication, through rank 0. */ @@ -146,26 +154,26 @@ int main( int argc, char *argv[] ) * to the right. Each process, in turn, performs third-party * communication via process 0's window. */ if (rank > 0) { - MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } MPI_Rget(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window, &req); assert(req != MPI_REQUEST_NULL); MPI_Wait(&req, MPI_STATUS_IGNORE); - MPI_Raccumulate(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window, &req); - assert(req != MPI_REQUEST_NULL); - MPI_Wait(&req, MPI_STATUS_IGNORE); + /* Use flush to guarantee remote completion */ + MPI_Accumulate(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window); + MPI_Win_flush(0, window); - exp = (rank + nproc-1) % nproc; + exp = (rank + nproc - 1) % nproc; if (val != exp) { printf("%d - Got %d, expected %d\n", rank, val, exp); errors++; } - if (rank < nproc-1) { - MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD); + if (rank < nproc - 1) { + MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); @@ -182,10 +190,12 @@ int main( int argc, char *argv[] ) MPI_Win_lock_all(0, window); - MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]); + MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, + MPI_REPLACE, window, &pn_req[0]); MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]); MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]); - MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]); + MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, + &pn_req[3]); assert(pn_req[0] != MPI_REQUEST_NULL); assert(pn_req[1] != MPI_REQUEST_NULL); @@ -207,10 +217,12 @@ int main( int argc, char *argv[] ) MPI_Win_lock_all(0, window); - MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]); + MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, + MPI_REPLACE, window, &pn_req[0]); MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]); MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]); - MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]); + MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, + &pn_req[3]); assert(pn_req[0] != MPI_REQUEST_NULL); assert(pn_req[1] != MPI_REQUEST_NULL); @@ -230,10 +242,12 @@ int main( int argc, char *argv[] ) MPI_Win_lock_all(0, window); - MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]); + MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, + MPI_REPLACE, window, &pn_req[0]); MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]); MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]); - MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]); + MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, + &pn_req[3]); assert(pn_req[0] != MPI_REQUEST_NULL); assert(pn_req[1] != MPI_REQUEST_NULL); @@ -255,10 +269,12 @@ int main( int argc, char *argv[] ) MPI_Win_lock_all(0, window); - MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]); + MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, + MPI_REPLACE, window, &pn_req[0]); MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]); MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]); - MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]); + MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, + &pn_req[3]); assert(pn_req[0] != MPI_REQUEST_NULL); assert(pn_req[1] != MPI_REQUEST_NULL); @@ -273,7 +289,8 @@ int main( int argc, char *argv[] ) } MPI_Win_free(&window); - if (buf) MPI_Free_mem(buf); + if (buf) + MPI_Free_mem(buf); MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); diff --git a/teshsuite/smpi/mpich3-test/rma/rget-unlock.c b/teshsuite/smpi/mpich3-test/rma/rget-unlock.c new file mode 100644 index 0000000000..4c854df66a --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/rget-unlock.c @@ -0,0 +1,87 @@ +/* + * (C) 2016 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + * + * Portions of this code were written by Intel Corporation. + * Copyright (C) 2011-2016 Intel Corporation. Intel provides this material + * to Argonne National Laboratory subject to Software Grant and Corporate + * Contributor License Agreement dated February 8, 2012. + * + * + * This is a test case to make sure synchronization in unlock works correctly. + * + * Essentially this program does the following: + * + * lock_all + * req=rget(buf) + * unlock_all + * re-use buf + * wait(req) + * + * This program is valid but if unlock_all does not implement the synchronization + * semantics correctly reusing the buffer would race with outstanding rgets. + * + */ + +#include +#include +#include +#include + +#define N_ELMS (128) +#define BLOCKSIZE (1) +#define N_BLOCKS (N_ELMS/BLOCKSIZE) + +int main(int argc, char *argv[]) +{ + MPI_Win win; + int i; + int *rbuf, *lbuf; + int rank, size, trg; + MPI_Request *reqs; + int n_errors = 0; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + trg = (rank + 1) % size; + + rbuf = malloc(sizeof(int) * N_ELMS); + for (i = 0; i < N_ELMS; i++) + rbuf[i] = rank; + + lbuf = malloc(sizeof(int) * N_ELMS); + memset(lbuf, -1, sizeof(int) * N_ELMS); + + reqs = malloc(sizeof(MPI_Request) * N_BLOCKS); + + MPI_Win_create(rbuf, sizeof(int) * N_ELMS, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); + MPI_Win_lock_all(MPI_MODE_NOCHECK, win); + for (i = 0; i < N_BLOCKS; i++) + MPI_Rget(lbuf+i*BLOCKSIZE, BLOCKSIZE, MPI_INT, trg, i*BLOCKSIZE, BLOCKSIZE, MPI_INT, win, &reqs[i]); + MPI_Win_unlock_all(win); + for (i = 0; i < N_ELMS; i++) + lbuf[i] = -2; + + MPI_Waitall(N_BLOCKS, reqs, MPI_STATUSES_IGNORE); + for (i = 0; i < N_ELMS; i++) { + int v = lbuf[i]; + if (v != -2) { + printf("lbuf[%d]=%d, expected -2\n", i, v); + n_errors++; + } + } + MPI_Win_free(&win); + + free(reqs); + free(lbuf); + free(rbuf); + + if (rank == 0 && n_errors == 0) + printf(" No Errors\n"); + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/rmanull.c b/teshsuite/smpi/mpich3-test/rma/rmanull.c index cb228f3747..70d092ad14 100644 --- a/teshsuite/smpi/mpich3-test/rma/rmanull.c +++ b/teshsuite/smpi/mpich3-test/rma/rmanull.c @@ -16,14 +16,14 @@ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "PROC_NULL to " op_name_, err ); \ + MTestPrintErrorMsg("PROC_NULL to " op_name_, err); \ } \ } \ - err = MPI_Win_fence( 0, win ); \ + err = MPI_Win_fence(0, win); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Fence after " op_name_, err ); \ + MTestPrintErrorMsg("Fence after " op_name_, err); \ } \ } \ } while (0) @@ -36,21 +36,21 @@ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Lock before" op_name_, err ); \ + MTestPrintErrorMsg("Lock before" op_name_, err); \ } \ } \ err = fcn_call_ \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "PROC_NULL to " op_name_, err ); \ + MTestPrintErrorMsg("PROC_NULL to " op_name_, err); \ } \ } \ - err = MPI_Win_unlock( MPI_PROC_NULL, win ); \ + err = MPI_Win_unlock(MPI_PROC_NULL, win); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Unlock after " op_name_, err ); \ + MTestPrintErrorMsg("Unlock after " op_name_, err); \ } \ } \ } while (0) @@ -63,28 +63,28 @@ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Lock before" op_name_, err ); \ + MTestPrintErrorMsg("Lock before" op_name_, err); \ } \ } \ err = fcn_call_ \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "PROC_NULL to " op_name_, err ); \ + MTestPrintErrorMsg("PROC_NULL to " op_name_, err); \ } \ } \ - err = MPI_Win_unlock( MPI_PROC_NULL, win ); \ + err = MPI_Win_unlock(MPI_PROC_NULL, win); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Unlock after " op_name_, err ); \ + MTestPrintErrorMsg("Unlock after " op_name_, err); \ } \ } \ - err = MPI_Wait( &req_, MPI_STATUS_IGNORE ); \ + err = MPI_Wait(&req_, MPI_STATUS_IGNORE); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Wait after " op_name_, err ); \ + MTestPrintErrorMsg("Wait after " op_name_, err); \ } \ } \ } while (0) @@ -93,139 +93,127 @@ static char MTEST_Descrip[] = "Test the MPI_PROC_NULL is a valid target"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { - int errs = 0, err; - int rank, size; - int *buf, bufsize; - int *result; - int *rmabuf, rsize, rcount; - MPI_Comm comm; - MPI_Win win; - MPI_Request req; + int errs = 0, err; + int rank, size; + int *buf, bufsize; + int *result; + int *rmabuf, rsize, rcount; + MPI_Comm comm; + MPI_Win win; + MPI_Request req; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); bufsize = 256 * sizeof(int); - buf = (int *)malloc( bufsize ); + buf = (int *) malloc(bufsize); if (!buf) { - fprintf( stderr, "Unable to allocated %d bytes\n", bufsize ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated %d bytes\n", bufsize); + MPI_Abort(MPI_COMM_WORLD, 1); } - result = (int *)malloc( bufsize ); + result = (int *) malloc(bufsize); if (!result) { - fprintf( stderr, "Unable to allocated %d bytes\n", bufsize ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated %d bytes\n", bufsize); + MPI_Abort(MPI_COMM_WORLD, 1); } - rcount = 16; - rsize = rcount * sizeof(int); - rmabuf = (int *)malloc( rsize ); + rcount = 16; + rsize = rcount * sizeof(int); + rmabuf = (int *) malloc(rsize); if (!rmabuf) { - fprintf( stderr, "Unable to allocated %d bytes\n", rsize ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated %d bytes\n", rsize); + MPI_Abort(MPI_COMM_WORLD, 1); } - - /* The following illustrates the use of the routines to - run through a selection of communicators and datatypes. - Use subsets of these for tests that do not involve combinations - of communicators, datatypes, and counts of datatypes */ - while (MTestGetIntracommGeneral( &comm, 1, 1 )) { - if (comm == MPI_COMM_NULL) continue; - /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); - - MPI_Win_create( buf, bufsize, sizeof(int), MPI_INFO_NULL, comm, &win ); - /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); + + /* The following illustrates the use of the routines to + * run through a selection of communicators and datatypes. + * Use subsets of these for tests that do not involve combinations + * of communicators, datatypes, and counts of datatypes */ + while (MTestGetIntracommGeneral(&comm, 1, 1)) { + if (comm == MPI_COMM_NULL) + continue; + /* Determine the sender and receiver */ + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); + + MPI_Win_create(buf, bufsize, sizeof(int), MPI_INFO_NULL, comm, &win); + /* To improve reporting of problems about operations, we + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/ - MPI_Win_fence( 0, win ); + MPI_Win_fence(0, win); TEST_FENCE_OP("Put", - MPI_Put( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, - rcount, MPI_INT, win ); - ); + MPI_Put(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win); +); TEST_FENCE_OP("Get", - MPI_Get( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, - rcount, MPI_INT, win ); - ); + MPI_Get(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win); +); TEST_FENCE_OP("Accumulate", - MPI_Accumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, - 0, rcount, MPI_INT, MPI_SUM, win ); - ); + MPI_Accumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, + 0, rcount, MPI_INT, MPI_SUM, win); +); TEST_FENCE_OP("Get accumulate", - MPI_Get_accumulate( rmabuf, rcount, MPI_INT, result, - rcount, MPI_INT, MPI_PROC_NULL, 0, - rcount, MPI_INT, MPI_SUM, win ); - ); + MPI_Get_accumulate(rmabuf, rcount, MPI_INT, result, + rcount, MPI_INT, MPI_PROC_NULL, 0, + rcount, MPI_INT, MPI_SUM, win); +); TEST_FENCE_OP("Fetch and op", - MPI_Fetch_and_op( rmabuf, result, MPI_INT, MPI_PROC_NULL, - 0, MPI_SUM, win ); - ); + MPI_Fetch_and_op(rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, MPI_SUM, win); +); TEST_FENCE_OP("Compare and swap", - MPI_Compare_and_swap( rmabuf, &rank, result, MPI_INT, - MPI_PROC_NULL, 0, win ); - ); + MPI_Compare_and_swap(rmabuf, &rank, result, MPI_INT, MPI_PROC_NULL, 0, win); +); /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/ - TEST_PT_OP("Put", - MPI_Put( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, - MPI_INT, win ); - ); - TEST_PT_OP("Get", - MPI_Get( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, - MPI_INT, win ); - ); + TEST_PT_OP("Put", MPI_Put(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win); +); + TEST_PT_OP("Get", MPI_Get(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win); +); TEST_PT_OP("Accumulate", - MPI_Accumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, - rcount, MPI_INT, MPI_SUM, win ); - ); + MPI_Accumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, + rcount, MPI_INT, MPI_SUM, win); +); TEST_PT_OP("Get accumulate", - MPI_Get_accumulate( rmabuf, rcount, MPI_INT, result, rcount, - MPI_INT, MPI_PROC_NULL, 0, rcount, - MPI_INT, MPI_SUM, win ); - ); + MPI_Get_accumulate(rmabuf, rcount, MPI_INT, result, rcount, + MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, MPI_SUM, win); +); TEST_PT_OP("Fetch and op", - MPI_Fetch_and_op( rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, - MPI_SUM, win ); - ); + MPI_Fetch_and_op(rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, MPI_SUM, win); +); TEST_PT_OP("Compare and swap", - MPI_Compare_and_swap( rmabuf, &rank, result, MPI_INT, - MPI_PROC_NULL, 0, win ); - ); + MPI_Compare_and_swap(rmabuf, &rank, result, MPI_INT, MPI_PROC_NULL, 0, win); +); /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/ TEST_REQ_OP("Rput", req, - MPI_Rput( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, - MPI_INT, win, &req ); - ); + MPI_Rput(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win, &req); +); TEST_REQ_OP("Rget", req, - MPI_Rget( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, - MPI_INT, win, &req ); - ); + MPI_Rget(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win, &req); +); TEST_REQ_OP("Raccumulate", req, - MPI_Raccumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, - rcount, MPI_INT, MPI_SUM, win, &req ); - ); + MPI_Raccumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, + rcount, MPI_INT, MPI_SUM, win, &req); +); TEST_REQ_OP("Rget_accumulate", req, - MPI_Rget_accumulate( rmabuf, rcount, MPI_INT, result, - rcount, MPI_INT, MPI_PROC_NULL, 0, - rcount, MPI_INT, MPI_SUM, win, &req ); - ); + MPI_Rget_accumulate(rmabuf, rcount, MPI_INT, result, + rcount, MPI_INT, MPI_PROC_NULL, 0, + rcount, MPI_INT, MPI_SUM, win, &req); +); - MPI_Win_free( &win ); + MPI_Win_free(&win); MTestFreeComm(&comm); } - free( result ); - free( buf ); - free( rmabuf ); - MTest_Finalize( errs ); + free(result); + free(buf); + free(rmabuf); + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/rmazero.c b/teshsuite/smpi/mpich3-test/rma/rmazero.c index 9e27b77bbb..78bbbe372a 100644 --- a/teshsuite/smpi/mpich3-test/rma/rmazero.c +++ b/teshsuite/smpi/mpich3-test/rma/rmazero.c @@ -18,14 +18,14 @@ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Zero-byte op " op_name_, err ); \ + MTestPrintErrorMsg("Zero-byte op " op_name_, err); \ } \ } \ - err = MPI_Win_fence( 0, win ); \ + err = MPI_Win_fence(0, win); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Fence after " op_name_, err ); \ + MTestPrintErrorMsg("Fence after " op_name_, err); \ } \ } \ } while (0) @@ -38,21 +38,21 @@ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Lock before" op_name_, err ); \ + MTestPrintErrorMsg("Lock before" op_name_, err); \ } \ } \ err = fcn_call_ \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Zero-byte op " op_name_, err ); \ + MTestPrintErrorMsg("Zero-byte op " op_name_, err); \ } \ } \ - err = MPI_Win_unlock( TARGET, win ); \ + err = MPI_Win_unlock(TARGET, win); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Unlock after " op_name_, err ); \ + MTestPrintErrorMsg("Unlock after " op_name_, err); \ } \ } \ } while (0) @@ -65,28 +65,28 @@ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Lock before" op_name_, err ); \ + MTestPrintErrorMsg("Lock before" op_name_, err); \ } \ } \ err = fcn_call_ \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Zero-byte op " op_name_, err ); \ + MTestPrintErrorMsg("Zero-byte op " op_name_, err); \ } \ } \ - err = MPI_Win_unlock( TARGET, win ); \ + err = MPI_Win_unlock(TARGET, win); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Unlock after " op_name_, err ); \ + MTestPrintErrorMsg("Unlock after " op_name_, err); \ } \ } \ - err = MPI_Wait( &req_, MPI_STATUS_IGNORE ); \ + err = MPI_Wait(&req_, MPI_STATUS_IGNORE); \ if (err) { \ errs++; \ if (errs < 10) { \ - MTestPrintErrorMsg( "Wait after " op_name_, err ); \ + MTestPrintErrorMsg("Wait after " op_name_, err); \ } \ } \ } while (0) @@ -95,37 +95,37 @@ static char MTEST_Descrip[] = "Test handling of zero-byte transfers"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { - int errs = 0, err; - int rank, size; - int *buf, bufsize; - int *result; - int *rmabuf, rsize, rcount; - MPI_Comm comm; - MPI_Win win; - MPI_Request req; - MPI_Datatype derived_dtp; - - MTest_Init( &argc, &argv ); + int errs = 0, err; + int rank, size; + int *buf, bufsize; + int *result; + int *rmabuf, rsize, rcount; + MPI_Comm comm; + MPI_Win win; + MPI_Request req; + MPI_Datatype derived_dtp; + + MTest_Init(&argc, &argv); bufsize = 256 * sizeof(int); - buf = (int *)malloc( bufsize ); + buf = (int *) malloc(bufsize); if (!buf) { - fprintf( stderr, "Unable to allocated %d bytes\n", bufsize ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated %d bytes\n", bufsize); + MPI_Abort(MPI_COMM_WORLD, 1); } - result = (int *)malloc( bufsize ); + result = (int *) malloc(bufsize); if (!result) { - fprintf( stderr, "Unable to allocated %d bytes\n", bufsize ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated %d bytes\n", bufsize); + MPI_Abort(MPI_COMM_WORLD, 1); } - rcount = 16; - rsize = rcount * sizeof(int); - rmabuf = (int *)malloc( rsize ); + rcount = 16; + rsize = rcount * sizeof(int); + rmabuf = (int *) malloc(rsize); if (!rmabuf) { - fprintf( stderr, "Unable to allocated %d bytes\n", rsize ); - MPI_Abort( MPI_COMM_WORLD, 1 ); + fprintf(stderr, "Unable to allocated %d bytes\n", rsize); + MPI_Abort(MPI_COMM_WORLD, 1); } MPI_Type_contiguous(2, MPI_INT, &derived_dtp); @@ -133,106 +133,94 @@ int main( int argc, char *argv[] ) /* The following loop is used to run through a series of communicators * that are subsets of MPI_COMM_WORLD, of size 1 or greater. */ - while (MTestGetIntracommGeneral( &comm, 1, 1 )) { + while (MTestGetIntracommGeneral(&comm, 1, 1)) { int count = 0; - if (comm == MPI_COMM_NULL) continue; + if (comm == MPI_COMM_NULL) + continue; /* Determine the sender and receiver */ - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); - MPI_Win_create( buf, bufsize, 2*sizeof(int), MPI_INFO_NULL, comm, &win ); + MPI_Win_create(buf, bufsize, 2 * sizeof(int), MPI_INFO_NULL, comm, &win); /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN ); + * change the error handler to errors return */ + MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/ - MPI_Win_fence( 0, win ); + MPI_Win_fence(0, win); - TEST_FENCE_OP("Put", - MPI_Put( rmabuf, count, MPI_INT, TARGET, 0, - count, MPI_INT, win ); - ); + TEST_FENCE_OP("Put", MPI_Put(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win); +); - TEST_FENCE_OP("Get", - MPI_Get( rmabuf, count, MPI_INT, TARGET, 0, - count, MPI_INT, win ); - ); + TEST_FENCE_OP("Get", MPI_Get(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win); +); TEST_FENCE_OP("Accumulate", - MPI_Accumulate( rmabuf, count, MPI_INT, TARGET, - 0, count, MPI_INT, MPI_SUM, win ); - ); + MPI_Accumulate(rmabuf, count, MPI_INT, TARGET, + 0, count, MPI_INT, MPI_SUM, win); +); TEST_FENCE_OP("Accumulate_derived", - MPI_Accumulate( rmabuf, count, derived_dtp, TARGET, - 0, count, derived_dtp, MPI_SUM, win ); - ); + MPI_Accumulate(rmabuf, count, derived_dtp, TARGET, + 0, count, derived_dtp, MPI_SUM, win); +); TEST_FENCE_OP("Get accumulate", - MPI_Get_accumulate( rmabuf, count, MPI_INT, result, - count, MPI_INT, TARGET, 0, - count, MPI_INT, MPI_SUM, win ); - ); + MPI_Get_accumulate(rmabuf, count, MPI_INT, result, + count, MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win); +); /* Note: It's not possible to generate a zero-byte FOP or CAS */ /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/ - TEST_PT_OP("Put", - MPI_Put( rmabuf, count, MPI_INT, TARGET, 0, count, - MPI_INT, win ); - ); - TEST_PT_OP("Get", - MPI_Get( rmabuf, count, MPI_INT, TARGET, 0, count, - MPI_INT, win ); - ); + TEST_PT_OP("Put", MPI_Put(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win); +); + TEST_PT_OP("Get", MPI_Get(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win); +); TEST_PT_OP("Accumulate", - MPI_Accumulate( rmabuf, count, MPI_INT, TARGET, 0, - count, MPI_INT, MPI_SUM, win ); - ); + MPI_Accumulate(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win); +); TEST_PT_OP("Accumulate_derived", - MPI_Accumulate( rmabuf, count, derived_dtp, TARGET, 0, - count, derived_dtp, MPI_SUM, win ); - ); + MPI_Accumulate(rmabuf, count, derived_dtp, TARGET, 0, + count, derived_dtp, MPI_SUM, win); +); TEST_PT_OP("Get accumulate", - MPI_Get_accumulate( rmabuf, count, MPI_INT, result, count, - MPI_INT, TARGET, 0, count, - MPI_INT, MPI_SUM, win ); - ); + MPI_Get_accumulate(rmabuf, count, MPI_INT, result, count, + MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win); +); /* Note: It's not possible to generate a zero-byte FOP or CAS */ /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/ TEST_REQ_OP("Rput", req, - MPI_Rput( rmabuf, count, MPI_INT, TARGET, 0, count, - MPI_INT, win, &req ); - ); + MPI_Rput(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win, &req); +); TEST_REQ_OP("Rget", req, - MPI_Rget( rmabuf, count, MPI_INT, TARGET, 0, count, - MPI_INT, win, &req ); - ); + MPI_Rget(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win, &req); +); TEST_REQ_OP("Raccumulate", req, - MPI_Raccumulate( rmabuf, count, MPI_INT, TARGET, 0, - count, MPI_INT, MPI_SUM, win, &req ); - ); + MPI_Raccumulate(rmabuf, count, MPI_INT, TARGET, 0, + count, MPI_INT, MPI_SUM, win, &req); +); TEST_REQ_OP("Raccumulate_derived", req, - MPI_Raccumulate( rmabuf, count, derived_dtp, TARGET, 0, - count, derived_dtp, MPI_SUM, win, &req ); - ); + MPI_Raccumulate(rmabuf, count, derived_dtp, TARGET, 0, + count, derived_dtp, MPI_SUM, win, &req); +); TEST_REQ_OP("Rget_accumulate", req, - MPI_Rget_accumulate( rmabuf, count, MPI_INT, result, - count, MPI_INT, TARGET, 0, - count, MPI_INT, MPI_SUM, win, &req ); - ); + MPI_Rget_accumulate(rmabuf, count, MPI_INT, result, + count, MPI_INT, TARGET, 0, + count, MPI_INT, MPI_SUM, win, &req); +); - MPI_Win_free( &win ); + MPI_Win_free(&win); MTestFreeComm(&comm); } MPI_Type_free(&derived_dtp); - free( result ); - free( buf ); - free( rmabuf ); - MTest_Finalize( errs ); + free(result); + free(buf); + free(rmabuf); + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/rput_local_comp.c b/teshsuite/smpi/mpich3-test/rma/rput_local_comp.c new file mode 100644 index 0000000000..0d1f682d28 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/rput_local_comp.c @@ -0,0 +1,129 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#include +#include +#include +#include "mpitest.h" + +#define ITER 100 +#define MAX_SIZE 65536 + +int main(int argc, char *argv[]) +{ + int rank, nproc, i; + int errors = 0, all_errors = 0; + int *buf = NULL, *winbuf = NULL; + MPI_Win window; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + if (nproc < 2) { + if (rank == 0) + printf("Error: must be run with two or more processes\n"); + MPI_Abort(MPI_COMM_WORLD, 1); + } + + MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &buf); + MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &winbuf); + MPI_Win_create(winbuf, MAX_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, + MPI_COMM_WORLD, &window); + + MPI_Win_lock_all(0, window); + + /* Test Rput local completion with small data. + * Small data is always copied to header packet as immediate data. */ + if (rank == 1) { + for (i = 0; i < ITER; i++) { + MPI_Request put_req; + int val = -1; + + buf[0] = rank; + MPI_Rput(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, window, &put_req); + MPI_Wait(&put_req, MPI_STATUS_IGNORE); + + /* reset local buffer to check local completion */ + buf[0] = 0; + MPI_Win_flush(0, window); + + MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window); + MPI_Win_flush(0, window); + + if (val != rank) { + printf("%d - Got %d in small Rput test, expected %d\n", rank, val, rank); + errors++; + } + } + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* Test Rput local completion with large data . + * Large data is not suitable for 1-copy optimization, and always sent out + * from user buffer. */ + if (rank == 1) { + for (i = 0; i < ITER; i++) { + MPI_Request put_req; + int val0 = -1, val1 = -1, val2 = -1; + int j; + + /* initialize data */ + for (j = 0; j < MAX_SIZE; j++) { + buf[j] = rank + j + i; + } + + MPI_Rput(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, window, &put_req); + MPI_Wait(&put_req, MPI_STATUS_IGNORE); + + /* reset local buffer to check local completion */ + buf[0] = 0; + buf[MAX_SIZE - 1] = 0; + buf[MAX_SIZE / 2] = 0; + MPI_Win_flush(0, window); + + /* get remote values which are modified in local buffer after wait */ + MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window); + MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window); + MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window); + MPI_Win_flush(0, window); + + if (val0 != rank + i) { + printf("%d - Got %d in large Rput test, expected %d\n", rank, val0, rank + i); + errors++; + } + if (val1 != rank + MAX_SIZE - 1 + i) { + printf("%d - Got %d in large Rput test, expected %d\n", rank, val1, + rank + MAX_SIZE - 1 + i); + errors++; + } + if (val2 != rank + MAX_SIZE / 2 + i) { + printf("%d - Got %d in large Rput test, expected %d\n", rank, val2, + rank + MAX_SIZE / 2 + i); + errors++; + } + } + } + + MPI_Win_unlock_all(window); + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Win_free(&window); + if (buf) + MPI_Free_mem(buf); + if (winbuf) + MPI_Free_mem(winbuf); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/selfrma.c b/teshsuite/smpi/mpich3-test/rma/selfrma.c index ca8ae4ba84..6a8b4f086f 100644 --- a/teshsuite/smpi/mpich3-test/rma/selfrma.c +++ b/teshsuite/smpi/mpich3-test/rma/selfrma.c @@ -14,99 +14,95 @@ static char MTEST_Descrip[] = "RMA to self"; */ -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; int rank, size, i, j; - MPI_Comm comm; - MPI_Win win; - int *winbuf, count; - int *sbuf, scount, vcount; - MPI_Datatype vectype; + MPI_Comm comm; + MPI_Win win; + int *winbuf, count; + int *sbuf, scount, vcount; + MPI_Datatype vectype; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); comm = MPI_COMM_WORLD; - MPI_Comm_rank( comm, &rank ); - MPI_Comm_size( comm, &size ); + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &size); /* Allocate and initialize sbuf */ scount = 1000; - count = 1000; - sbuf = (int *)malloc( scount * sizeof(int) ); + count = 1000; + sbuf = (int *) malloc(scount * sizeof(int)); if (!sbuf) { - fprintf( stderr, "Could not allocate send buffer f size %d\n", - scount ); - MPI_Abort( MPI_COMM_WORLD, 0 ); + fprintf(stderr, "Could not allocate send buffer f size %d\n", scount); + MPI_Abort(MPI_COMM_WORLD, 0); } - for (i=0; i + * Author: James Dinan * Date : December, 2010 * * This code performs N accumulates into a 2d patch of a shared array. The @@ -28,7 +28,8 @@ #define SUB_YDIM 8 #define ITERATIONS 1 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int itr, i, j, rank, nranks, peer, bufsize, errors; double *win_buf, *src_buf; MPI_Win buf_win; @@ -42,51 +43,51 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); - for (i = 0; i < XDIM*YDIM; i++) { + for (i = 0; i < XDIM * YDIM; i++) { *(win_buf + i) = -1.0; *(src_buf + i) = 1.0 + rank; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided accumulate operations */ for (itr = 0; itr < ITERATIONS; itr++) { - MPI_Aint idx_loc[SUB_YDIM]; - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; - - for (i = 0; i < SUB_YDIM; i++) { - MPI_Get_address(&src_buf[i*XDIM], &idx_loc[i]); - idx_rem[i] = i*XDIM; - blk_len[i] = SUB_XDIM; - } + MPI_Aint idx_loc[SUB_YDIM]; + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; + + for (i = 0; i < SUB_YDIM; i++) { + MPI_Get_address(&src_buf[i * XDIM], &idx_loc[i]); + idx_rem[i] = i * XDIM; + blk_len[i] = SUB_XDIM; + } #ifdef ABSOLUTE - MPI_Type_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_DOUBLE, &src_type); + MPI_Type_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_DOUBLE, &src_type); #else - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); #endif - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); #ifdef ABSOLUTE - MPI_Accumulate(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win); + MPI_Accumulate(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win); #else - MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win); + MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win); #endif - MPI_Win_unlock(peer, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -96,40 +97,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0 + (1.0 + ((rank+nranks-1)%nranks)) * (ITERATIONS); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0 + (1.0 + ((rank + nranks - 1) % nranks)) * (ITERATIONS); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -137,7 +138,7 @@ int main(int argc, char **argv) { MPI_Free_mem(win_buf); MPI_Free_mem(src_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_acc_onelock.c b/teshsuite/smpi/mpich3-test/rma/strided_acc_onelock.c index 55ecde262c..529d628f56 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_acc_onelock.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_acc_onelock.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Accumulate Test * - * Author: James Dinan + * Author: James Dinan * Date : December, 2010 * * This code performs one-sided accumulate into a 2d patch of a shared array. @@ -19,11 +19,12 @@ #include "mpitest.h" #include "squelch.h" -#define XDIM 1024 +#define XDIM 1024 #define YDIM 1024 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; double *buffer, *src_buf; MPI_Win buf_win; @@ -37,41 +38,42 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &buffer); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); - for (i = 0; i < XDIM*YDIM; i++) { - *(buffer + i) = 1.0 + rank; + for (i = 0; i < XDIM * YDIM; i++) { + *(buffer + i) = 1.0 + rank; *(src_buf + i) = 1.0 + rank; } MPI_Win_create(buffer, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; for (i = 0; i < ITERATIONS; i++) { - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - for (j = 0; j < YDIM; j++) { - MPI_Accumulate(src_buf + j*XDIM, XDIM, MPI_DOUBLE, peer, - j*XDIM*sizeof(double), XDIM, MPI_DOUBLE, MPI_SUM, buf_win); - } + for (j = 0; j < YDIM; j++) { + MPI_Accumulate(src_buf + j * XDIM, XDIM, MPI_DOUBLE, peer, + j * XDIM * sizeof(double), XDIM, MPI_DOUBLE, MPI_SUM, buf_win); + } - MPI_Win_unlock(peer, buf_win); + MPI_Win_unlock(peer, buf_win); } MPI_Barrier(MPI_COMM_WORLD); MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); for (i = errors = 0; i < XDIM; i++) { - for (j = 0; j < YDIM; j++) { - const double actual = *(buffer + i + j*XDIM); - const double expected = (1.0 + rank) + (1.0 + ((rank+nranks-1)%nranks)) * (ITERATIONS); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < YDIM; j++) { + const double actual = *(buffer + i + j * XDIM); + const double expected = + (1.0 + rank) + (1.0 + ((rank + nranks - 1) % nranks)) * (ITERATIONS); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -79,7 +81,7 @@ int main(int argc, char **argv) { MPI_Free_mem(buffer); MPI_Free_mem(src_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_acc_subarray.c b/teshsuite/smpi/mpich3-test/rma/strided_acc_subarray.c index c8f850c6a7..b1c667c739 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_acc_subarray.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_acc_subarray.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Accumulate Test * - * Author: James Dinan + * Author: James Dinan * Date : December, 2010 * * This code performs N accumulates into a 2d patch of a shared array. The @@ -22,13 +22,14 @@ #include "mpitest.h" #include "squelch.h" -#define XDIM 1024 +#define XDIM 1024 #define YDIM 1024 #define SUB_XDIM 512 #define SUB_YDIM 512 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; double *win_buf, *src_buf; MPI_Win buf_win; @@ -42,44 +43,44 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); - for (i = 0; i < XDIM*YDIM; i++) { + for (i = 0; i < XDIM * YDIM; i++) { *(win_buf + i) = -1.0; *(src_buf + i) = 1.0 + rank; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided accumulate operations */ for (i = 0; i < ITERATIONS; i++) { - int ndims = 2; - int src_arr_sizes[2] = { XDIM, YDIM }; - int src_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM }; - int src_arr_starts[2] = { 0, 0 }; - int dst_arr_sizes[2] = { XDIM, YDIM }; - int dst_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM }; - int dst_arr_starts[2] = { 0, 0 }; - MPI_Datatype src_type, dst_type; + int ndims = 2; + int src_arr_sizes[2] = { XDIM, YDIM }; + int src_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM }; + int src_arr_starts[2] = { 0, 0 }; + int dst_arr_sizes[2] = { XDIM, YDIM }; + int dst_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM }; + int dst_arr_starts[2] = { 0, 0 }; + MPI_Datatype src_type, dst_type; - MPI_Type_create_subarray(ndims, src_arr_sizes, src_arr_subsizes, src_arr_starts, - MPI_ORDER_C, MPI_DOUBLE, &src_type); + MPI_Type_create_subarray(ndims, src_arr_sizes, src_arr_subsizes, src_arr_starts, + MPI_ORDER_C, MPI_DOUBLE, &src_type); - MPI_Type_create_subarray(ndims, dst_arr_sizes, dst_arr_subsizes, dst_arr_starts, - MPI_ORDER_C, MPI_DOUBLE, &dst_type); + MPI_Type_create_subarray(ndims, dst_arr_sizes, dst_arr_subsizes, dst_arr_starts, + MPI_ORDER_C, MPI_DOUBLE, &dst_type); - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win); + MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -89,40 +90,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0 + (1.0 + ((rank+nranks-1)%nranks)) * (ITERATIONS); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0 + (1.0 + ((rank + nranks - 1) % nranks)) * (ITERATIONS); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -130,7 +131,7 @@ int main(int argc, char **argv) { MPI_Free_mem(win_buf); MPI_Free_mem(src_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_get_indexed.c b/teshsuite/smpi/mpich3-test/rma/strided_get_indexed.c index 3a98d29879..c0c1406062 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_get_indexed.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_get_indexed.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Get Test * - * Author: James Dinan + * Author: James Dinan * Date : December, 2010 * * This code performs N strided get operations from a 2d patch of a shared @@ -27,7 +27,8 @@ #define SUB_XDIM 8 #define SUB_YDIM 256 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; double *win_buf, *loc_buf; MPI_Win buf_win; @@ -45,20 +46,20 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &loc_buf); - for (i = 0; i < XDIM*YDIM; i++) { - *(win_buf + i) = 1.0 + rank; + for (i = 0; i < XDIM * YDIM; i++) { + *(win_buf + i) = 1.0 + rank; *(loc_buf + i) = -1.0; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Build the datatype */ for (i = 0; i < SUB_YDIM; i++) { - idx_rem[i] = i*XDIM; - blk_len[i] = SUB_XDIM; + idx_rem[i] = i * XDIM; + blk_len[i] = SUB_XDIM; } MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &loc_type); @@ -87,47 +88,47 @@ int main(int argc, char **argv) { errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(loc_buf + i + j*XDIM); - const double expected = (1.0 + peer); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(loc_buf + i + j * XDIM); + const double expected = (1.0 + peer); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(loc_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(loc_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(loc_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(loc_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_free(&buf_win); MPI_Free_mem(win_buf); MPI_Free_mem(loc_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed.c b/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed.c index e3293a1eff..88a08adbe7 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Accumulate Test * - * Author: James Dinan + * Author: James Dinan * Date : December, 2010 * * This code performs N strided put operations followed by get operations into @@ -28,7 +28,8 @@ #define SUB_YDIM 2 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; double *win_buf, *src_buf, *dst_buf; MPI_Win buf_win; @@ -43,47 +44,47 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf); - for (i = 0; i < XDIM*YDIM; i++) { + for (i = 0; i < XDIM * YDIM; i++) { *(win_buf + i) = -1.0; - *(src_buf + i) = 1.0 + rank; + *(src_buf + i) = 1.0 + rank; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided accumulate operations */ for (i = 0; i < ITERATIONS; i++) { - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; - - for (j = 0; j < SUB_YDIM; j++) { - idx_rem[j] = j*XDIM; - blk_len[j] = SUB_XDIM; - } - - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); - - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); - - /* PUT */ - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, - 1, dst_type, MPI_REPLACE, buf_win); - MPI_Win_unlock(peer, buf_win); - - /* GET */ - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, - 1, dst_type, MPI_NO_OP, buf_win); - MPI_Win_unlock(peer, buf_win); - - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; + + for (j = 0; j < SUB_YDIM; j++) { + idx_rem[j] = j * XDIM; + blk_len[j] = SUB_XDIM; + } + + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); + + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); + + /* PUT */ + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, + 1, dst_type, MPI_REPLACE, buf_win); + MPI_Win_unlock(peer, buf_win); + + /* GET */ + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, + 1, dst_type, MPI_NO_OP, buf_win); + MPI_Win_unlock(peer, buf_win); + + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -93,40 +94,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = (1.0 + ((rank+nranks-1)%nranks)); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = (1.0 + ((rank + nranks - 1) % nranks)); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -135,7 +136,7 @@ int main(int argc, char **argv) { MPI_Free_mem(src_buf); MPI_Free_mem(dst_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed_shared.c b/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed_shared.c index e1c8169b61..6a36196916 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed_shared.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed_shared.c @@ -28,7 +28,8 @@ #define SUB_YDIM 2 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int rank, nranks, rank_world, nranks_world; int i, j, peer, bufsize, errors; double *win_buf, *src_buf, *dst_buf; @@ -40,7 +41,7 @@ int main(int argc, char **argv) { MPI_Comm_rank(MPI_COMM_WORLD, &rank_world); MPI_Comm_size(MPI_COMM_WORLD, &nranks_world); - MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shr_comm); + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank_world, MPI_INFO_NULL, &shr_comm); MPI_Comm_rank(shr_comm, &rank); MPI_Comm_size(shr_comm, &nranks); @@ -53,47 +54,47 @@ int main(int argc, char **argv) { MPI_Win_fence(0, buf_win); - for (i = 0; i < XDIM*YDIM; i++) { + for (i = 0; i < XDIM * YDIM; i++) { *(win_buf + i) = -1.0; - *(src_buf + i) = 1.0 + rank; + *(src_buf + i) = 1.0 + rank; } MPI_Win_fence(0, buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided accumulate operations */ for (i = 0; i < ITERATIONS; i++) { - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; - - for (j = 0; j < SUB_YDIM; j++) { - idx_rem[j] = j*XDIM; - blk_len[j] = SUB_XDIM; - } - - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); - - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); - - /* PUT */ - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, - 1, dst_type, MPI_REPLACE, buf_win); - MPI_Win_unlock(peer, buf_win); - - /* GET */ - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, - 1, dst_type, MPI_NO_OP, buf_win); - MPI_Win_unlock(peer, buf_win); - - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; + + for (j = 0; j < SUB_YDIM; j++) { + idx_rem[j] = j * XDIM; + blk_len[j] = SUB_XDIM; + } + + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); + + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); + + /* PUT */ + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, + 1, dst_type, MPI_REPLACE, buf_win); + MPI_Win_unlock(peer, buf_win); + + /* GET */ + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0, + 1, dst_type, MPI_NO_OP, buf_win); + MPI_Win_unlock(peer, buf_win); + + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -103,40 +104,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = (1.0 + ((rank+nranks-1)%nranks)); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = (1.0 + ((rank + nranks - 1) % nranks)); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -145,7 +146,7 @@ int main(int argc, char **argv) { MPI_Free_mem(dst_buf); MPI_Comm_free(&shr_comm); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed.c b/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed.c index 09f17ae1f6..0b6c8c46b7 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed.c @@ -6,7 +6,7 @@ /* One-Sided MPI 2-D Strided Accumulate Test * - * Author: James Dinan + * Author: James Dinan * Date : December, 2010 * * This code performs N strided put operations followed by get operations into @@ -28,7 +28,8 @@ #define SUB_YDIM 255 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int i, j, rank, nranks, peer, bufsize, errors; double *win_buf, *src_buf, *dst_buf; MPI_Win buf_win; @@ -43,43 +44,43 @@ int main(int argc, char **argv) { MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf); MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf); - for (i = 0; i < XDIM*YDIM; i++) { + for (i = 0; i < XDIM * YDIM; i++) { *(win_buf + i) = -1.0; - *(src_buf + i) = 1.0 + rank; + *(src_buf + i) = 1.0 + rank; } MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided accumulate operations */ for (i = 0; i < ITERATIONS; i++) { - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; - for (j = 0; j < SUB_YDIM; j++) { - idx_rem[j] = j*XDIM; - blk_len[j] = SUB_XDIM; - } + for (j = 0; j < SUB_YDIM; j++) { + idx_rem[j] = j * XDIM; + blk_len[j] = SUB_XDIM; + } - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(MPI_COMM_WORLD); @@ -89,40 +90,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = (1.0 + ((rank+nranks-1)%nranks)); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = (1.0 + ((rank + nranks - 1) % nranks)); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -131,7 +132,7 @@ int main(int argc, char **argv) { MPI_Free_mem(src_buf); MPI_Free_mem(dst_buf); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed_shared.c b/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed_shared.c index 1e65f2a9d4..b6f2bfa773 100644 --- a/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed_shared.c +++ b/teshsuite/smpi/mpich3-test/rma/strided_putget_indexed_shared.c @@ -28,7 +28,8 @@ #define SUB_YDIM 255 #define ITERATIONS 10 -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int rank, nranks, rank_world, nranks_world; int i, j, peer, bufsize, errors; double *win_buf, *src_buf, *dst_buf; @@ -40,7 +41,7 @@ int main(int argc, char **argv) { MPI_Comm_rank(MPI_COMM_WORLD, &rank_world); MPI_Comm_size(MPI_COMM_WORLD, &nranks_world); - MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shr_comm); + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank_world, MPI_INFO_NULL, &shr_comm); MPI_Comm_rank(shr_comm, &rank); MPI_Comm_size(shr_comm, &nranks); @@ -53,43 +54,43 @@ int main(int argc, char **argv) { MPI_Win_fence(0, buf_win); - for (i = 0; i < XDIM*YDIM; i++) { + for (i = 0; i < XDIM * YDIM; i++) { *(win_buf + i) = -1.0; - *(src_buf + i) = 1.0 + rank; + *(src_buf + i) = 1.0 + rank; } MPI_Win_fence(0, buf_win); - peer = (rank+1) % nranks; + peer = (rank + 1) % nranks; /* Perform ITERATIONS strided accumulate operations */ for (i = 0; i < ITERATIONS; i++) { - int idx_rem[SUB_YDIM]; - int blk_len[SUB_YDIM]; - MPI_Datatype src_type, dst_type; + int idx_rem[SUB_YDIM]; + int blk_len[SUB_YDIM]; + MPI_Datatype src_type, dst_type; - for (j = 0; j < SUB_YDIM; j++) { - idx_rem[j] = j*XDIM; - blk_len[j] = SUB_XDIM; - } + for (j = 0; j < SUB_YDIM; j++) { + idx_rem[j] = j * XDIM; + blk_len[j] = SUB_XDIM; + } - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); - MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type); + MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type); - MPI_Type_commit(&src_type); - MPI_Type_commit(&dst_type); + MPI_Type_commit(&src_type); + MPI_Type_commit(&dst_type); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); - MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); - MPI_Win_unlock(peer, buf_win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win); + MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win); + MPI_Win_unlock(peer, buf_win); - MPI_Type_free(&src_type); - MPI_Type_free(&dst_type); + MPI_Type_free(&src_type); + MPI_Type_free(&dst_type); } MPI_Barrier(shr_comm); @@ -99,40 +100,40 @@ int main(int argc, char **argv) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win); errors = 0; for (i = 0; i < SUB_XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = (1.0 + ((rank+nranks-1)%nranks)); - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = (1.0 + ((rank + nranks - 1) % nranks)); + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = SUB_XDIM; i < XDIM; i++) { - for (j = 0; j < SUB_YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = 0; j < SUB_YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } for (i = 0; i < XDIM; i++) { - for (j = SUB_YDIM; j < YDIM; j++) { - const double actual = *(win_buf + i + j*XDIM); - const double expected = -1.0; - if (fabs(actual - expected) > 1.0e-10) { - SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", - rank, j, i, expected, actual); ); - errors++; - fflush(stdout); + for (j = SUB_YDIM; j < YDIM; j++) { + const double actual = *(win_buf + i + j * XDIM); + const double expected = -1.0; + if (fabs(actual - expected) > 1.0e-10) { + SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n", + rank, j, i, expected, actual);); + errors++; + fflush(stdout); + } } - } } MPI_Win_unlock(rank, buf_win); @@ -141,7 +142,7 @@ int main(int argc, char **argv) { MPI_Free_mem(dst_buf); MPI_Comm_free(&shr_comm); - MTest_Finalize( errors ); + MTest_Finalize(errors); MPI_Finalize(); - return MTestReturnValue( errors ); + return MTestReturnValue(errors); } diff --git a/teshsuite/smpi/mpich3-test/rma/test1.c b/teshsuite/smpi/mpich3-test/rma/test1.c index b11995b8a0..eb2d1a141c 100644 --- a/teshsuite/smpi/mpich3-test/rma/test1.c +++ b/teshsuite/smpi/mpich3-test/rma/test1.c @@ -3,7 +3,7 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "mpitest.h" #include "squelch.h" @@ -12,16 +12,16 @@ #define SIZE 100 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, A[SIZE], B[SIZE], i; MPI_Comm CommDeuce; MPI_Win win; int errs = 0; - - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -32,50 +32,52 @@ int main(int argc, char *argv[]) if (rank < 2) { if (rank == 0) { - for (i=0; i #include "mpitest.h" @@ -15,17 +15,17 @@ #define NROWS 1000 #define NCOLS 1000 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, **A, *A_data, i, j; MPI_Comm CommDeuce; MPI_Win win; MPI_Datatype column, xpose; int errs = 0; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -39,14 +39,13 @@ int main(int argc, char *argv[]) A = (int **) malloc(NROWS * sizeof(int *)); A[0] = A_data; - for (i=1; i= 50) - { + if (errs >= 50) { printf("Total number of errors: %d\n", errs); } } @@ -104,6 +98,6 @@ int main(int argc, char *argv[]) } MPI_Comm_free(&CommDeuce); MTest_Finalize(errs); - MPI_Finalize(); - return 0; -} + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/transpose2.c b/teshsuite/smpi/mpich3-test/rma/transpose2.c index bfb30c4f80..101e1ead5f 100644 --- a/teshsuite/smpi/mpich3-test/rma/transpose2.c +++ b/teshsuite/smpi/mpich3-test/rma/transpose2.c @@ -3,30 +3,30 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "mpitest.h" /* transposes a matrix using put, fence, and derived datatypes. Uses vector and struct (Example 3.33 from MPI 1.1 Standard). We could use vector and type_create_resized instead. Run - on 2 processes */ + on 2 processes */ #define NROWS 100 #define NCOLS 100 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, A[NROWS][NCOLS], i, j, blocklen[2]; MPI_Comm CommDeuce; MPI_Aint disp[2]; MPI_Win win; MPI_Datatype column, column1, type[2]; - int errs=0; + int errs = 0; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -36,23 +36,22 @@ int main(int argc, char *argv[]) MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce); if (rank < 2) { - if (rank == 0) - { - for (i=0; i= 50) - { + if (errs >= 50) { printf("Total number of errors: %d\n", errs); } } @@ -102,6 +96,6 @@ int main(int argc, char *argv[]) MPI_Comm_free(&CommDeuce); MTest_Finalize(errs); - MPI_Finalize(); - return 0; -} + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/transpose3.c b/teshsuite/smpi/mpich3-test/rma/transpose3.c index 86ef3d5ff2..50a5c4a600 100644 --- a/teshsuite/smpi/mpich3-test/rma/transpose3.c +++ b/teshsuite/smpi/mpich3-test/rma/transpose3.c @@ -3,7 +3,7 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "mpitest.h" #include "squelch.h" @@ -15,18 +15,18 @@ #define NROWS 100 #define NCOLS 100 -int main(int argc, char *argv[]) -{ - int rank, nprocs, A[NROWS][NCOLS], i, j, destrank; +int main(int argc, char *argv[]) +{ + int rank, nprocs, i, j, destrank; MPI_Comm CommDeuce; MPI_Win win; MPI_Datatype column, xpose; MPI_Group comm_group, group; - int errs=0; + int errs = 0; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -35,15 +35,15 @@ int main(int argc, char *argv[]) MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce); - if (rank < 2) - { + if (rank < 2) { MPI_Comm_group(CommDeuce, &comm_group); - if (rank == 0) - { - for (i=0; i= 50) - { + if (errs >= 50) { printf("Total number of errors: %d\n", errs); } +#ifndef USE_WIN_ALLOCATE + MPI_Free_mem(A); +#endif } MPI_Group_free(&group); @@ -102,6 +115,6 @@ int main(int argc, char *argv[]) } MPI_Comm_free(&CommDeuce); MTest_Finalize(errs); - MPI_Finalize(); - return 0; -} + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/transpose4.c b/teshsuite/smpi/mpich3-test/rma/transpose4.c index 6e81c43de7..1559a9d590 100644 --- a/teshsuite/smpi/mpich3-test/rma/transpose4.c +++ b/teshsuite/smpi/mpich3-test/rma/transpose4.c @@ -3,7 +3,7 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "mpitest.h" @@ -14,17 +14,17 @@ #define NROWS 100 #define NCOLS 100 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, A[NROWS][NCOLS], i, j; MPI_Comm CommDeuce; MPI_Win win; MPI_Datatype column, xpose; int errs = 0; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -33,12 +33,11 @@ int main(int argc, char *argv[]) MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce); - if (rank < 2) - { + if (rank < 2) { if (rank == 0) { - for (i=0; i #include "mpitest.h" /* This does a transpose-cum-accumulate operation. Uses vector and hvector datatypes (Example 3.32 from MPI 1.1 Standard). Run on 2 - processes */ + processes */ #define NROWS 1000 #define NCOLS 1000 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, **A, *A_data, i, j; MPI_Comm CommDeuce; MPI_Win win; MPI_Datatype column, xpose; int errs = 0; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -34,20 +34,18 @@ int main(int argc, char *argv[]) MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce); - if (rank < 2) - { + if (rank < 2) { A_data = (int *) malloc(NROWS * NCOLS * sizeof(int)); A = (int **) malloc(NROWS * sizeof(int *)); A[0] = A_data; - for (i=1; i= 50) - { + if (errs >= 50) { printf("Total number of errors: %d\n", errs); } } @@ -106,6 +99,6 @@ int main(int argc, char *argv[]) MPI_Comm_free(&CommDeuce); MTest_Finalize(errs); - MPI_Finalize(); - return 0; -} + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/transpose6.c b/teshsuite/smpi/mpich3-test/rma/transpose6.c index 09471dae9c..c9f36e18f7 100644 --- a/teshsuite/smpi/mpich3-test/rma/transpose6.c +++ b/teshsuite/smpi/mpich3-test/rma/transpose6.c @@ -3,74 +3,69 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "mpitest.h" -/* This does a local transpose-cum-accumulate operation. Uses +/* This does a local transpose-cum-accumulate operation. Uses vector and hvector datatypes (Example 3.32 from MPI 1.1 Standard). Run on 1 process. */ #define NROWS 100 #define NCOLS 100 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, A[NROWS][NCOLS], B[NROWS][NCOLS], i, j; MPI_Win win; MPI_Datatype column, xpose; int errs = 0; - - MTest_Init(&argc,&argv); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - if (rank==0) - { - for (i=0; i= 20) - { - printf("Total number of errors: %d\n", errs); + if (errs >= 20) { + printf("Total number of errors: %d\n", errs); } - - MPI_Win_free(&win); + + MPI_Win_free(&win); } MTest_Finalize(errs); - MPI_Finalize(); - return 0; -} + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/transpose7.c b/teshsuite/smpi/mpich3-test/rma/transpose7.c index 954c3991b9..cd9e20b6fa 100644 --- a/teshsuite/smpi/mpich3-test/rma/transpose7.c +++ b/teshsuite/smpi/mpich3-test/rma/transpose7.c @@ -3,7 +3,7 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include #include #include "mpitest.h" @@ -15,17 +15,17 @@ #define NROWS 1000 #define NCOLS 1000 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) +{ int rank, nprocs, **A, *A_data, i, j; MPI_Comm CommDeuce; MPI_Win win; MPI_Datatype column, xpose; int errs = 0; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -34,19 +34,17 @@ int main(int argc, char *argv[]) MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce); - if (rank < 2) - { + if (rank < 2) { A_data = (int *) malloc(NROWS * NCOLS * sizeof(int)); A = (int **) malloc(NROWS * sizeof(int *)); A[0] = A_data; - for (i=1; i= 50) - { + if (errs >= 50) { printf("Total number of errors: %d\n", errs); } } - else - { - for (i=0; i 0) - MPI_Alloc_mem(rank*ELEM_SIZE, MPI_INFO_NULL, &buf); + MPI_Alloc_mem(rank * ELEM_SIZE, MPI_INFO_NULL, &buf); else - buf = NULL; + buf = NULL; - MPI_Win_create(buf, rank*ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window); + MPI_Win_create(buf, rank * ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window); MPI_Win_get_attr(window, MPI_WIN_CREATE_FLAVOR, &flavor, &flag); if (!flag) { - printf("%d: MPI_Win_create - Error, no flavor\n", rank); - errors++; - } else if (*flavor != MPI_WIN_FLAVOR_CREATE) { - printf("%d: MPI_Win_create - Error, bad flavor (%d)\n", rank, *flavor); - errors++; + printf("%d: MPI_Win_create - Error, no flavor\n", rank); + errors++; + } + else if (*flavor != MPI_WIN_FLAVOR_CREATE) { + printf("%d: MPI_Win_create - Error, bad flavor (%d)\n", rank, *flavor); + errors++; } MPI_Win_get_attr(window, MPI_WIN_MODEL, &model, &flag); if (!flag) { - printf("%d: MPI_Win_create - Error, no model\n", rank); - errors++; - } else if ( ! (*model == MPI_WIN_SEPARATE || *model == MPI_WIN_UNIFIED) ) { - printf("%d: MPI_Win_create - Error, bad model (%d)\n", rank, *model); - errors++; + printf("%d: MPI_Win_create - Error, no model\n", rank); + errors++; + } + else if (!(*model == MPI_WIN_SEPARATE || *model == MPI_WIN_UNIFIED)) { + printf("%d: MPI_Win_create - Error, bad model (%d)\n", rank, *model); + errors++; } MPI_Win_free(&window); if (buf) - MPI_Free_mem(buf); + MPI_Free_mem(buf); /** Create using MPI_Win_allocate() **/ - MPI_Win_allocate(rank*ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf, &window); + MPI_Win_allocate(rank * ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf, &window); if (rank > 0 && buf == NULL) { - printf("%d: MPI_Win_allocate - Error, bad base pointer\n", rank); - errors++; + printf("%d: MPI_Win_allocate - Error, bad base pointer\n", rank); + errors++; } MPI_Win_get_attr(window, MPI_WIN_CREATE_FLAVOR, &flavor, &flag); if (!flag) { - printf("%d: MPI_Win_allocate - Error, no flavor\n", rank); - errors++; - } else if (*flavor != MPI_WIN_FLAVOR_ALLOCATE) { - printf("%d: MPI_Win_allocate - Error, bad flavor (%d)\n", rank, *flavor); - errors++; + printf("%d: MPI_Win_allocate - Error, no flavor\n", rank); + errors++; + } + else if (*flavor != MPI_WIN_FLAVOR_ALLOCATE) { + printf("%d: MPI_Win_allocate - Error, bad flavor (%d)\n", rank, *flavor); + errors++; } MPI_Win_get_attr(window, MPI_WIN_MODEL, &model, &flag); if (!flag) { - printf("%d: MPI_Win_allocate - Error, no model\n", rank); - errors++; - } else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) { - printf("%d: MPI_Win_allocate - Error, bad model (%d)\n", rank, *model); - errors++; + printf("%d: MPI_Win_allocate - Error, no model\n", rank); + errors++; + } + else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) { + printf("%d: MPI_Win_allocate - Error, bad model (%d)\n", rank, *model); + errors++; } MPI_Win_free(&window); @@ -92,21 +96,23 @@ int main( int argc, char *argv[] ) MPI_Win_get_attr(window, MPI_WIN_CREATE_FLAVOR, &flavor, &flag); if (!flag) { - printf("%d: MPI_Win_create_dynamic - Error, no flavor\n", rank); - errors++; - } else if (*flavor != MPI_WIN_FLAVOR_DYNAMIC) { - printf("%d: MPI_Win_create_dynamic - Error, bad flavor (%d)\n", rank, *flavor); - errors++; + printf("%d: MPI_Win_create_dynamic - Error, no flavor\n", rank); + errors++; + } + else if (*flavor != MPI_WIN_FLAVOR_DYNAMIC) { + printf("%d: MPI_Win_create_dynamic - Error, bad flavor (%d)\n", rank, *flavor); + errors++; } MPI_Win_get_attr(window, MPI_WIN_MODEL, &model, &flag); if (!flag) { - printf("%d: MPI_Win_create_dynamic - Error, no model\n", rank); - errors++; - } else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) { - printf("%d: MPI_Win_create_dynamic - Error, bad model (%d)\n", rank, *model); - errors++; + printf("%d: MPI_Win_create_dynamic - Error, no model\n", rank); + errors++; + } + else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) { + printf("%d: MPI_Win_create_dynamic - Error, bad model (%d)\n", rank, *model); + errors++; } MPI_Win_free(&window); diff --git a/teshsuite/smpi/mpich3-test/rma/win_info.c b/teshsuite/smpi/mpich3-test/rma/win_info.c index 3a2222de96..3eb43802f1 100644 --- a/teshsuite/smpi/mpich3-test/rma/win_info.c +++ b/teshsuite/smpi/mpich3-test/rma/win_info.c @@ -7,30 +7,59 @@ #include #include +#include #include "mpitest.h" #define VERBOSE 0 -int main(int argc, char **argv) { - int i, j, rank, nproc; +int main(int argc, char **argv) +{ + int rank, nproc; MPI_Info info_in, info_out; - int errors = 0, all_errors = 0; - MPI_Win win; - void *base; - char invalid_key[] = "invalid_test_key"; - char buf[MPI_MAX_INFO_VAL]; - int flag; + int errors = 0, all_errors = 0; + MPI_Win win; + void *base; + char invalid_key[] = "invalid_test_key"; + char buf[MPI_MAX_INFO_VAL]; + int flag; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); + /* Test#1: setting a valid key at window-create time */ + MPI_Info_create(&info_in); - MPI_Info_set(info_in, invalid_key, "true"); + MPI_Info_set(info_in, "no_locks", "true"); + + MPI_Win_allocate(sizeof(int), sizeof(int), info_in, MPI_COMM_WORLD, &base, &win); + + MPI_Win_get_info(win, &info_out); + + MPI_Info_get(info_out, "no_locks", MPI_MAX_INFO_VAL, buf, &flag); + if (!flag || strncmp(buf, "true", strlen("true")) != 0) { + if (!flag) + printf("%d: no_locks is not defined\n", rank); + else + printf("%d: no_locks = %s, expected true\n", rank, buf); + errors++; + } + + MPI_Info_free(&info_in); + MPI_Info_free(&info_out); + + /* We create a new window with no info argument for the next text to ensure that we have the + * default settings */ + MPI_Win_free(&win); MPI_Win_allocate(sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &base, &win); + /* Test#2: setting and getting invalid key */ + + MPI_Info_create(&info_in); + MPI_Info_set(info_in, invalid_key, "true"); + MPI_Win_set_info(win, info_in); MPI_Win_get_info(win, &info_out); @@ -45,22 +74,73 @@ int main(int argc, char **argv) { } #endif + MPI_Info_free(&info_in); + MPI_Info_free(&info_out); + + /* Test#3: setting info key "no_lock" to false and getting the key */ + + MPI_Info_create(&info_in); + MPI_Info_set(info_in, "no_locks", "false"); + + MPI_Win_set_info(win, info_in); + MPI_Win_get_info(win, &info_out); + + MPI_Info_get(info_out, "no_locks", MPI_MAX_INFO_VAL, buf, &flag); + if (!flag || strncmp(buf, "false", strlen("false")) != 0) { + if (!flag) + printf("%d: no_locks is not defined\n", rank); + else + printf("%d: no_locks = %s, expected false\n", rank, buf); + errors++; + } + if (flag && VERBOSE) + printf("%d: no_locks = %s\n", rank, buf); + + MPI_Info_free(&info_in); + MPI_Info_free(&info_out); + + /* Test#4: setting info key "no_lock" to true and getting the key */ + + MPI_Info_create(&info_in); + MPI_Info_set(info_in, "no_locks", "true"); + + MPI_Win_set_info(win, info_in); + MPI_Win_get_info(win, &info_out); + MPI_Info_get(info_out, "no_locks", MPI_MAX_INFO_VAL, buf, &flag); - if (flag && VERBOSE) printf("%d: no_locks = %s\n", rank, buf); + if (!flag || strncmp(buf, "true", strlen("true")) != 0) { + if (!flag) + printf("%d: no_locks is not defined\n", rank); + else + printf("%d: no_locks = %s, expected true\n", rank, buf); + errors++; + } + if (flag && VERBOSE) + printf("%d: no_locks = %s\n", rank, buf); + + MPI_Info_free(&info_in); + MPI_Info_free(&info_out); + + /* Test#4: getting other info keys */ + + MPI_Win_get_info(win, &info_out); MPI_Info_get(info_out, "accumulate_ordering", MPI_MAX_INFO_VAL, buf, &flag); - if (flag && VERBOSE) printf("%d: accumulate_ordering = %s\n", rank, buf); + if (flag && VERBOSE) + printf("%d: accumulate_ordering = %s\n", rank, buf); MPI_Info_get(info_out, "accumulate_ops", MPI_MAX_INFO_VAL, buf, &flag); - if (flag && VERBOSE) printf("%d: accumulate_ops = %s\n", rank, buf); + if (flag && VERBOSE) + printf("%d: accumulate_ops = %s\n", rank, buf); MPI_Info_get(info_out, "same_size", MPI_MAX_INFO_VAL, buf, &flag); - if (flag && VERBOSE) printf("%d: same_size = %s\n", rank, buf); + if (flag && VERBOSE) + printf("%d: same_size = %s\n", rank, buf); MPI_Info_get(info_out, "alloc_shm", MPI_MAX_INFO_VAL, buf, &flag); - if (flag && VERBOSE) printf("%d: alloc_shm = %s\n", rank, buf); + if (flag && VERBOSE) + printf("%d: alloc_shm = %s\n", rank, buf); - MPI_Info_free(&info_in); MPI_Info_free(&info_out); MPI_Win_free(&win); diff --git a/teshsuite/smpi/mpich3-test/rma/win_large_shm.c b/teshsuite/smpi/mpich3-test/rma/win_large_shm.c index fe730d2f72..63bb5f7c00 100644 --- a/teshsuite/smpi/mpich3-test/rma/win_large_shm.c +++ b/teshsuite/smpi/mpich3-test/rma/win_large_shm.c @@ -11,68 +11,83 @@ #include #include -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ int my_rank, shared_rank; void *mybase = NULL; MPI_Win win; MPI_Info win_info; MPI_Comm shared_comm; - int shm_win_size = 1024 * 1024 * 1024 * sizeof(char); /* 1GB */ + int i; + int shm_win_size = 1024 * 1024 * 1024 * sizeof(char); /* 1GB */ MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - MPI_Info_create(&win_info); - MPI_Info_set(win_info, (char*)"alloc_shm", (char*)"true"); + for (i = 0; i < 2; i++) { + if (i == 0) { + MPI_Info_create(&win_info); + MPI_Info_set(win_info, (char *) "alloc_shm", (char *) "true"); + } + else { + win_info = MPI_INFO_NULL; + } - MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, my_rank, MPI_INFO_NULL, &shared_comm); + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, my_rank, MPI_INFO_NULL, + &shared_comm); - MPI_Comm_rank(shared_comm, &shared_rank); + MPI_Comm_rank(shared_comm, &shared_rank); - /* every processes allocate 1GB window memory */ - MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); + /* every processes allocate 1GB window memory */ + MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); - MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win); + MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); - /* some processes allocate 1GB and some processes allocate zero bytes */ - if (my_rank % 2 == 0) - MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); - else - MPI_Win_allocate(0, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); + /* some processes allocate 1GB and some processes allocate zero bytes */ + if (my_rank % 2 == 0) + MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); + else + MPI_Win_allocate(0, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); - if (shared_rank % 2 == 0) - MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win); - else - MPI_Win_allocate_shared(0, sizeof(char), win_info, shared_comm, &mybase, &win); + if (shared_rank % 2 == 0) + MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, + &win); + else + MPI_Win_allocate_shared(0, sizeof(char), win_info, shared_comm, &mybase, &win); - MPI_Win_free(&win); + MPI_Win_free(&win); - /* some processes allocate 1GB and some processes allocate smaller bytes */ - if (my_rank % 2 == 0) - MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); - else - MPI_Win_allocate(shm_win_size/2, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); + /* some processes allocate 1GB and some processes allocate smaller bytes */ + if (my_rank % 2 == 0) + MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win); + else + MPI_Win_allocate(shm_win_size / 2, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, + &win); - MPI_Win_free(&win); + MPI_Win_free(&win); - /* some processes allocate 1GB and some processes allocate smaller bytes */ - if (shared_rank % 2 == 0) - MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win); - else - MPI_Win_allocate_shared(shm_win_size/2, sizeof(char), win_info, shared_comm, &mybase, &win); + /* some processes allocate 1GB and some processes allocate smaller bytes */ + if (shared_rank % 2 == 0) + MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, + &win); + else + MPI_Win_allocate_shared(shm_win_size / 2, sizeof(char), win_info, shared_comm, &mybase, + &win); - MPI_Win_free(&win); + MPI_Win_free(&win); - MPI_Comm_free(&shared_comm); + MPI_Comm_free(&shared_comm); - MPI_Info_free(&win_info); + if (i == 0) + MPI_Info_free(&win_info); + } if (my_rank == 0) printf(" No Errors\n"); diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared.c b/teshsuite/smpi/mpich3-test/rma/win_shared.c index 03e35dee39..7dc5e0cce0 100644 --- a/teshsuite/smpi/mpich3-test/rma/win_shared.c +++ b/teshsuite/smpi/mpich3-test/rma/win_shared.c @@ -15,14 +15,15 @@ const int verbose = 0; -int main(int argc, char **argv) { - int i, j, rank, nproc; - int shm_rank, shm_nproc; +int main(int argc, char **argv) +{ + int i, j, rank, nproc; + int shm_rank, shm_nproc; MPI_Aint size; - int errors = 0, all_errors = 0; - int *base, *my_base; - int disp_unit; - MPI_Win shm_win; + int errors = 0, all_errors = 0; + int *base, *my_base; + int disp_unit; + MPI_Win shm_win; MPI_Comm shm_comm; MPI_Init(&argc, &argv); @@ -36,11 +37,11 @@ int main(int argc, char **argv) { MPI_Comm_size(shm_comm, &shm_nproc); /* Allocate ELEM_PER_PROC integers for each process */ - MPI_Win_allocate_shared(sizeof(int)*ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL, - shm_comm, &my_base, &shm_win); + MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL, + shm_comm, &my_base, &shm_win); /* Locate absolute base */ - MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &size, &disp_unit, &base); + MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &size, &disp_unit, &base); /* make sure the query returned the right values */ if (disp_unit != sizeof(int)) @@ -52,8 +53,9 @@ int main(int argc, char **argv) { if (shm_rank && (base == my_base)) errors++; - if (verbose) printf("%d -- size = %d baseptr = %p my_baseptr = %p\n", shm_rank, - (int) size, (void*) base, (void*) my_base); + if (verbose) + printf("%d -- size = %d baseptr = %p my_baseptr = %p\n", shm_rank, + (int) size, (void *) base, (void *) my_base); MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win); @@ -69,10 +71,10 @@ int main(int argc, char **argv) { /* Read and verify everyone's data */ for (i = 0; i < shm_nproc; i++) { for (j = 0; j < ELEM_PER_PROC; j++) { - if ( base[i*ELEM_PER_PROC + j] != j ) { + if (base[i * ELEM_PER_PROC + j] != j) { errors++; printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, - base[i*ELEM_PER_PROC + j], i, j, j); + base[i * ELEM_PER_PROC + j], i, j, j); } } } diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_create.c b/teshsuite/smpi/mpich3-test/rma/win_shared_create.c new file mode 100644 index 0000000000..0042184af0 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/win_shared_create.c @@ -0,0 +1,140 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +#include +#include +#include +#include +#include "mpitest.h" + +#define ELEM_PER_PROC 4 +int local_buf[ELEM_PER_PROC]; + +const int verbose = 0; + +int main(int argc, char **argv) +{ + int i, rank, nproc; + int shm_rank, shm_nproc; + MPI_Aint size; + int errors = 0, all_errors = 0; + int **bases = NULL, *my_base = NULL; + int disp_unit; + MPI_Win shm_win = MPI_WIN_NULL, win = MPI_WIN_NULL; + MPI_Comm shm_comm = MPI_COMM_NULL; + MPI_Group shm_group = MPI_GROUP_NULL, world_group = MPI_GROUP_NULL; + int dst_shm_rank, dst_world_rank; + MPI_Info create_info = MPI_INFO_NULL; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm); + + MPI_Comm_rank(shm_comm, &shm_rank); + MPI_Comm_size(shm_comm, &shm_nproc); + + /* Platform does not support shared memory, just return. */ + if (shm_nproc < 2) { + goto exit; + } + + /* Specify the last process in the node as the target process */ + dst_shm_rank = shm_nproc - 1; + MPI_Comm_group(shm_comm, &shm_group); + MPI_Comm_group(MPI_COMM_WORLD, &world_group); + MPI_Group_translate_ranks(shm_group, 1, &dst_shm_rank, world_group, &dst_world_rank); + + bases = calloc(shm_nproc, sizeof(int *)); + + /* Allocate shm window among local processes, then create a global window with + * those shm window buffers */ + MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL, + shm_comm, &my_base, &shm_win); + if (verbose) + printf("%d -- allocate shared: my_base = %p, absolute base\n", shm_rank, my_base); + + for (i = 0; i < shm_nproc; i++) { + MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &bases[i]); + if (verbose) + printf("%d -- shared query: base[%d]=%p, size %ld, unit %d\n", + shm_rank, i, bases[i], size, disp_unit); + } + +#ifdef USE_INFO_ALLOC_SHM + MPI_Info_create(&create_info); + MPI_Info_set(create_info, "alloc_shm", "true"); +#else + create_info = MPI_INFO_NULL; +#endif + + /* Reset data */ + for (i = 0; i < ELEM_PER_PROC; i++) { + my_base[i] = 0; + local_buf[i] = i + 1; + } + + MPI_Win_create(my_base, sizeof(int) * ELEM_PER_PROC, sizeof(int), create_info, MPI_COMM_WORLD, + &win); + + /* Do RMA through global window, then check value through shared window */ + MPI_Win_lock_all(0, win); + MPI_Win_lock_all(0, shm_win); + + if (shm_rank == 0) { + MPI_Put(&local_buf[0], 1, MPI_INT, dst_world_rank, 0, 1, MPI_INT, win); + MPI_Put(&local_buf[ELEM_PER_PROC - 1], 1, MPI_INT, dst_world_rank, ELEM_PER_PROC - 1, 1, + MPI_INT, win); + MPI_Win_flush(dst_world_rank, win); + } + + MPI_Win_sync(shm_win); + MPI_Barrier(shm_comm); + MPI_Win_sync(shm_win); + + if (bases[dst_shm_rank][0] != local_buf[0]) { + errors++; + printf("%d -- Got %d at rank %d index %d, expected %d\n", rank, + bases[dst_shm_rank][0], dst_shm_rank, 0, local_buf[0]); + } + if (bases[dst_shm_rank][ELEM_PER_PROC - 1] != local_buf[ELEM_PER_PROC - 1]) { + errors++; + printf("%d -- Got %d at rank %d index %d, expected %d\n", rank, + bases[dst_shm_rank][ELEM_PER_PROC - 1], dst_shm_rank, + ELEM_PER_PROC - 1, local_buf[ELEM_PER_PROC - 1]); + } + + MPI_Win_unlock_all(shm_win); + MPI_Win_unlock_all(win); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + MPI_Win_free(&win); + MPI_Win_free(&shm_win); + + exit: + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + if (create_info != MPI_INFO_NULL) + MPI_Info_free(&create_info); + if (shm_comm != MPI_COMM_NULL) + MPI_Comm_free(&shm_comm); + if (shm_group != MPI_GROUP_NULL) + MPI_Group_free(&shm_group); + if (world_group != MPI_GROUP_NULL) + MPI_Group_free(&world_group); + + MPI_Finalize(); + + if (bases) + free(bases); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig.c b/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig.c index 22e37e1797..db25c332fc 100644 --- a/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig.c +++ b/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig.c @@ -15,14 +15,15 @@ const int verbose = 0; -int main(int argc, char **argv) { - int i, j, rank, nproc; - int shm_rank, shm_nproc; +int main(int argc, char **argv) +{ + int i, j, rank, nproc; + int shm_rank, shm_nproc; MPI_Info alloc_shared_info; - int errors = 0, all_errors = 0; - int disp_unit; - int *my_base; - MPI_Win shm_win; + int errors = 0, all_errors = 0; + int disp_unit; + int *my_base; + MPI_Win shm_win; MPI_Comm shm_comm; MPI_Init(&argc, &argv); @@ -39,8 +40,8 @@ int main(int argc, char **argv) { MPI_Comm_size(shm_comm, &shm_nproc); /* Allocate ELEM_PER_PROC integers for each process */ - MPI_Win_allocate_shared(sizeof(int)*ELEM_PER_PROC, sizeof(int), alloc_shared_info, - shm_comm, &my_base, &shm_win); + MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), alloc_shared_info, + shm_comm, &my_base, &shm_win); MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win); @@ -55,16 +56,16 @@ int main(int argc, char **argv) { /* Read and verify everyone's data */ for (i = 0; i < shm_nproc; i++) { - int *base; - MPI_Aint size; + int *base; + MPI_Aint size; MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &base); assert(size >= ELEM_PER_PROC * sizeof(int)); for (j = 0; j < ELEM_PER_PROC; j++) { - if ( base[j] != j ) { + if (base[j] != j) { errors++; - printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, + printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, base[j], i, j, j); } } diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig_put.c b/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig_put.c index 0e68d2d8a8..e733c874f0 100644 --- a/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig_put.c +++ b/teshsuite/smpi/mpich3-test/rma/win_shared_noncontig_put.c @@ -15,14 +15,15 @@ const int verbose = 0; -int main(int argc, char **argv) { - int i, j, rank, nproc; - int shm_rank, shm_nproc; +int main(int argc, char **argv) +{ + int i, j, rank, nproc; + int shm_rank, shm_nproc; MPI_Info alloc_shared_info; - int errors = 0, all_errors = 0; - int disp_unit; - int *my_base, my_size; - MPI_Win shm_win; + int errors = 0, all_errors = 0; + int disp_unit; + int *my_base, my_size; + MPI_Win shm_win; MPI_Comm shm_comm; MPI_Init(&argc, &argv); @@ -39,26 +40,25 @@ int main(int argc, char **argv) { MPI_Comm_size(shm_comm, &shm_nproc); /* Allocate ELEM_PER_PROC integers on each even rank process */ - my_size = (shm_rank % 2 == 0) ? sizeof(int)*ELEM_PER_PROC : 0; - MPI_Win_allocate_shared(my_size, sizeof(int), alloc_shared_info, - shm_comm, &my_base, &shm_win); + my_size = (shm_rank % 2 == 0) ? sizeof(int) * ELEM_PER_PROC : 0; + MPI_Win_allocate_shared(my_size, sizeof(int), alloc_shared_info, shm_comm, &my_base, &shm_win); for (i = 0; i < ELEM_PER_PROC; i++) { - MPI_Win_fence(MPI_MODE_NOPRECEDE, shm_win); - if (shm_rank % 2 == 0) { - MPI_Put(&i, 1, MPI_INT, - (shm_rank + 2 > shm_nproc) ? 0 : (shm_rank+2) % shm_nproc, - i, 1, MPI_INT, shm_win); - } - MPI_Win_fence(MPI_MODE_NOSUCCEED, shm_win); + MPI_Win_fence(MPI_MODE_NOPRECEDE, shm_win); + if (shm_rank % 2 == 0) { + MPI_Put(&i, 1, MPI_INT, + (shm_rank + 2 > shm_nproc) ? 0 : (shm_rank + 2) % shm_nproc, + i, 1, MPI_INT, shm_win); + } + MPI_Win_fence(MPI_MODE_NOSUCCEED, shm_win); } MPI_Barrier(shm_comm); /* Read and verify everyone's data */ for (i = 0; i < shm_nproc; i++) { - int *base; - MPI_Aint size; + int *base; + MPI_Aint size; MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &base); @@ -66,13 +66,14 @@ int main(int argc, char **argv) { assert(size >= ELEM_PER_PROC * sizeof(int)); for (j = 0; j < ELEM_PER_PROC; j++) { - if ( base[j] != j ) { + if (base[j] != j) { errors++; printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, base[j], i, j, j); } } - } else { + } + else { assert(size == 0); assert(base == NULL); } diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_put_flush_get.c b/teshsuite/smpi/mpich3-test/rma/win_shared_put_flush_get.c new file mode 100644 index 0000000000..5c4cfcf31f --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/win_shared_put_flush_get.c @@ -0,0 +1,199 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +#include +#include +#include +#include "mpitest.h" + +#define ITER 100 +#define BUF_CNT 4 +double local_buf[BUF_CNT], check_buf[BUF_CNT]; + +const int verbose = 0; + +int main(int argc, char *argv[]) +{ + int rank, nproc, i, x; + int errors = 0, all_errors = 0; + MPI_Win win = MPI_WIN_NULL; + + MPI_Comm shm_comm = MPI_COMM_NULL; + int shm_nproc, shm_rank; + double **shm_bases = NULL, *my_base; + MPI_Win shm_win = MPI_WIN_NULL; + MPI_Group shm_group = MPI_GROUP_NULL, world_group = MPI_GROUP_NULL; + int *shm_ranks = NULL, *shm_ranks_in_world = NULL; + MPI_Aint get_target_base_offsets = 0; + + int win_size = sizeof(double) * BUF_CNT; + int new_win_size = win_size; + int win_unit = sizeof(double); + int shm_root_rank_in_world; + int origin = -1, put_target, get_target; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_group(MPI_COMM_WORLD, &world_group); + + if (nproc != 4) { + if (rank == 0) + printf("Error: must be run with four processes\n"); + MPI_Abort(MPI_COMM_WORLD, 1); + } + + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm); + MPI_Comm_rank(shm_comm, &shm_rank); + MPI_Comm_size(shm_comm, &shm_nproc); + MPI_Comm_group(shm_comm, &shm_group); + + /* Platform does not support shared memory or wrong host file, just return. */ + if (shm_nproc != 2) { + goto exit; + } + + shm_bases = (double **) calloc(shm_nproc, sizeof(double *)); + shm_ranks = (int *) calloc(shm_nproc, sizeof(int)); + shm_ranks_in_world = (int *) calloc(shm_nproc, sizeof(int)); + + if (shm_rank == 0) + shm_root_rank_in_world = rank; + MPI_Bcast(&shm_root_rank_in_world, 1, MPI_INT, 0, shm_comm); + + /* Identify ranks of target processes which are located on node 0 */ + if (rank == 0) { + for (i = 0; i < shm_nproc; i++) { + shm_ranks[i] = i; + } + MPI_Group_translate_ranks(shm_group, shm_nproc, shm_ranks, world_group, shm_ranks_in_world); + } + MPI_Bcast(shm_ranks_in_world, shm_nproc, MPI_INT, 0, MPI_COMM_WORLD); + + put_target = shm_ranks_in_world[shm_nproc - 1]; + get_target = shm_ranks_in_world[0]; + + /* Identify the rank of origin process which are located on node 1 */ + if (shm_root_rank_in_world == 1 && shm_rank == 0) { + origin = rank; + if (verbose) { + printf("---- I am origin = %d, get_target = %d, put_target = %d\n", + origin, get_target, put_target); + } + } + + /* Allocate shared memory among local processes */ + MPI_Win_allocate_shared(win_size, win_unit, MPI_INFO_NULL, shm_comm, &my_base, &shm_win); + + if (shm_root_rank_in_world == 0 && verbose) { + MPI_Aint size; + int disp_unit; + for (i = 0; i < shm_nproc; i++) { + MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &shm_bases[i]); + printf("%d -- shared query: base[%d]=%p, size %ld, " + "unit %d\n", rank, i, shm_bases[i], size, disp_unit); + } + } + + /* Get offset of put target(1) on get target(0) */ + get_target_base_offsets = (shm_nproc - 1) * win_size / win_unit; + + if (origin == rank && verbose) + printf("%d -- base_offset of put_target %d on get_target %d: %ld\n", + rank, put_target, get_target, get_target_base_offsets); + + /* Create using MPI_Win_create(). Note that new window size of get_target(0) + * is equal to the total size of shm segments on this node, thus get_target + * process can read the byte located on put_target process.*/ + for (i = 0; i < BUF_CNT; i++) { + local_buf[i] = (i + 1) * 1.0; + my_base[i] = 0.0; + } + + if (get_target == rank) + new_win_size = win_size * shm_nproc; + + MPI_Win_create(my_base, new_win_size, win_unit, MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + if (verbose) + printf("%d -- new window my_base %p, size %d\n", rank, my_base, new_win_size); + + MPI_Barrier(MPI_COMM_WORLD); + + /* Check if flush guarantees the completion of put operations on target side. + * + * P exclusively locks 2 processes whose windows are shared with each other. + * P first put and flush to a process, then get the updated data from another process. + * If flush returns before operations are done on the target side, the data may be + * incorrect.*/ + for (x = 0; x < ITER; x++) { + for (i = 0; i < BUF_CNT; i++) { + local_buf[i] += x; + check_buf[i] = 0; + } + + if (rank == origin) { + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, put_target, 0, win); + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, get_target, 0, win); + + for (i = 0; i < BUF_CNT; i++) { + MPI_Put(&local_buf[i], 1, MPI_DOUBLE, put_target, i, 1, MPI_DOUBLE, win); + } + MPI_Win_flush(put_target, win); + + MPI_Get(check_buf, BUF_CNT, MPI_DOUBLE, get_target, + get_target_base_offsets, BUF_CNT, MPI_DOUBLE, win); + MPI_Win_flush(get_target, win); + + for (i = 0; i < BUF_CNT; i++) { + if (check_buf[i] != local_buf[i]) { + printf("%d(iter %d) - Got check_buf[%d] = %.1lf, expected %.1lf\n", + rank, x, i, check_buf[i], local_buf[i]); + errors++; + } + } + + MPI_Win_unlock(put_target, win); + MPI_Win_unlock(get_target, win); + } + } + + MPI_Barrier(MPI_COMM_WORLD); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + exit: + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + if (shm_bases) + free(shm_bases); + if (shm_ranks) + free(shm_ranks); + if (shm_ranks_in_world) + free(shm_ranks_in_world); + + if (shm_win != MPI_WIN_NULL) + MPI_Win_free(&shm_win); + + if (win != MPI_WIN_NULL) + MPI_Win_free(&win); + + if (shm_comm != MPI_COMM_NULL) + MPI_Comm_free(&shm_comm); + + if (shm_group != MPI_GROUP_NULL) + MPI_Group_free(&shm_group); + + if (world_group != MPI_GROUP_NULL) + MPI_Group_free(&world_group); + + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_rma_flush_load.c b/teshsuite/smpi/mpich3-test/rma/win_shared_rma_flush_load.c new file mode 100644 index 0000000000..1386fcdfa0 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/win_shared_rma_flush_load.c @@ -0,0 +1,299 @@ +/* -*- 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 ITER 10000 +#define BUF_CNT 1 +int local_buf[BUF_CNT], result_addr[BUF_CNT]; +#ifdef TEST_CAS +int compare_buf[BUF_CNT]; +#endif + +const int verbose = 0; + +/* This test checks the remote completion of flush with RMA write-like operations + * (PUT, ACC, GET_ACC, FOP, CAS), and confirms result by shm load. + * 1. P(target) and P(checker) allocate a shared window, and + * then create a global window with P(origin) by using the shared window buffer. + * 2. P(origin) issues RMA operations and flush to P(target) through the global + * window and then call send-recv to synchronize with P(checker). + * 3. P(checker) then checks the result through shm window by local load. */ + +int rank = -1, nproc = 0; +int origin = -1, target = -1, checker = -1; +MPI_Win win = MPI_WIN_NULL, shm_win = MPI_WIN_NULL; +int *shm_target_base = NULL, *my_base = NULL; + +/* Define operation name for error message */ +#ifdef TEST_PUT +const char *rma_name = "Put"; +#elif defined(TEST_ACC) +const char *rma_name = "Accumulate"; +#elif defined(TEST_GACC) +const char *rma_name = "Get_accumulate"; +#elif defined(TEST_FOP) +const char *rma_name = "Fetch_and_op"; +#elif defined(TEST_CAS) +const char *rma_name = "Compare_and_swap"; +#else +const char *rma_name = "None"; +#endif + +/* Issue functions for different RMA operations */ +#ifdef TEST_PUT +static inline void issue_rma_op(int i) +{ + MPI_Put(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, win); +} +#elif defined(TEST_ACC) +static inline void issue_rma_op(int i) +{ + MPI_Accumulate(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, MPI_REPLACE, win); +} +#elif defined(TEST_GACC) +static inline void issue_rma_op(int i) +{ + MPI_Get_accumulate(&local_buf[i], 1, MPI_INT, &result_addr[i], 1, MPI_INT, target, i, + 1, MPI_INT, MPI_REPLACE, win); +} +#elif defined(TEST_FOP) +static inline void issue_rma_op(int i) +{ + MPI_Fetch_and_op(&local_buf[i], &result_addr[i], MPI_INT, target, i, MPI_REPLACE, win); +} +#elif defined(TEST_CAS) +static inline void issue_rma_op(int i) +{ + compare_buf[i] = i; /* always equal to window value, thus swap happens */ + MPI_Compare_and_swap(&local_buf[i], &compare_buf[i], &result_addr[i], MPI_INT, target, i, win); +} +#endif + + +/* Local check function for GET-like operations */ +#if defined(TEST_GACC) || defined(TEST_FOP) || defined(TEST_CAS) + +/* Check local result buffer for GET-like operations */ +static int check_local_result(int iter) +{ + int i = 0; + int errors = 0; + + for (i = 0; i < BUF_CNT; i++) { + if (result_addr[i] != i) { + printf("rank %d (iter %d) - check %s, got result_addr[%d] = %d, expected %d\n", + rank, iter, rma_name, i, result_addr[i], i); + errors++; + } + } + return errors; +} + +#else +#define check_local_result(iter) (0) +#endif + +static int run_test() +{ + int i = 0, x = 0; + int errors = 0; + int sbuf = 0, rbuf = 0; + MPI_Status stat; + + for (x = 0; x < ITER; x++) { + /* 1. Target resets window data */ + if (rank == target) { + for (i = 0; i < BUF_CNT; i++) + my_base[i] = i; + MPI_Win_sync(shm_win); /* write is done on shm window */ + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* 2. Every one resets local data */ + for (i = 0; i < BUF_CNT; i++) { + local_buf[i] = BUF_CNT + x * BUF_CNT + i; + result_addr[i] = 0; + } + + /* 3. Origin issues RMA operation to target */ + if (rank == origin) { + /* 3-1. Issue RMA. */ + for (i = 0; i < BUF_CNT; i++) { + issue_rma_op(i); + } + MPI_Win_flush(target, win); + + /* 3-2. Check local result buffer. */ + errors += check_local_result(x); + + /* sync with checker */ + MPI_Send(&sbuf, 1, MPI_INT, checker, 999, MPI_COMM_WORLD); + } + + /* 4. Checker confirms result on target */ + if (rank == checker) { + /* sync with origin */ + MPI_Recv(&rbuf, 1, MPI_INT, origin, 999, MPI_COMM_WORLD, &stat); + + MPI_Win_sync(shm_win); + + for (i = 0; i < BUF_CNT; i++) { + if (shm_target_base[i] != local_buf[i]) { + printf("rank %d (iter %d) - check %s, got shm_target_base[%d] = %d, " + "expected %d\n", rank, x, rma_name, i, shm_target_base[i], local_buf[i]); + errors++; + } + } + } + + MPI_Barrier(MPI_COMM_WORLD); + } + + return errors; +} + +int main(int argc, char *argv[]) +{ + int i; + int errors = 0, all_errors = 0; + MPI_Comm shm_comm = MPI_COMM_NULL; + int shm_rank; + int *shm_ranks = NULL, *shm_root_ranks = NULL; + int win_size = sizeof(int) * BUF_CNT; + int win_unit = sizeof(int); + int shm_root_rank = -1, shm_target = -1, target_shm_root = -1; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + if (nproc != 3) { + if (rank == 0) + printf("Error: must be run with three processes\n"); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Abort(MPI_COMM_WORLD, 1); + } + +#if !defined(TEST_PUT) && !defined(TEST_ACC) && !defined(TEST_GACC) && !defined(TEST_FOP) && !defined(TEST_CAS) + if (rank == 0) + printf("Error: must specify operation type at compile time\n"); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Abort(MPI_COMM_WORLD, 1); +#endif + + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm); + MPI_Comm_rank(shm_comm, &shm_rank); + + shm_ranks = (int *) calloc(nproc, sizeof(int)); + shm_root_ranks = (int *) calloc(nproc, sizeof(int)); + + /* Identify node id */ + if (shm_rank == 0) + shm_root_rank = rank; + MPI_Bcast(&shm_root_rank, 1, MPI_INT, 0, shm_comm); + + /* Exchange local root rank and local rank */ + shm_ranks[rank] = shm_rank; + shm_root_ranks[rank] = shm_root_rank; + + MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, shm_ranks, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, shm_root_ranks, 1, MPI_INT, MPI_COMM_WORLD); + + /* Check if there are at least two processes in shared memory. */ + for (i = 0; i < nproc; i++) { + if (shm_ranks[i] != 0) { + target_shm_root = shm_root_ranks[i]; + break; + } + } + + /* Every process is in separate memory, we cannot create shared window. Just return. */ + if (target_shm_root < 0) + goto exit; + + /* Identify origin, target and checker ranks. + * the first process in shared memory is target, and the second one is checker; + * the last process is origin.*/ + shm_target = 0; + for (i = 0; i < nproc; i++) { + if (shm_root_ranks[i] == target_shm_root) { + if (shm_ranks[i] == 0) { + target = i; + } + else if (shm_ranks[i] == 1) { + checker = i; + } + else { + /* all three processes are in shared memory, origin is the third one. */ + origin = i; + } + } + else { + /* origin is in separate memory. */ + origin = i; + } + } + + if (verbose) { + printf("---- rank %d: origin = %d, checker = %d, target = %d, test %s\n", + rank, origin, checker, target, rma_name); + } + + /* Allocate shared memory among local processes, then create a global window + * with the shared window buffers. */ + MPI_Win_allocate_shared(win_size, win_unit, MPI_INFO_NULL, shm_comm, &my_base, &shm_win); + MPI_Win_create(my_base, win_size, win_unit, MPI_INFO_NULL, MPI_COMM_WORLD, &win); + + /* Get address of target window on checker process. */ + if (rank == checker) { + MPI_Aint size; + int disp_unit; + MPI_Win_shared_query(shm_win, shm_target, &size, &disp_unit, &shm_target_base); + if (verbose) { + printf("---- I am checker = %d, shm_target_base=%p\n", checker, shm_target_base); + } + } + + /* Start checking. */ + MPI_Win_lock_all(0, win); + MPI_Win_lock_all(0, shm_win); + + errors = run_test(); + + MPI_Win_unlock_all(shm_win); + MPI_Win_unlock_all(win); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + exit: + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + if (shm_ranks) + free(shm_ranks); + if (shm_root_ranks) + free(shm_root_ranks); + + if (shm_win != MPI_WIN_NULL) + MPI_Win_free(&shm_win); + + if (win != MPI_WIN_NULL) + MPI_Win_free(&win); + + if (shm_comm != MPI_COMM_NULL) + MPI_Comm_free(&shm_comm); + + MPI_Finalize(); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_zerobyte.c b/teshsuite/smpi/mpich3-test/rma/win_shared_zerobyte.c new file mode 100644 index 0000000000..2b17d79d95 --- /dev/null +++ b/teshsuite/smpi/mpich3-test/rma/win_shared_zerobyte.c @@ -0,0 +1,116 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ + +#include +#include +#include +#include +#include "mpitest.h" + +const int verbose = 0; + +int main(int argc, char **argv) +{ + int i, rank, nproc; + int shm_rank, shm_nproc; + MPI_Aint size; + int errors = 0, all_errors = 0; + int **bases = NULL, *abs_base, *my_base; + int disp_unit; + MPI_Win shm_win; + MPI_Comm shm_comm; + int ELEM_PER_PROC = 0; + + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm); + + MPI_Comm_rank(shm_comm, &shm_rank); + MPI_Comm_size(shm_comm, &shm_nproc); + + /* Platform does not support shared memory, just return. */ + if (shm_nproc < 2) { + goto exit; + } + + bases = calloc(shm_nproc, sizeof(int *)); + + if (shm_rank == 0 || shm_rank == shm_nproc - 1) { + ELEM_PER_PROC = 16; + } + + /* Allocate ELEM_PER_PROC integers for each process */ + MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL, + shm_comm, &my_base, &shm_win); + + /* Locate absolute base */ + MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &size, &disp_unit, &abs_base); + + if (verbose) + printf("%d -- allocate shared: my_base = %p, absolute base = %p\n", shm_rank, my_base, + abs_base); + + for (i = 0; i < shm_nproc; i++) { + MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &bases[i]); + if (verbose) + printf("%d -- shared query: base[%d]=%p, size %ld, unit %d\n", + shm_rank, i, bases[i], size, disp_unit); + } + + MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win); + + /* Reset data */ + for (i = 0; i < ELEM_PER_PROC; i++) { + my_base[i] = 0; + } + + MPI_Win_sync(shm_win); + MPI_Barrier(shm_comm); + MPI_Win_sync(shm_win); + + /* Read and verify everyone's data */ + if (shm_rank == 0) { + bases[0][0] = 1; + } + + MPI_Win_sync(shm_win); + MPI_Barrier(shm_comm); + MPI_Win_sync(shm_win); + + if (bases[0][0] != 1) { + errors++; + printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, bases[0][0], 0, 0, 1); + } + + if (bases[shm_nproc - 1][0] != 0) { + errors++; + printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, + bases[shm_nproc - 1][0], shm_nproc - 1, 0, 0); + } + + MPI_Win_unlock_all(shm_win); + MPI_Win_free(&shm_win); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + + exit: + + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + MPI_Comm_free(&shm_comm); + + MPI_Finalize(); + + if (bases) + free(bases); + + return 0; +} diff --git a/teshsuite/smpi/mpich3-test/rma/wincall.c b/teshsuite/smpi/mpich3-test/rma/wincall.c index c29b7966fd..06a88231f6 100644 --- a/teshsuite/smpi/mpich3-test/rma/wincall.c +++ b/teshsuite/smpi/mpich3-test/rma/wincall.c @@ -15,51 +15,51 @@ static char MTEST_Descrip[] = "Test win_call_errhandler"; static int calls = 0; static int errs = 0; static MPI_Win mywin; -void eh( MPI_Win *win, int *err, ... ); -void eh( MPI_Win *win, int *err, ... ) +void eh(MPI_Win * win, int *err, ...); +void eh(MPI_Win * win, int *err, ...) { if (*err != MPI_ERR_OTHER) { - errs++; - printf( "Unexpected error code\n" ); + errs++; + printf("Unexpected error code\n"); } if (*win != mywin) { - errs++; - printf( "Unexpected window\n" ); + errs++; + printf("Unexpected window\n"); } calls++; return; } -int main( int argc, char *argv[] ) + +int main(int argc, char *argv[]) { int buf[2]; - MPI_Win win; + MPI_Win win; MPI_Errhandler newerr; - int i; + int i; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); /* Run this test multiple times to expose storage leaks (we found a leak - of error handlers with this test) */ - for (i=0;i<1000; i++) { - calls = 0; - - MPI_Win_create( buf, 2*sizeof(int), sizeof(int), - MPI_INFO_NULL, MPI_COMM_WORLD, &win ); - mywin = win; - - MPI_Win_create_errhandler( eh, &newerr ); - - MPI_Win_set_errhandler( win, newerr ); - MPI_Win_call_errhandler( win, MPI_ERR_OTHER ); - MPI_Errhandler_free( &newerr ); - if (calls != 1) { - errs++; - printf( "Error handler not called\n" ); - } - MPI_Win_free( &win ); + * of error handlers with this test) */ + for (i = 0; i < 1000; i++) { + calls = 0; + + MPI_Win_create(buf, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); + mywin = win; + + MPI_Win_create_errhandler(eh, &newerr); + + MPI_Win_set_errhandler(win, newerr); + MPI_Win_call_errhandler(win, MPI_ERR_OTHER); + MPI_Errhandler_free(&newerr); + if (calls != 1) { + errs++; + printf("Error handler not called\n"); + } + MPI_Win_free(&win); } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/window_creation.c b/teshsuite/smpi/mpich3-test/rma/window_creation.c index a805350eb1..f96501c058 100644 --- a/teshsuite/smpi/mpich3-test/rma/window_creation.c +++ b/teshsuite/smpi/mpich3-test/rma/window_creation.c @@ -15,39 +15,47 @@ static int verbose = 0; -int main(int argc, char ** argv) { - int rank, nproc, i; - void *base_ptrs[NUM_WIN]; - MPI_Win windows[NUM_WIN]; +int main(int argc, char **argv) +{ + int rank, nproc, i; + void *base_ptrs[NUM_WIN]; + MPI_Win windows[NUM_WIN]; - MPI_Init(&argc, &argv); + MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &nproc); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); - if (rank == 0) if (verbose) printf("Starting MPI window creation test with %d processes\n", nproc); + if (rank == 0) + if (verbose) + printf("Starting MPI window creation test with %d processes\n", nproc); - /* Perform a pile of window creations */ - for (i = 0; i < NUM_WIN; i++) { - if (rank == 0) if (verbose) printf(" + Creating window %d\n", i); + /* Perform a pile of window creations */ + for (i = 0; i < NUM_WIN; i++) { + if (rank == 0) + if (verbose) + printf(" + Creating window %d\n", i); - MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptrs[i]); - MPI_Win_create(base_ptrs[i], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[i]); - } + MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptrs[i]); + MPI_Win_create(base_ptrs[i], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[i]); + } - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - /* Free all the windows */ - for (i = 0; i < NUM_WIN; i++) { - if (rank == 0) if (verbose) printf(" + Freeing window %d\n", i); + /* Free all the windows */ + for (i = 0; i < NUM_WIN; i++) { + if (rank == 0) + if (verbose) + printf(" + Freeing window %d\n", i); - MPI_Win_free(&windows[i]); - MPI_Free_mem(base_ptrs[i]); - } + MPI_Win_free(&windows[i]); + MPI_Free_mem(base_ptrs[i]); + } - if (rank == 0) printf(" No Errors\n"); + if (rank == 0) + printf(" No Errors\n"); - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/winname.c b/teshsuite/smpi/mpich3-test/rma/winname.c index 290f26e260..dfffb15047 100644 --- a/teshsuite/smpi/mpich3-test/rma/winname.c +++ b/teshsuite/smpi/mpich3-test/rma/winname.c @@ -14,34 +14,34 @@ #include #endif -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int errs = 0; MPI_Win win; int cnt, namelen; char name[MPI_MAX_OBJECT_NAME], nameout[MPI_MAX_OBJECT_NAME]; - MTest_Init( &argc, &argv ); + MTest_Init(&argc, &argv); cnt = 0; - while (MTestGetWin( &win, 1 )) { - if (win == MPI_WIN_NULL) continue; - - sprintf( name, "win-%d", cnt ); - cnt++; - MPI_Win_set_name( win, name ); - nameout[0] = 0; - MPI_Win_get_name( win, nameout, &namelen ); - if (strcmp( name, nameout )) { - errs++; - printf( "Unexpected name, was %s but should be %s\n", - nameout, name ); - } + while (MTestGetWin(&win, 1)) { + if (win == MPI_WIN_NULL) + continue; - MTestFreeWin( &win ); + sprintf(name, "win-%d", cnt); + cnt++; + MPI_Win_set_name(win, name); + nameout[0] = 0; + MPI_Win_get_name(win, nameout, &namelen); + if (strcmp(name, nameout)) { + errs++; + printf("Unexpected name, was %s but should be %s\n", nameout, name); + } + + MTestFreeWin(&win); } - MTest_Finalize( errs ); + MTest_Finalize(errs); MPI_Finalize(); return 0; } diff --git a/teshsuite/smpi/mpich3-test/rma/wintest.c b/teshsuite/smpi/mpich3-test/rma/wintest.c index a8a784c3ad..d28f806cca 100644 --- a/teshsuite/smpi/mpich3-test/rma/wintest.c +++ b/teshsuite/smpi/mpich3-test/rma/wintest.c @@ -3,7 +3,7 @@ * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ -#include "mpi.h" +#include "mpi.h" #include "stdio.h" #include "mpitest.h" @@ -13,17 +13,17 @@ #define SIZE1 10 #define SIZE2 20 -int main(int argc, char *argv[]) -{ - int rank, destrank, nprocs, A[SIZE2], B[SIZE2], i; +int main(int argc, char *argv[]) +{ + int rank, destrank, nprocs, A[SIZE2], i; MPI_Comm CommDeuce; MPI_Group comm_group, group; MPI_Win win; int errs = 0, flag; - MTest_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD,&nprocs); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MTest_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { printf("Run this program with 2 or more processes\n"); @@ -36,27 +36,44 @@ int main(int argc, char *argv[]) MPI_Comm_group(CommDeuce, &comm_group); if (rank == 0) { - for (i=0; i +#include +#include +#include "mpitest.h" + +#define ITER 10000 +#define BUF_CNT 1 +int local_buf[BUF_CNT], result_addr[BUF_CNT], check_addr[BUF_CNT]; +#ifdef TEST_CAS +int compare_buf[BUF_CNT]; +#endif + +const int verbose = 0; + +/* This test checks the remote completion of flush with RMA write-like operations + * (PUT, ACC, GET_ACC, FOP, CAS), and confirms result by GET issued from another + * process. + * 1. Three processes create window by Win_allocate. + * 2. P(origin) issues RMA operations and flush to P(target), then call + * send-recv to synchronize with P(checker). + * 3. P(checker) then issues get to P(target) to check the results. + */ + +int rank = -1, nproc = 0; +int origin = -1, target = -1, checker = -1; +MPI_Win win = MPI_WIN_NULL; +int *my_base = NULL; + +/* Define operation name for error message */ +#ifdef TEST_PUT +const char *rma_name = "Put"; +#elif defined(TEST_ACC) +const char *rma_name = "Accumulate"; +#elif defined(TEST_GACC) +const char *rma_name = "Get_accumulate"; +#elif defined(TEST_FOP) +const char *rma_name = "Fetch_and_op"; +#elif defined(TEST_CAS) +const char *rma_name = "Compare_and_swap"; +#else +const char *rma_name = "None"; +#endif + +/* Issue functions for different RMA operations */ +#ifdef TEST_PUT +static inline void issue_rma_op(int i) +{ + MPI_Put(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, win); +} +#elif defined(TEST_ACC) +static inline void issue_rma_op(int i) +{ + MPI_Accumulate(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, MPI_REPLACE, win); +} +#elif defined(TEST_GACC) +static inline void issue_rma_op(int i) +{ + MPI_Get_accumulate(&local_buf[i], 1, MPI_INT, &result_addr[i], 1, MPI_INT, target, i, + 1, MPI_INT, MPI_REPLACE, win); +} +#elif defined(TEST_FOP) +static inline void issue_rma_op(int i) +{ + MPI_Fetch_and_op(&local_buf[i], &result_addr[i], MPI_INT, target, i, MPI_REPLACE, win); +} +#elif defined(TEST_CAS) +static inline void issue_rma_op(int i) +{ + compare_buf[i] = i; /* always equal to window value, thus swap happens */ + MPI_Compare_and_swap(&local_buf[i], &compare_buf[i], &result_addr[i], MPI_INT, target, i, win); +} +#endif + + +/* Local check function for GET-like operations */ +#if defined(TEST_GACC) || defined(TEST_FOP) || defined(TEST_CAS) + +/* Check local result buffer for GET-like operations */ +static int check_local_result(int iter) +{ + int i = 0; + int errors = 0; + + for (i = 0; i < BUF_CNT; i++) { + if (result_addr[i] != i) { + printf("rank %d (iter %d) - check %s, got result_addr[%d] = %d, expected %d\n", + rank, iter, rma_name, i, result_addr[i], i); + errors++; + } + } + return errors; +} + +#else +#define check_local_result(iter) (0) +#endif + +static int run_test() +{ + int i = 0, x = 0; + int errors = 0; + int sbuf = 0, rbuf = 0; + MPI_Status stat; + + for (x = 0; x < ITER; x++) { + /* 1. Target resets window data */ + if (rank == target) { + for (i = 0; i < BUF_CNT; i++) + my_base[i] = i; + MPI_Win_sync(win); /* write is done on window */ + } + + MPI_Barrier(MPI_COMM_WORLD); + + /* 2. Every one resets local data */ + for (i = 0; i < BUF_CNT; i++) { + local_buf[i] = BUF_CNT + x * BUF_CNT + i; + result_addr[i] = 0; + } + + /* 3. Origin issues RMA operation to target */ + if (rank == origin) { + /* 3-1. Issue RMA. */ + for (i = 0; i < BUF_CNT; i++) { + issue_rma_op(i); + } + MPI_Win_flush(target, win); + + /* 3-2. Sync with checker */ + MPI_Send(&sbuf, 1, MPI_INT, checker, 999, MPI_COMM_WORLD); + + /* 3-3. Check local result buffer */ + errors += check_local_result(x); + } + + /* 4. Checker issues GET to target and checks result */ + if (rank == checker) { + /* 4-1. Sync with origin */ + MPI_Recv(&rbuf, 1, MPI_INT, origin, 999, MPI_COMM_WORLD, &stat); + + /* 4-2. Get result and check */ + MPI_Get(check_addr, BUF_CNT, MPI_INT, target, 0, BUF_CNT, MPI_INT, win); + MPI_Win_flush(target, win); + + for (i = 0; i < BUF_CNT; i++) { + if (check_addr[i] != local_buf[i]) { + printf("rank %d (iter %d) - check %s, got check_addr[%d] = %d, expected %d\n", + rank, x, rma_name, i, check_addr[i], local_buf[i]); + errors++; + } + } + } + + MPI_Barrier(MPI_COMM_WORLD); + } + + return errors; +} + +int main(int argc, char *argv[]) +{ + int errors = 0, all_errors = 0; + int win_size = sizeof(int) * BUF_CNT; + int win_unit = sizeof(int); + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + if (nproc != 3) { + if (rank == 0) + printf("Error: must be run with three processes\n"); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Abort(MPI_COMM_WORLD, 1); + } + +#if !defined(TEST_PUT) && !defined(TEST_ACC) && !defined(TEST_GACC) && !defined(TEST_FOP) && !defined(TEST_CAS) + if (rank == 0) + printf("Error: must specify operation type at compile time\n"); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Abort(MPI_COMM_WORLD, 1); +#endif + + /* Identify origin, target and checker ranks. */ + target = 0; + checker = 2; + origin = 1; + + MPI_Win_allocate(win_size, win_unit, MPI_INFO_NULL, MPI_COMM_WORLD, &my_base, &win); + + /* Start checking. */ + MPI_Win_lock_all(0, win); + + errors = run_test(); + + MPI_Win_unlock_all(win); + + MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + if (rank == 0 && all_errors == 0) + printf(" No Errors\n"); + + if (win != MPI_WIN_NULL) + MPI_Win_free(&win); + + MPI_Finalize(); + + return 0; +}