16 integer,
parameter :: sizeoflong = 8
17 integer,
parameter :: linewidth = 80
18 integer,
parameter :: wordsize = 25
22 function isalpha(c) result(zz)
25 character(kind=c_char),
intent(in) :: c
27 zz = ((ichar(
'a') <= ichar(c) .and. ichar(c) <= ichar(
'z')) &
28 .or. (ichar(
'A') <= ichar(c) .and. ichar(c) <= ichar(
'Z')))
31 function upcase(s) result(zz)
34 character(kind=c_char, len=*),
intent(in) :: s
35 character(kind=c_char, len=len(s)) :: zz
37 character(*),
parameter :: uc =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 38 character(*),
parameter :: lc =
"abcdefghijklmnopqrstuvwxyz" 42 if (n /= 0) zz(i:i) = uc(n:n)
46 integer(c_int) function read_words_from_a_file(kv, kvi, kvo, p, i) &
52 type(c_ptr),
value,
intent(in) :: kvi, kvo
53 type(c_ptr),
value,
intent(in) :: p
54 integer(c_long),
value,
intent(in) :: i
59 character(kind=c_char, len=wordsize) :: b
60 character(len=linewidth) :: line
61 character(kind=c_char) :: cc
64 call kmr_assert(.not. c_associated(kvi) .and. kv%klen == 0 &
65 .and. kv%vlen == 0 .and. c_associated(kvo), &
66 "kvi == 0 && kv.klen == 0 && kv.vlen == 0 && kvo != 0")
67 open(17, file=
'LICENSE', status=
'old')
70 call kmr_assert(j <= (wordsize - 1),
"j <= (wordsize - 1)")
71 read(17,
'(a)', iostat=ios) line
73 call kmr_assert(len(trim(line)) < linewidth, &
74 "len(trim(line)) < linewidth")
76 do r = 1, len(trim(line)) + 1
78 if ((ios .lt. 0 .or. .not. isalpha(cc) .or. (j == (wordsize - 1))) &
97 end function read_words_from_a_file
99 integer(c_int) function print_top_five(kv, kvi, kvo, p, i) &
105 type(c_ptr),
value,
intent(in) :: kvi, kvo
106 type(c_ptr),
value,
intent(in) :: p
107 integer(c_long),
value,
intent(in) :: i
111 character(kind=c_char, len=kv%vlen),
target :: v
114 if (rank == 0 .and. i < 5)
then 116 print
"(A,A,A,I0)",
"#", v(1:kv%vlen-1),
"=", (0 - kv%k)
119 end function print_top_five
121 integer(c_int) function sum_counts_for_a_word(kv, n, kvi, kvo, p) &
127 integer(c_long),
value,
intent(in) :: n
128 type(c_ptr),
value,
intent(in) :: kvi, kvo
129 type(c_ptr),
value,
intent(in) :: p
140 nkv%klen = kv(1)%klen
142 nkv%vlen = sizeoflong
145 end function sum_counts_for_a_word
157 type(c_ptr) :: kvs0, kvs1, kvs2, kvs3, kvs4
158 integer :: nprocs, rank, thlv
161 call mpi_init_thread(mpi_thread_serialized, thlv, ierr)
162 call mpi_comm_size(mpi_comm_world, nprocs, ierr)
163 call mpi_comm_rank(mpi_comm_world, rank, ierr)
167 call mpi_barrier(mpi_comm_world, ierr)
168 if (rank == 0) print
"(A)",
"Ranking words..." 171 ierr =
kmr_map_once(kvs0, c_null_ptr, 0, .false., read_words_from_a_file)
177 ierr =
kmr_reduce(kvs1, kvs2, c_null_ptr, 0, sum_counts_for_a_word)
185 ierr =
kmr_map(kvs4, c_null_ptr, c_null_ptr, 0, print_top_five)
#define kmr_reduce(KVI, KVO, ARG, OPT, R)
Reduces key-value pairs.
Converts in reverse of kmr_strint().
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.
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).
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.
#define kmr_init()
Sets up the environment.
int kmr_sort(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Sorts a key-value stream globally.
Converts a character array to a (pointer value) integer for key/value (it is casting in C)...
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.
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).