File: test_mutex_trylock.c

package info (click to toggle)
armci-mpi 0.0~git20160222-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,756 kB
  • sloc: ansic: 12,698; sh: 229; makefile: 53; fortran: 44
file content (56 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (C) 2010. See COPYRIGHT in top-level directory.
 */

/** ARMCI Mutex test -- James Dinan <dinan@mcs.anl.gov>
  * 
  * All processes create N mutexes then lock+unlock all mutexes on all
  * processes.  Locking is accomplished via trylock in a loop.
  */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>

#include <mpi.h>
#include <armci.h>
#include <armcix.h>

#define NUM_MUTEXES 10

int main(int argc, char ** argv) {
  int rank, nproc, i, j;
  armcix_mutex_hdl_t mhdl;
  ARMCI_Group world_group;

  MPI_Init(&argc, &argv);
  ARMCI_Init();

  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &nproc);

  if (rank == 0) printf("Starting ARMCIX mutex test with %d processes\n", nproc);

  ARMCI_Group_get_world(&world_group);
  mhdl = ARMCIX_Create_mutexes_hdl(NUM_MUTEXES, &world_group);

  for (i = 0; i < nproc; i++)
    for (j = 0; j < NUM_MUTEXES; j++) {
      while (ARMCIX_Trylock_hdl(mhdl, j, (rank+i)%nproc))
        ;
      ARMCIX_Unlock_hdl(mhdl, j, (rank+i)%nproc);
    }

  printf(" + %3d done\n", rank);
  fflush(NULL);

  ARMCIX_Destroy_mutexes_hdl(mhdl);

  if (rank == 0) printf("Test complete: PASS.\n");

  ARMCI_Finalize();
  MPI_Finalize();

  return 0;
}