2 * Copyright (C) 2013. See COPYRIGHT in top-level directory.
5 /** MPI Mutex test -- James Dinan <dinan@mcs.anl.gov>
7 * All processes create a mutex then lock+unlock it N times.
16 #include "mcs-mutex.h"
21 const int verbose = 0;
22 double delay_ctr = 0.0;
24 int main(int argc, char ** argv) {
26 double t_mpix_mtx, t_mcs_mtx;
30 MPI_Init(&argc, &argv);
32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
36 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank,
37 MPI_INFO_NULL, &mtx_comm);
39 mtx_comm = MPI_COMM_WORLD;
42 MCS_Mutex_create(0, mtx_comm, &mcs_mtx);
44 MPI_Barrier(MPI_COMM_WORLD);
45 t_mcs_mtx = MPI_Wtime();
47 for (i = 0; i < NUM_ITER; i++) {
48 /* Combining trylock and lock here is helpful for testing because it makes
49 * CAS and Fetch-and-op contend for the tail pointer. */
53 MCS_Mutex_trylock(mcs_mtx, &success);
57 MCS_Mutex_lock(mcs_mtx);
59 MCS_Mutex_unlock(mcs_mtx);
62 MPI_Barrier(MPI_COMM_WORLD);
63 t_mcs_mtx = MPI_Wtime() - t_mcs_mtx;
65 MCS_Mutex_free(&mcs_mtx);
69 printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx/NUM_ITER*1.0e6);
73 if (mtx_comm != MPI_COMM_WORLD)
74 MPI_Comm_free(&mtx_comm);