-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathatomic_fetch_inc.c
69 lines (57 loc) · 1.43 KB
/
atomic_fetch_inc.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
/* atomic_fetch_inc.c
*
* Copyright (c) 2016 U.S. Army Research Laboratory. All rights reserved.
* Copyright (c) 2019 Brown Deer Technology, LLC. All rights reserved.
*
* This file is part of the ARL OpenSHMEM Reference Implementation software
* package. For license information, see the LICENSE file in the top level
* directory of the distribution.
*
*/
/*
* Performance test for shmem_int_atomic_fetch_inc
*/
#include <stdio.h>
#include <shmem.h>
#include "ctimer.h"
#define NLOOP 10000
int main (void)
{
int i, npe;
static int dest;
static unsigned int t, tsum;
static int pWrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE];
static long pSync[SHMEM_REDUCE_SYNC_SIZE];
for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) {
pSync[i] = SHMEM_SYNC_VALUE;
}
shmem_init();
int me = shmem_my_pe();
int npes = shmem_n_pes();
if (me == 0) {
printf("# SHMEM Atomic Fetch-and-Increment Performance"
" for variable NPES\n"
"# NPES\tLatency (nanoseconds)\n");
}
for (npe = 2; npe <= npes; npe++)
{
int nxtpe = me + 1;
if (nxtpe >= npe) nxtpe -= npe;
shmem_barrier_all();
ctimer_start();
if (me < npe) {
t = ctimer();
for (i = 0; i < NLOOP; i++) {
shmem_int_atomic_fetch_inc(&dest, nxtpe);
}
t -= ctimer();
shmem_int_sum_to_all(&tsum, &t, 1, 0, 0, npe, pWrk, pSync);
}
if (me == 0) {
unsigned int nsec = ctimer_nsec(tsum / (npe * NLOOP));
printf("%5d %7u\n", npe, nsec);
}
}
shmem_finalize();
return 0;
}