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.
8 /** MPI Mutex test -- James Dinan <dinan@mcs.anl.gov>
10 * All processes create a mutex then lock+unlock it N times.
19 #include "mcs-mutex.h"
24 const int verbose = 0;
25 double delay_ctr = 0.0;
27 int main(int argc, char ** argv) {
29 double t_mpix_mtx, t_mcs_mtx;
33 MPI_Init(&argc, &argv);
35 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
39 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank,
40 MPI_INFO_NULL, &mtx_comm);
42 mtx_comm = MPI_COMM_WORLD;
45 MCS_Mutex_create(0, mtx_comm, &mcs_mtx);
47 MPI_Barrier(MPI_COMM_WORLD);
48 t_mcs_mtx = MPI_Wtime();
50 for (i = 0; i < NUM_ITER; i++) {
51 /* Combining trylock and lock here is helpful for testing because it makes
52 * CAS and Fetch-and-op contend for the tail pointer. */
56 MCS_Mutex_trylock(mcs_mtx, &success);
60 MCS_Mutex_lock(mcs_mtx);
62 MCS_Mutex_unlock(mcs_mtx);
65 MPI_Barrier(MPI_COMM_WORLD);
66 t_mcs_mtx = MPI_Wtime() - t_mcs_mtx;
68 MCS_Mutex_free(&mcs_mtx);
72 printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx/NUM_ITER*1.0e6);
76 if (mtx_comm != MPI_COMM_WORLD)
77 MPI_Comm_free(&mtx_comm);