X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/826897d361add5db3272a9810e70371a40ba1660..8bd25d18b5b13783fe7fa8e1c7b3961f2bf5e0dc:/teshsuite/smpi/mpich3-test/rma/mutex_bench.c diff --git a/teshsuite/smpi/mpich3-test/rma/mutex_bench.c b/teshsuite/smpi/mpich3-test/rma/mutex_bench.c index 2db24e41af..a5cf508d4b 100644 --- a/teshsuite/smpi/mpich3-test/rma/mutex_bench.c +++ b/teshsuite/smpi/mpich3-test/rma/mutex_bench.c @@ -1,12 +1,10 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ /* - * Copyright (C) 2013. See COPYRIGHT in top-level directory. + * + * (C) 2013 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. */ -/** MPI Mutex test -- James Dinan - * - * All processes create a mutex then lock+unlock it N times. - */ - #include #include #include @@ -21,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; }