1
2
3
4
5
6
7
8
9
10 #include "oshmem_config.h"
11
12 #include "oshmem/constants.h"
13 #include "oshmem/include/shmem.h"
14 #include "oshmem/include/shmemx.h"
15
16 #include "oshmem/runtime/runtime.h"
17
18 #include "oshmem/op/op.h"
19 #include "oshmem/mca/atomic/atomic.h"
20
21
22
23
24
25
26
27 #define DO_SHMEM_TYPE_ATOMIC_FETCH(ctx, type_name, type, target, pe, out_value) do { \
28 int rc = OSHMEM_SUCCESS; \
29 size_t size = 0; \
30 type value = 0; \
31 \
32 RUNTIME_CHECK_INIT(); \
33 RUNTIME_CHECK_PE(pe); \
34 RUNTIME_CHECK_ADDR(target); \
35 \
36 size = sizeof(out_value); \
37 rc = MCA_ATOMIC_CALL(fadd( \
38 ctx, \
39 (void*)target, \
40 (void*)&out_value, \
41 value, \
42 size, \
43 pe)); \
44 RUNTIME_CHECK_RC(rc); \
45 } while (0)
46
47 #define SHMEM_CTX_TYPE_ATOMIC_FETCH(type_name, type, prefix) \
48 type prefix##_ctx##type_name##_atomic_fetch(shmem_ctx_t ctx, const type *target, int pe) \
49 { \
50 type out_value; \
51 DO_SHMEM_TYPE_ATOMIC_FETCH(ctx, type_name, type, target, \
52 pe, out_value); \
53 return out_value; \
54 }
55
56 #define SHMEM_TYPE_ATOMIC_FETCH(type_name, type, prefix) \
57 type prefix##type_name##_atomic_fetch(const type *target, int pe) \
58 { \
59 type out_value; \
60 DO_SHMEM_TYPE_ATOMIC_FETCH(oshmem_ctx_default, type_name, \
61 type, target, pe, out_value); \
62 \
63 return out_value; \
64 }
65
66 #if OSHMEM_PROFILING
67 #include "oshmem/include/pshmem.h"
68 #pragma weak shmem_ctx_int_atomic_fetch = pshmem_ctx_int_atomic_fetch
69 #pragma weak shmem_ctx_long_atomic_fetch = pshmem_ctx_long_atomic_fetch
70 #pragma weak shmem_ctx_longlong_atomic_fetch = pshmem_ctx_longlong_atomic_fetch
71 #pragma weak shmem_ctx_uint_atomic_fetch = pshmem_ctx_uint_atomic_fetch
72 #pragma weak shmem_ctx_ulong_atomic_fetch = pshmem_ctx_ulong_atomic_fetch
73 #pragma weak shmem_ctx_ulonglong_atomic_fetch = pshmem_ctx_ulonglong_atomic_fetch
74 #pragma weak shmem_ctx_double_atomic_fetch = pshmem_ctx_double_atomic_fetch
75 #pragma weak shmem_ctx_float_atomic_fetch = pshmem_ctx_float_atomic_fetch
76
77 #pragma weak shmem_int_atomic_fetch = pshmem_int_atomic_fetch
78 #pragma weak shmem_long_atomic_fetch = pshmem_long_atomic_fetch
79 #pragma weak shmem_longlong_atomic_fetch = pshmem_longlong_atomic_fetch
80 #pragma weak shmem_uint_atomic_fetch = pshmem_uint_atomic_fetch
81 #pragma weak shmem_ulong_atomic_fetch = pshmem_ulong_atomic_fetch
82 #pragma weak shmem_ulonglong_atomic_fetch = pshmem_ulonglong_atomic_fetch
83 #pragma weak shmem_double_atomic_fetch = pshmem_double_atomic_fetch
84 #pragma weak shmem_float_atomic_fetch = pshmem_float_atomic_fetch
85
86 #pragma weak shmem_int_fetch = pshmem_int_fetch
87 #pragma weak shmem_long_fetch = pshmem_long_fetch
88 #pragma weak shmem_longlong_fetch = pshmem_longlong_fetch
89 #pragma weak shmem_double_fetch = pshmem_double_fetch
90 #pragma weak shmem_float_fetch = pshmem_float_fetch
91
92 #pragma weak shmemx_int32_fetch = pshmemx_int32_fetch
93 #pragma weak shmemx_int64_fetch = pshmemx_int64_fetch
94 #include "oshmem/shmem/c/profile/defines.h"
95 #endif
96
97 SHMEM_CTX_TYPE_ATOMIC_FETCH(_int, int, shmem)
98 SHMEM_CTX_TYPE_ATOMIC_FETCH(_long, long, shmem)
99 SHMEM_CTX_TYPE_ATOMIC_FETCH(_longlong, long long, shmem)
100 SHMEM_CTX_TYPE_ATOMIC_FETCH(_uint, unsigned int, shmem)
101 SHMEM_CTX_TYPE_ATOMIC_FETCH(_ulong, unsigned long, shmem)
102 SHMEM_CTX_TYPE_ATOMIC_FETCH(_ulonglong, unsigned long long, shmem)
103 SHMEM_CTX_TYPE_ATOMIC_FETCH(_double, double, shmem)
104 SHMEM_CTX_TYPE_ATOMIC_FETCH(_float, float, shmem)
105 SHMEM_TYPE_ATOMIC_FETCH(_int, int, shmem)
106 SHMEM_TYPE_ATOMIC_FETCH(_long, long, shmem)
107 SHMEM_TYPE_ATOMIC_FETCH(_longlong, long long, shmem)
108 SHMEM_TYPE_ATOMIC_FETCH(_uint, unsigned int, shmem)
109 SHMEM_TYPE_ATOMIC_FETCH(_ulong, unsigned long, shmem)
110 SHMEM_TYPE_ATOMIC_FETCH(_ulonglong, unsigned long long, shmem)
111 SHMEM_TYPE_ATOMIC_FETCH(_double, double, shmem)
112 SHMEM_TYPE_ATOMIC_FETCH(_float, float, shmem)
113
114
115 #define SHMEM_TYPE_FETCH(type_name, type, prefix) \
116 type prefix##type_name##_fetch(const type *target, int pe) \
117 { \
118 type out_value; \
119 DO_SHMEM_TYPE_ATOMIC_FETCH(oshmem_ctx_default, type_name, \
120 type, target, pe, out_value); \
121 return out_value; \
122 }
123
124 SHMEM_TYPE_FETCH(_int, int, shmem)
125 SHMEM_TYPE_FETCH(_long, long, shmem)
126 SHMEM_TYPE_FETCH(_longlong, long long, shmem)
127 SHMEM_TYPE_FETCH(_double, double, shmem)
128 SHMEM_TYPE_FETCH(_float, float, shmem)
129 SHMEM_TYPE_FETCH(_int32, int32_t, shmemx)
130 SHMEM_TYPE_FETCH(_int64, int64_t, shmemx)
131