34 integer(c_int),
parameter :: &
39 kmr_kv_pointer_owned = 5, &
40 kmr_kv_pointer_unmanaged = 6
44 integer(c_int),
parameter :: &
45 kmr_nothreading = ishft(1,0), &
46 kmr_inspect = ishft(1,1), &
47 kmr_keep_open = ishft(1,2), &
48 kmr_key_as_rank = ishft(1,3), &
49 kmr_rank_zero = ishft(1,4)
53 integer(c_int),
parameter :: &
54 kmr_each_rank = ishft(1,0), &
55 kmr_subdirectories = ishft(1,1), &
56 kmr_list_file = ishft(1,2), &
57 kmr_shuffle_names = ishft(1,3)
61 integer(c_int),
parameter :: &
62 kmr_separator_space = ishft(1,0), &
63 kmr_reply_each = ishft(1,1), &
64 kmr_reply_root = ishft(1,2), &
65 kmr_one_by_one = ishft(1,3)
71 integer(c_int) :: klen, vlen
72 integer(c_long) :: k, v
77 integer(c_long) :: icomm_cc
78 integer(c_int) :: icomm
79 integer(c_int) :: reply_root
85 integer(c_int) function kmr_mapfn(kv, kvi, kvo, p, i) bind(c)
90 type(c_ptr),
value,
intent(in) :: kvi, kvo
91 type(c_ptr),
value,
intent(in) :: p
92 integer(c_long),
value,
intent(in) :: i
99 integer(c_int) function kmr_redfn(kv, n, kvi, kvo, p) bind(c)
104 integer(c_long),
value,
intent(in) :: n
105 type(c_ptr),
value,
intent(in) :: kvi, kvo
106 type(c_ptr),
value,
intent(in) :: p
113 type(c_ptr) function
kmr_strptr(s) bind(c, name=
'kmr_strptr_ff')
116 character(kind=c_char,len=1) :: s
123 character(kind=c_char,len=1) function kmr_ptrstr(s) &
124 bind(c, name=
'kmr_ptrstr_ff')
127 type(c_ptr),
value :: s
134 integer(c_long) function kmr_ptrint(p) bind(c, name='kmr_ptrint_ff')
137 type(c_ptr),
value,
intent(in) :: p
144 type(c_ptr) function
kmr_intptr(p) bind(c, name=
'kmr_intptr_ff')
147 integer(c_long),
value,
intent(in) :: p
154 integer(c_long) function kmr_dblint(v) bind(c, name='kmr_dblint_ff')
157 real(c_double),
value,
intent(in) :: v
164 real(c_double) function kmr_intdbl(v) bind(c, name='kmr_intdbl_ff')
167 integer(c_long),
value,
intent(in) :: v
175 integer(c_long) function kmr_strint(s) bind(c, name='kmr_strint_ff')
178 character(kind=c_char,len=1) :: s
188 bind(c, name=
'kmr_intstr_ff')
191 integer(c_long),
value :: p
192 character(kind=c_char,len=1) :: s
193 integer(c_int),
value :: n
201 bind(c, name=
'kmr_fix_bits_endian_ff')
204 integer(c_long),
value,
intent(in) :: b
212 bind(c, name=
'kmr_get_rank_ff')
215 type(c_ptr),
value,
intent(in) :: kvs
223 bind(c, name=
'kmr_get_nprocs_ff')
226 type(c_ptr),
value,
intent(in) :: kvs
232 bind(c, name=
'kmr_get_key_type_ff')
235 type(c_ptr),
value,
intent(in) :: kvs
241 bind(c, name=
'kmr_get_value_type_ff')
244 type(c_ptr),
value,
intent(in) :: kvs
252 bind(c, name=
'kmr_local_element_count')
255 type(c_ptr),
value,
intent(in) :: kvs
256 integer(c_long),
intent(out) :: v
260 interface kmr_init_ff
261 integer(c_int) function kmr_init_ff(kf, opt, fopt) &
262 bind(c, name=
'kmr_init_ff')
265 integer(c_int),
value,
intent(in) :: kf
266 integer(c_long),
value,
intent(in) :: opt
267 integer(c_long),
value,
intent(in) :: fopt
268 end function kmr_init_ff
269 end interface kmr_init_ff
274 integer(c_int) function kmr_fin() bind(c, name='kmr_fin')
280 interface kmr_create_context_ff
281 type(c_ptr) function kmr_create_context_ff(comm, info, name) &
282 bind(c, name=
'kmr_create_context_ff')
285 integer(c_int),
value,
intent(in) :: comm
286 integer(c_int),
value,
intent(in) :: info
287 type(c_ptr),
intent(in) :: name
288 end function kmr_create_context_ff
289 end interface kmr_create_context_ff
295 bind(c, name=
'kmr_free_context')
298 type(c_ptr),
value,
intent(in) :: mr
306 bind(c, name=
'kmr_get_context_of_kvs')
309 type(c_ptr),
value,
intent(in) :: kvs
315 bind(c, name=
'kmr_create_kvs7')
318 type(c_ptr),
value,
intent(in) :: mr
319 integer(c_int),
value,
intent(in) :: kf, vf
320 integer(c_long),
value,
intent(in) :: opt
321 type(c_ptr),
value,
intent(in) :: f
322 integer(c_int),
value,
intent(in) :: l
323 type(c_ptr),
value,
intent(in) :: n
330 integer(c_int) function kmr_free_kvs(kvs) bind(c, name='kmr_free_kvs')
333 type(c_ptr),
value,
intent(in) :: kvs
340 integer(c_int) function kmr_add_kv(kvs, kv) bind(c, name='kmr_add_kv')
344 type(c_ptr),
value,
intent(in) :: kvs
353 bind(c, name=
'kmr_add_kv_done')
356 type(c_ptr),
value,
intent(in) :: kvs
361 integer(c_int) function kmr_map_ff(s, kvi, kvo, p, opt, m, g, l, f) &
362 bind(c, name=
'kmr_map9')
365 integer(c_int),
value,
intent(in) :: s
366 type(c_ptr),
value,
intent(in) :: kvi, kvo
367 type(c_ptr),
value,
intent(in) :: p
368 integer(c_long),
value,
intent(in) :: opt
369 type(c_funptr),
value,
intent(in) :: m
370 type(c_ptr),
value,
intent(in) :: g
371 integer(c_int),
value,
intent(in) :: l
372 type(c_ptr),
value,
intent(in) :: f
373 end function kmr_map_ff
374 end interface kmr_map_ff
376 interface kmr_map_on_rank_zero_ff
377 integer(c_int) function kmr_map_on_rank_zero_ff(kvo, p, opt, m) &
378 bind(c, name=
'kmr_map_on_rank_zero')
381 type(c_ptr),
value,
intent(in) :: kvo
382 type(c_ptr),
value,
intent(in) :: p
383 integer(c_long),
value,
intent(in) :: opt
384 type(c_funptr),
value,
intent(in) :: m
385 end function kmr_map_on_rank_zero_ff
386 end interface kmr_map_on_rank_zero_ff
389 integer(c_int) function kmr_map_once_ff(kvo, p, opt, rankzeroonly, m) &
390 bind(c, name=
'kmr_map_once')
393 type(c_ptr),
value,
intent(in) :: kvo
394 type(c_ptr),
value,
intent(in) :: p
395 integer(c_long),
value,
intent(in) :: opt
396 logical(c_bool),
value,
intent(in) :: rankzeroonly
397 type(c_funptr),
value,
intent(in) :: m
401 interface kmr_map_ms_ff
402 integer(c_int) function kmr_map_ms_ff(kvi, kvo, p, opt, m) &
403 bind(c, name=
'kmr_map_ms')
406 type(c_ptr),
value,
intent(in) :: kvi, kvo
407 type(c_ptr),
value,
intent(in) :: p
408 integer(c_long),
value,
intent(in) :: opt
409 type(c_funptr),
value,
intent(in) :: m
410 end function kmr_map_ms_ff
411 end interface kmr_map_ms_ff
416 bind(c, name=
'kmr_map_via_spawn_ff')
419 type(c_ptr),
value,
intent(in) :: kvi, kvo
420 type(c_ptr),
value,
intent(in) :: p
421 integer(c_int),
value,
intent(in) :: info
422 integer(c_long),
value,
intent(in) :: opt
423 type(c_funptr),
value,
intent(in) :: m
429 ii, comm) bind(c, name=
'kmr_get_spawner_communicator_ff')
432 type(c_ptr),
value,
intent(in) :: mr
433 integer(c_long),
value,
intent(in) :: ii
434 integer(c_int),
intent(out) :: comm
440 bind(c, name=
'kmr_sort_locally')
443 type(c_ptr),
value,
intent(in) :: kvi, kvo
444 logical(c_bool),
value,
intent(in) :: shuffling
445 integer(c_long),
value,
intent(in) :: opt
451 bind(c, name=
'kmr_shuffle')
454 type(c_ptr),
value,
intent(in) :: kvi, kvo
455 integer(c_long),
value,
intent(in) :: opt
461 bind(c, name=
'kmr_replicate')
464 type(c_ptr),
value,
intent(in) :: kvi, kvo
465 integer(c_long),
value,
intent(in) :: opt
469 interface kmr_reduce_ff
470 integer(c_int) function kmr_reduce_ff(s, kvi, kvo, p, opt, r, g, l, f) &
471 bind(c, name=
'kmr_reduce9')
474 integer(c_int),
value,
intent(in) :: s
475 type(c_ptr),
value,
intent(in) :: kvi, kvo
476 type(c_ptr),
value,
intent(in) :: p
477 integer(c_long),
value,
intent(in) :: opt
478 type(c_funptr),
value,
intent(in) :: r
479 type(c_ptr),
value,
intent(in) :: g
480 integer(c_int),
value,
intent(in) :: l
481 type(c_ptr),
value,
intent(in) :: f
482 end function kmr_reduce_ff
483 end interface kmr_reduce_ff
489 bind(c, name=
'kmr_dump_kvs')
492 type(c_ptr),
value,
intent(in) :: kvi
493 integer(c_int),
value,
intent(in) :: f
501 bind(c, name=
'kmr_get_element_count')
504 type(c_ptr),
value,
intent(in) :: kvs
505 integer(c_long),
intent(out) :: v
510 integer(c_int) function kmr_sort_ff(kvi, kvo, opt) &
511 bind(c, name=
'kmr_sort')
514 type(c_ptr),
value,
intent(in) :: kvi, kvo
515 integer(c_long),
value,
intent(in) :: opt
521 bind(c, name=
'kmr_reverse')
524 type(c_ptr),
value,
intent(in) :: kvi, kvo
525 integer(c_long),
value,
intent(in) :: opt
533 subroutine kmr_assert(v, expr)
535 logical,
intent(in) :: v
536 character(len=*),
intent(in) :: expr
538 print *,
"Assertion failed: ", trim(expr)
539 call mpi_abort(mpi_comm_world, 1)
541 end subroutine kmr_assert
546 integer(c_int) function kmr_nullmapfn(kv, kvi, kvo, p, i) bind(c) result(zz)
550 type(c_ptr),
value,
intent(in) :: kvi, kvo
551 type(c_ptr),
value,
intent(in) :: p
552 integer(c_long),
value,
intent(in) :: i
555 call kmr_assert(c_associated(kvi) .and. c_associated(kvo) &
556 .and. c_associated(p), &
557 .and..and.
"c_associated(kvi) c_associated(kvo) c_associated(p)")
560 end function kmr_nullmapfn
575 integer(c_long) function kmr_fixopt(b) result(zz)
576 integer(c_int),
value,
intent(in) :: b
578 end function kmr_fixopt
582 integer(c_int) function kmr_init() result(zz)
583 call kmr_assert(c_int > 0,
'c_int > 0')
584 call kmr_assert(c_long > 0,
'c_long > 0')
587 zz = kmr_init_ff(kmr_kv_pointer_unmanaged, &
588 kmr_fixopt(kmr_rank_zero), kmr_fixopt(kmr_shuffle_names))
593 type(c_ptr) function kmr_create_context(comm, info) result(zz)
594 integer,
value,
intent(in) :: comm
595 integer,
value,
intent(in) :: info
596 zz = kmr_create_context_ff(int(comm, c_int), &
597 int(info, c_int), c_null_ptr)
602 type(c_ptr) function kmr_create_kvs(mr, kf, vf) result(zz)
603 type(c_ptr),
value,
intent(in) :: mr
604 integer(c_int),
value,
intent(in) :: kf, vf
606 c_null_ptr, 0, c_null_ptr)
611 integer(c_int) function kmr_map(kvi, kvo, p, opt, m) result(zz)
612 type(c_ptr),
value,
intent(in) :: kvi, kvo
613 type(c_ptr),
value,
intent(in) :: p
614 integer(c_int),
value,
intent(in) :: opt
616 zz = kmr_map_ff(0, kvi, kvo, p, kmr_fixopt(opt), c_funloc(m), &
617 c_null_ptr, 0, c_null_ptr)
623 type(c_ptr),
value,
intent(in) :: kvo
624 type(c_ptr),
value,
intent(in) :: p
625 integer(c_int),
value,
intent(in) :: opt
629 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
630 zz = kmr_map_on_rank_zero_ff(kvo, p, kmr_fixopt(opt), c_funloc(m))
635 integer(c_int) function kmr_map_once(kvo, p, opt, rankzeroonly, m) result(zz)
636 type(c_ptr),
value,
intent(in) :: kvo
637 type(c_ptr),
value,
intent(in) :: p
638 integer(c_int),
value,
intent(in) :: opt
639 logical,
value,
intent(in) :: rankzeroonly
641 logical(c_bool) :: bb
642 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
643 if (rankzeroonly)
then 653 integer(c_int) function kmr_map_ms(kvi, kvo, p, opt, m) result(zz)
654 type(c_ptr),
value,
intent(in) :: kvi, kvo
655 type(c_ptr),
value,
intent(in) :: p
656 integer(c_int),
value,
intent(in) :: opt
658 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
659 zz = kmr_map_ms_ff(kvi, kvo, p, kmr_fixopt(opt), c_funloc(m))
666 type(c_ptr),
value,
intent(in) :: kvi, kvo
667 type(c_ptr),
value,
intent(in) :: p
668 integer,
value,
intent(in) :: info
669 integer(c_int),
value,
intent(in) :: opt
672 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
674 if (c_associated(c_funloc(m), c_funloc(kmr_nullmapfn)))
then 689 type(c_ptr),
value,
intent(in) :: mr
690 integer(c_long),
value,
intent(in) :: ii
691 integer,
intent(out) :: comm
697 integer(c_int) function kmr_sort_locally(kvi, kvo, shuffling, opt) result(zz)
698 type(c_ptr),
value,
intent(in) :: kvi, kvo
699 logical(c_bool),
value,
intent(in) :: shuffling
700 integer(c_int),
value,
intent(in) :: opt
701 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
702 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
708 integer(c_int) function kmr_shuffle(kvi, kvo, opt) result(zz)
709 type(c_ptr),
value,
intent(in) :: kvi, kvo
710 integer(c_int),
value,
intent(in) :: opt
711 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
712 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
718 integer(c_int) function kmr_replicate(kvi, kvo, opt) result(zz)
719 type(c_ptr),
value,
intent(in) :: kvi, kvo
720 integer(c_int),
value,
intent(in) :: opt
721 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
722 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
728 integer(c_int) function kmr_reduce(kvi, kvo, p, opt, r) result(zz)
729 type(c_ptr),
value,
intent(in) :: kvi, kvo
730 type(c_ptr),
value,
intent(in) :: p
731 integer(c_int),
value,
intent(in) :: opt
733 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
734 zz = kmr_reduce_ff(0, kvi, kvo, p, kmr_fixopt(opt), c_funloc(r), &
735 c_null_ptr, 0, c_null_ptr)
740 integer(c_int) function kmr_sort(kvi, kvo, opt) result(zz)
741 type(c_ptr),
value,
intent(in) :: kvi, kvo
742 integer(c_int),
value,
intent(in) :: opt
743 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
744 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
750 integer(c_int) function kmr_reverse(kvi, kvo, opt) result(zz)
751 type(c_ptr),
value,
intent(in) :: kvi, kvo
752 integer(c_int),
value,
intent(in) :: opt
753 call kmr_assert(c_associated(kvi),
'c_associated(kvi)')
754 call kmr_assert(c_associated(kvo),
'c_associated(kvo)')
#define kmr_reduce(KVI, KVO, ARG, OPT, R)
Reduces key-value pairs.
Converts in reverse of kmr_strint().
Converts in reverse of kmr_ptrint.
int kmr_map_once(KMR_KVS *kvo, void *arg, struct kmr_option opt, _Bool rank_zero_only, kmr_mapfn_t m)
Maps once.
#define kmr_create_kvs(MR, KF, VF)
Makes a new key-value stream (of type KMR_KVS) with the specified field datatypes.
(See kmr_get_context_of_kvs() in C).
MPI_Comm * kmr_get_spawner_communicator(KMR *mr, long index)
Obtains (a reference to) a parent inter-communicator of a spawned process.
Gets MPI nprocs from a key-value stream.
int kmr_shuffle(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Shuffles key-value pairs to the appropriate destination ranks.
(See kmr_free_context() in C).
Returns the element count local on each node.
Gets MPI rank from a key-value stream.
#define kmr_map(KVI, KVO, ARG, OPT, M)
Maps simply.
Handy Copy of a Key-Value Field.
(See kmr_get_element_count() in C).
#define kmr_init()
Sets up the environment.
(See kmr_add_kv_done() in C).
int kmr_sort(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Sorts a key-value stream globally.
Converts a double to a long for key/value (ill-mannered).
Converts in reverse of kmr_dblint.
(See kmr_free_kvs() in C).
int kmr_map_via_spawn(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, MPI_Info info, struct kmr_spawn_option opt, kmr_mapfn_t mapfn)
Maps on processes started by MPI_Comm_spawn().
Fixes little-endian bits used in Fortran to host-endian.
Converts a string to a C pointer (ill-mannered).
int kmr_map_ms(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps in master-slave mode.
Converts in reverse of kmr_strptr.
int kmr_replicate(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Replicates key-value pairs to be visible on all ranks, that is, it has the effect of bcast or all-gat...
Converts a character array to a (pointer value) integer for key/value (it is casting in C)...
int kmr_sort_locally(KMR_KVS *kvi, KMR_KVS *kvo, _Bool shuffling, struct kmr_option opt)
Reorders key-value pairs in a single rank.
Converts a pointer to a long for key/value (ill-mannered).
int kmr_reverse(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Makes a new pair by swapping the key and the value in each pair.
(See kmr_dump_kvs() in C).
int kmr_map_on_rank_zero(KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps on rank0 only.
KMR * kmr_create_context(const MPI_Comm comm, const MPI_Info conf, const char *name)
Makes a new KMR context (a context has type KMR).