1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2013 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
14 #include "mcs-mutex.h"
19 const int verbose = 0;
20 double delay_ctr = 0.0;
22 int main(int argc, char **argv)
29 MPI_Init(&argc, &argv);
31 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
35 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &mtx_comm);
37 mtx_comm = MPI_COMM_WORLD;
40 MCS_Mutex_create(0, mtx_comm, &mcs_mtx);
42 MPI_Barrier(MPI_COMM_WORLD);
43 t_mcs_mtx = MPI_Wtime();
45 for (i = 0; i < NUM_ITER; i++) {
46 /* Combining trylock and lock here is helpful for testing because it makes
47 * CAS and Fetch-and-op contend for the tail pointer. */
48 #ifdef USE_CONTIGUOUS_RANK
49 if (rank < nproc / 2) {
55 MCS_Mutex_trylock(mcs_mtx, &success);
59 MCS_Mutex_lock(mcs_mtx);
61 MCS_Mutex_unlock(mcs_mtx);
64 MPI_Barrier(MPI_COMM_WORLD);
65 t_mcs_mtx = MPI_Wtime() - t_mcs_mtx;
67 MCS_Mutex_free(&mcs_mtx);
71 printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx / NUM_ITER * 1.0e6);
75 if (mtx_comm != MPI_COMM_WORLD)
76 MPI_Comm_free(&mtx_comm);