Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
shmem.F90
Go to the documentation of this file.
1! Copyright (c) 2025-2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
34module shmem
35 use, intrinsic :: iso_c_binding
36 implicit none
37
38#ifdef HAVE_OPENSHMEM
39
40 enum, bind(c)
41 enumerator :: shmem_max_name_len = 256
42 end enum
43
44 enum, bind(c)
45 enumerator :: shmem_cmp_eq = 0
46 enumerator :: shmem_cmp_ne = 1
47 enumerator :: shmem_cmp_gt = 2
48 enumerator :: shmem_cmp_le = 3
49 enumerator :: shmem_cmp_lt = 4
50 enumerator :: shmem_cmp_ge = 5
51 end enum
52
53 enum, bind(c)
54 enumerator :: shmem_thread_single = 0
55 enumerator :: shmem_thread_funneled = 1
56 enumerator :: shmem_thread_serialized = 2
57 enumerator :: shmem_thread_multiple= 3
58 end enum
59
60 enum, bind(c)
61 enumerator :: shmem_ctx_private = 1
62 enumerator :: shmem_ctx_serialized = 2
63 enumerator :: shmem_ctx_nostore = 4
64 end enum
65
66 enum, bind(c)
67 enumerator :: shmem_ctx_low_latency = int(z'100')
68 enumerator :: shmem_ctx_dedicated = int(z'200')
69 enumerator :: shmem_ctx_best_effort = int(z'400')
70 enumerator :: shmem_ctx_bulk_data = int(z'800')
71 end enum
72
73 enum, bind(c)
76 end enum
77
78 enum, bind(c)
79 enumerator :: shmem_signal_set = 1
80 enumerator :: shmem_signal_add = 2
81 end enum
82
83 !
84 ! Library Setup
85 !
86
87 interface
88 subroutine shmem_init() bind (c, name='shmem_init')
89 end subroutine shmem_init
90 end interface
91
92 interface
93 subroutine shmem_finalize() bind (c, name='shmem_finalize')
94 end subroutine shmem_finalize
95 end interface
96
97 interface
98 integer(c_int) function shmem_me_pe() bind(c, name='shmem_my_pe')
99 use, intrinsic :: iso_c_binding
100 end function shmem_me_pe
101 end interface
102
103 interface
104 integer(c_int) function shmem_n_pes() bind(c, name='shmem_n_pes')
105 use, intrinsic :: iso_c_binding
106 end function shmem_n_pes
107 end interface
108
109 !
110 ! Library Query
111 !
112
113 interface
114 subroutine shmem_info_get_name(name) &
115 bind(c, name = 'shmem_info_get_name')
116 use, intrinsic :: iso_c_binding
117 import shmem_max_name_len
118 implicit none
119 character(kind=c_char, len=SHMEM_MAX_NAME_LEN) :: name
120 end subroutine shmem_info_get_name
121 end interface
122
123 interface
124 subroutine shmem_info_get_version(major, minor) &
125 bind(c, name = 'shmem_info_get_version')
126 use, intrinsic :: iso_c_binding
127 integer(c_int) :: major
128 integer(c_int) :: minor
129 end subroutine shmem_info_get_version
130 end interface
131
132 interface
133 integer(c_int) function shmem_pe_accessible(pe) &
134 bind(c, name = 'shmem_pe_accessible')
135 use, intrinsic :: iso_c_binding
136 integer(c_int), value :: pe
137 end function shmem_pe_accessible
138 end interface
139
140 interface
141 integer(c_int) function shmem_addr_accessible(addr, pe) &
142 bind(c, name = 'shmem_addr_accessible')
143 use, intrinsic :: iso_c_binding
144 type(c_ptr) :: addr
145 integer(c_int), value :: pe
146 end function shmem_addr_accessible
147 end interface
148
149 !
150 ! Memory Mangement
151 !
152
153 interface
154 type(c_ptr) function shmem_malloc(size) &
155 bind(c, name = 'shmem_malloc')
156 use, intrinsic :: iso_c_binding
157 integer(c_size_t), value :: size
158 end function shmem_malloc
159 end interface
160
161 interface
162 subroutine shmem_free(ptr) &
163 bind(c, name = 'shmem_free')
164 use, intrinsic :: iso_c_binding
165 type(c_ptr), value :: ptr
166 end subroutine shmem_free
167 end interface
168
169 interface
170 type(c_ptr) function shmem_realloc(ptr, size) &
171 bind(c, name = 'shmem_realloc')
172 use, intrinsic :: iso_c_binding
173 type(c_ptr), value :: ptr
174 integer(c_size_t), value :: size
175 end function shmem_realloc
176 end interface
177
178 interface
179 type(c_ptr) function shmem_align(alignment, size) &
180 bind(c, name = 'shmem_align')
181 use, intrinsic :: iso_c_binding
182 integer(c_size_t), value :: alignment
183 integer(c_size_t), value :: size
184 end function shmem_align
185 end interface
186
187 interface
188 type(c_ptr) function shmem_calloc(count, size) &
189 bind(c, name = 'shmem_calloc')
190 use, intrinsic :: iso_c_binding
191 integer(c_size_t), value :: count
192 integer(c_size_t), value :: size
193 end function shmem_calloc
194 end interface
195
196 interface
197 type(c_ptr) function shmem_malloc_with_hints(size, hints) &
198 bind(c, name = 'shmem_malloc_with_hints')
199 use, intrinsic :: iso_c_binding
200 integer(c_size_t), value :: size
201 integer(c_long), value :: hints
202 end function shmem_malloc_with_hints
203 end interface
204
205 interface
206 type(c_ptr) function shmem_ptr(dest, pe) &
207 bind(c, name = 'shmem_ptr')
208 use, intrinsic :: iso_c_binding
209 type(c_ptr), value :: dest
210 integer(c_int), value :: pe
211 end function shmem_ptr
212 end interface
213
214 !
215 ! Thread Support
216 !
217
218 interface
219 integer(c_int) function shmem_init_thread(requested, provided) &
220 bind(c, name = 'shmem_init_thread')
221 use, intrinsic :: iso_c_binding
222 integer(c_int), value :: requested
223 integer(c_int) :: provided
224 end function shmem_init_thread
225 end interface
226
227 interface
228 subroutine shmem_query_thread(provided) &
229 bind(c, name = 'shmem_query_thread')
230 use, intrinsic :: iso_c_binding
231 integer(c_int) :: provided
232 end subroutine shmem_query_thread
233 end interface
234
235 !
236 ! Communication Management
237 !
238
239 interface
240 integer(c_int) function shmem_ctx_create(options, ctx) &
241 bind(c, name = 'shmem_ctx_create')
242 use, intrinsic :: iso_c_binding
243 integer(c_long), value :: options
244 type(c_ptr), value :: ctx
245 end function shmem_ctx_create
246 end interface
247
248 interface
249 subroutine shmem_ctx_destroy(ctx) &
250 bind(c, name = 'shmem_ctx_destroy')
251 use, intrinsic :: iso_c_binding
252 type(c_ptr), value :: ctx
253 end subroutine shmem_ctx_destroy
254 end interface
255
256 !
257 ! Remote Memory Access
258 !
259
260 interface
261 subroutine shmem_putmem(dest, source, nelems, pe) &
262 bind(c, name = 'shmem_putmem')
263 use, intrinsic :: iso_c_binding
264 type(c_ptr), value :: dest
265 type(c_ptr), value :: source
266 integer(c_size_t), value :: nelems
267 integer(c_int), value :: pe
268 end subroutine shmem_putmem
269 end interface
270
271 interface
272 subroutine shmem_ctx_putmem(ctx, dest, source, nelems, pe) &
273 bind(c, name = 'shmem_ctx_putmem')
274 use, intrinsic :: iso_c_binding
275 type(c_ptr), value :: ctx
276 type(c_ptr), value :: dest
277 type(c_ptr), value :: source
278 integer(c_size_t), value :: nelems
279 integer(c_int), value :: pe
280 end subroutine shmem_ctx_putmem
281 end interface
282
283 interface
284 subroutine shmem_getmem(dest, source, nelems, pe) &
285 bind(c, name = 'shmem_getmem')
286 use, intrinsic :: iso_c_binding
287 type(c_ptr), value :: dest
288 type(c_ptr), value :: source
289 integer(c_size_t), value :: nelems
290 integer(c_int), value :: pe
291 end subroutine shmem_getmem
292 end interface
293
294 interface
295 subroutine shmem_ctx_getmem(ctx, dest, source, nelems, pe) &
296 bind(c, name = 'shmem_ctx_getmem')
297 use, intrinsic :: iso_c_binding
298 type(c_ptr), value :: ctx
299 type(c_ptr), value :: dest
300 type(c_ptr), value :: source
301 integer(c_size_t), value :: nelems
302 integer(c_int), value :: pe
303 end subroutine shmem_ctx_getmem
304 end interface
305
306 interface
307 subroutine shmem_putmem_nbi(dest, source, nelems, pe) &
308 bind(c, name = 'shmem_putmem_nbi')
309 use, intrinsic :: iso_c_binding
310 type(c_ptr), value :: dest
311 type(c_ptr), value :: source
312 integer(c_size_t), value :: nelems
313 integer(c_int), value :: pe
314 end subroutine shmem_putmem_nbi
315 end interface
316
317 interface
318 subroutine shmem_ctx_putmem_nbi(ctx, dest, source, nelems, pe) &
319 bind(c, name = 'shmem_ctx_putmem_nbi')
320 use, intrinsic :: iso_c_binding
321 type(c_ptr), value :: ctx
322 type(c_ptr), value :: dest
323 type(c_ptr), value :: source
324 integer(c_size_t), value :: nelems
325 integer(c_int), value :: pe
326 end subroutine shmem_ctx_putmem_nbi
327 end interface
328
329 interface
330 subroutine shmem_getmem_nbi(dest, source, nelems, pe) &
331 bind(c, name = 'shmem_getmem_nbi')
332 use, intrinsic :: iso_c_binding
333 type(c_ptr), value :: dest
334 type(c_ptr), value :: source
335 integer(c_size_t), value :: nelems
336 integer(c_int), value :: pe
337 end subroutine shmem_getmem_nbi
338 end interface
339
340 interface
341 subroutine shmem_ctx_getmem_nbi(ctx, dest, source, nelems, pe) &
342 bind(c, name = 'shmem_ctx_getmem_nbi')
343 use, intrinsic :: iso_c_binding
344 type(c_ptr), value :: ctx
345 type(c_ptr), value :: dest
346 type(c_ptr), value :: source
347 integer(c_size_t), value :: nelems
348 integer(c_int), value :: pe
349 end subroutine shmem_ctx_getmem_nbi
350 end interface
351
352 !
353 ! Signaling Operations (OpenSHMEM 1.5)
354 !
355
356 interface
357 subroutine shmem_putmem_signal_nbi(dest, source, nelems, sig_addr, &
358 signal, sig_op, pe) bind(c, name = 'shmem_putmem_signal_nbi')
359 use, intrinsic :: iso_c_binding
360 type(c_ptr), value :: dest
361 type(c_ptr), value :: source
362 integer(c_size_t), value :: nelems
363 type(c_ptr), value :: sig_addr
364 integer(c_int64_t), value :: signal
365 integer(c_int), value :: sig_op
366 integer(c_int), value :: pe
367 end subroutine shmem_putmem_signal_nbi
368 end interface
369
370 interface
371 integer(c_int64_t) function shmem_signal_wait_until(sig_addr, cmp, &
372 cmp_value) bind(c, name = 'shmem_signal_wait_until')
373 use, intrinsic :: iso_c_binding
374 type(c_ptr), value :: sig_addr
375 integer(c_int), value :: cmp
376 integer(c_int64_t), value :: cmp_value
377 end function shmem_signal_wait_until
378 end interface
379
380 interface
381 subroutine shmem_uint64_atomic_set(dest, val, pe) &
382 bind(c, name = 'shmem_uint64_atomic_set')
383 use, intrinsic :: iso_c_binding
384 type(c_ptr), value :: dest
385 integer(c_int64_t), value :: val
386 integer(c_int), value :: pe
387 end subroutine shmem_uint64_atomic_set
388 end interface
389
390 interface
391 subroutine shmem_uint64_wait_until(ivar, cmp, cmp_value) &
392 bind(c, name = 'shmem_uint64_wait_until')
393 use, intrinsic :: iso_c_binding
394 type(c_ptr), value :: ivar
395 integer(c_int), value :: cmp
396 integer(c_int64_t), value :: cmp_value
397 end subroutine shmem_uint64_wait_until
398 end interface
399
400 !
401 ! Collective Operations
402 !
403
404 interface
405 integer(c_int) function shmem_alltoallmem(team, dest, source, nelems) &
406 bind(c, name = 'shmem_alltoall_mem')
407 use, intrinsic :: iso_c_binding
408 type(c_ptr), value :: team
409 type(c_ptr), value :: dest
410 type(c_ptr), value :: source
411 integer(c_size_t), value :: nelems
412 end function shmem_alltoallmem
413 end interface
414
415 interface
416 subroutine shmem_barrier(PE_start, logPE_stride, PE_size, pSync) &
417 bind(c, name = 'shmem_barrier')
418 use, intrinsic :: iso_c_binding
419 integer(c_int), value :: PE_start
420 integer(c_int), value :: logPE_stride
421 integer(c_int), value :: PE_size
422 integer(c_long) :: pSync
423 end subroutine shmem_barrier
424 end interface
425
426 interface
427 subroutine shmem_barrier_all() &
428 bind(c, name = 'shmem_barrier_all')
429 end subroutine shmem_barrier_all
430 end interface
431
432 interface
433 integer(c_int) function shmem_broadcastmem(team, dest, source, &
434 nelems, PE_root) bind(c, name = 'shmem_broadcastmem')
435 use, intrinsic :: iso_c_binding
436 type(c_ptr), value :: team
437 type(c_ptr), value :: dest
438 type(c_ptr), value :: source
439 integer(c_size_t), value :: nelems
440 integer(c_int), value :: pe_root
441 end function shmem_broadcastmem
442 end interface
443
444 interface
445 integer(c_int) function shmem_collectmem(team, dest, source, nelems) &
446 bind(c, name = 'shmem_collectmem')
447 use, intrinsic :: iso_c_binding
448 type(c_ptr), value :: team
449 type(c_ptr), value :: dest
450 type(c_ptr), value :: source
451 integer(c_size_t), value :: nelems
452 end function shmem_collectmem
453 end interface
454
455 interface
456 integer(c_int) function shmem_fcollectmem(team, dest, source, nelems) &
457 bind(c, name = 'shmem_fcollectmem')
458 use, intrinsic :: iso_c_binding
459 type(c_ptr), value :: team
460 type(c_ptr), value :: dest
461 type(c_ptr), value :: source
462 integer(c_size_t), value :: nelems
463 end function shmem_fcollectmem
464 end interface
465
466 interface
467 subroutine shmem_sync(team) &
468 bind(c, name = 'shmem_sync')
469 use, intrinsic :: iso_c_binding
470 type(c_ptr), value :: team
471 end subroutine shmem_sync
472 end interface
473
474 interface
475 subroutine shmem_sync_all() &
476 bind(c, name = 'shmem_sync_all')
477 end subroutine shmem_sync_all
478 end interface
479
480 interface
481 subroutine shmem_fence() &
482 bind(c, name = 'shmem_fence')
483 end subroutine shmem_fence
484 end interface
485
486 interface
487 subroutine shmem_ctx_fence(ctx) &
488 bind(c, name = 'shmem_ctx_fence')
489 use, intrinsic :: iso_c_binding
490 type(c_ptr), value :: ctx
491 end subroutine shmem_ctx_fence
492 end interface
493
494 !
495 ! Memory ordering
496 !
497
498 interface
499 subroutine shmem_quiet() &
500 bind(c, name = 'shmem_quiet')
501 end subroutine shmem_quiet
502 end interface
503
504 interface
505 subroutine shmem_ctx_quiet(ctx) &
506 bind(c, name = 'shmem_ctx_quiet')
507 use, intrinsic :: iso_c_binding
508 type(c_ptr), value :: ctx
509 end subroutine shmem_ctx_quiet
510 end interface
511
512 !
513 ! Distributed Locks
514 !
515
516 interface
517 subroutine shmem_clear_lock(lock) &
518 bind(c, name = 'shmem_clear_lock')
519 use, intrinsic :: iso_c_binding
520 integer(c_long) :: lock
521 end subroutine shmem_clear_lock
522 end interface
523
524 interface
525 subroutine shmem_set_lock(lock) &
526 bind(c, name = 'shmem_set_lock')
527 use, intrinsic :: iso_c_binding
528 integer(c_long) :: lock
529 end subroutine shmem_set_lock
530 end interface
531
532 interface
533 integer(c_int) function shmem_test_lock(lock) &
534 bind(c, name = 'shmem_test_lock')
535 use, intrinsic :: iso_c_binding
536 integer(c_long) :: lock
537 end function shmem_test_lock
538 end interface
539
540#endif
541
542end module shmem
Fortran bindings to SHMEM's C API.
Definition shmem.F90:34
@ shmem_ctx_dedicated
Definition shmem.F90:68
@ shmem_ctx_low_latency
Definition shmem.F90:67
@ shmem_ctx_best_effort
Definition shmem.F90:69
@ shmem_ctx_bulk_data
Definition shmem.F90:70
@ shmem_ctx_serialized
Definition shmem.F90:62
@ shmem_ctx_private
Definition shmem.F90:61
@ shmem_ctx_nostore
Definition shmem.F90:63
@ shmem_max_name_len
Definition shmem.F90:41
@ shmem_malloc_atomics_remote
Definition shmem.F90:74
@ shmem_malloc_signal_remote
Definition shmem.F90:75
@ shmem_signal_add
Definition shmem.F90:80
@ shmem_signal_set
Definition shmem.F90:79
@ shmem_thread_serialized
Definition shmem.F90:56
@ shmem_thread_multiple
Definition shmem.F90:57
@ shmem_thread_single
Definition shmem.F90:54
@ shmem_thread_funneled
Definition shmem.F90:55
@ shmem_cmp_eq
Definition shmem.F90:45
@ shmem_cmp_gt
Definition shmem.F90:47
@ shmem_cmp_lt
Definition shmem.F90:49
@ shmem_cmp_ne
Definition shmem.F90:46
@ shmem_cmp_le
Definition shmem.F90:48
@ shmem_cmp_ge
Definition shmem.F90:50