-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpi.scm
393 lines (321 loc) · 7.49 KB
/
mpi.scm
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
;;
;; Chicken MPI interface. Based on the Caml/MPI interface by Xavier
;; Leroy.
;;
;;
;; Copyright 2007-2018 Ivan Raikov.
;;
;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; A full copy of the GPL license can be found at
;; <http://www.gnu.org/licenses/>.
;;
(module mpi
(MPI:barrier
MPI:broadcast-int
MPI:scatter-int
MPI:gather-int
MPI:allgather-int
MPI:broadcast-flonum
MPI:scatter-flonum
MPI:gather-flonum
MPI:allgather-flonum
MPI:broadcast-fixnum
MPI:broadcast
MPI:scatter
MPI:scatterv
MPI:gather
MPI:gatherv
MPI:allgather
MPI:alltoall
MPI:alltoallv
MPI:broadcast-bytevector
MPI:scatter-bytevector
MPI:scatterv-bytevector
MPI:gather-bytevector
MPI:gatherv-bytevector
MPI:allgather-bytevector
MPI:alltoall-bytevector
MPI:alltoallv-bytevector
MPI:broadcast-s8vector
MPI:scatter-s8vector
MPI:scatterv-s8vector
MPI:gather-s8vector
MPI:gatherv-s8vector
MPI:allgather-s8vector
MPI:alltoall-s8vector
MPI:alltoallv-s8vector
MPI:broadcast-u8vector
MPI:scatter-u8vector
MPI:scatterv-u8vector
MPI:gather-u8vector
MPI:gatherv-u8vector
MPI:allgather-u8vector
MPI:alltoall-u8vector
MPI:alltoallv-u8vector
MPI:broadcast-s16vector
MPI:scatter-s16vector
MPI:scatterv-s16vector
MPI:gather-s16vector
MPI:gatherv-s16vector
MPI:allgather-s16vector
MPI:alltoall-s16vector
MPI:alltoallv-s16vector
MPI:broadcast-u16vector
MPI:scatter-u16vector
MPI:scatterv-u16vector
MPI:gather-u16vector
MPI:gatherv-u16vector
MPI:allgather-u16vector
MPI:alltoall-u16vector
MPI:alltoallv-u16vector
MPI:broadcast-s32vector
MPI:scatter-s32vector
MPI:scatterv-s32vector
MPI:gather-s32vector
MPI:gatherv-s32vector
MPI:allgather-s32vector
MPI:alltoall-s32vector
MPI:alltoallv-s32vector
MPI:broadcast-u32vector
MPI:scatter-u32vector
MPI:scatterv-u32vector
MPI:gather-u32vector
MPI:gatherv-u32vector
MPI:allgather-u32vector
MPI:alltoall-u32vector
MPI:alltoallv-u32vector
MPI:broadcast-f32vector
MPI:scatter-f32vector
MPI:scatterv-f32vector
MPI:gather-f32vector
MPI:gatherv-f32vector
MPI:allgather-f32vector
MPI:alltoall-f32vector
MPI:alltoallv-f32vector
MPI:broadcast-f64vector
MPI:scatter-f64vector
MPI:scatterv-f64vector
MPI:gather-f64vector
MPI:gatherv-f64vector
MPI:allgather-f64vector
MPI:alltoall-f64vector
MPI:alltoallv-f64vector
MPI:reduce-int
MPI:reduce-flonum
MPI:allreduce-int
MPI:allreduce-flonum
MPI:scan-int
MPI:scan-flonum
MPI:reduce-s8vector
MPI:allreduce-s8vector
MPI:scan-s8vector
MPI:reduce-u8vector
MPI:allreduce-u8vector
MPI:scan-u8vector
MPI:reduce-s16vector
MPI:allreduce-s16vector
MPI:scan-s16vector
MPI:reduce-u16vector
MPI:allreduce-u16vector
MPI:scan-u16vector
MPI:reduce-s32vector
MPI:allreduce-s32vector
MPI:scan-s32vector
MPI:reduce-u32vector
MPI:allreduce-u32vector
MPI:scan-u32vector
MPI:reduce-f32vector
MPI:allreduce-f32vector
MPI:scan-f32vector
MPI:reduce-f64vector
MPI:allreduce-f64vector
MPI:scan-f64vector
MPI:comm?
MPI:get-comm-world
MPI:comm-size
MPI:comm-rank
MPI:comm-equal?
MPI:comm-split
MPI:comm-create
MPI:undefined
MPI:make-cart
MPI:make-dims
MPI:cart-rank
MPI:cart-coords
MPI:group?
MPI:group-size
MPI:group-rank
MPI:group-translate-ranks
MPI:comm-group
MPI:group-union
MPI:group-difference
MPI:group-intersection
MPI:group-incl
MPI:group-excl
MPI:group-range-incl
MPI:group-range-excl
MPI:datatype?
MPI:type-extent
MPI:type-size
MPI:type-char
MPI:type-int
MPI:type-fixnum
MPI:type-flonum
MPI:type-byte
MPI:type-s8
MPI:type-u8
MPI:type-s16
MPI:type-u16
MPI:type-s32
MPI:type-u32
MPI:type-f32
MPI:type-f64
MPI:make-type-struct
MPI:pack-size
MPI:init
MPI:spawn
MPI:finalize
MPI:wtime
MPI:send
MPI:send-fixnum
MPI:send-int
MPI:send-flonum
MPI:send-u8vector
MPI:send-s8vector
MPI:send-u16vector
MPI:send-s16vector
MPI:send-u32vector
MPI:send-s32vector
MPI:send-f32vector
MPI:send-f64vector
MPI:send-bytevector
MPI:probe
MPI:receive
MPI:receive-with-status
MPI:receive-bytevector
MPI:receive-bytevector-with-status
MPI:receive-flonum
MPI:receive-fixnum
MPI:receive-int
MPI:receive-u8vector
MPI:receive-s8vector
MPI:receive-u16vector
MPI:receive-s16vector
MPI:receive-u32vector
MPI:receive-s32vector
MPI:receive-f32vector
MPI:receive-f64vector
MPI:any-tag
MPI:any-source
MPI:i_max
MPI:i_min
MPI:i_sum
MPI:i_prod
MPI:i_land
MPI:i_lor
MPI:i_xor
MPI:f_max
MPI:f_min
MPI:f_sum
MPI:f_prod
MPI-rr-fold MPI-rr-foldi MPI-rr-map MPI-rr-for-each
)
(import scheme (chicken base) (chicken foreign) (chicken blob)
(only (chicken string) ->string)
srfi-1 srfi-4)
#>
#include "chicken-mpi.h"
<#
(include "init")
(include "datatype")
(include "group")
(include "comm")
(include "msgs")
(include "collcomm")
;; MPI round-robin fold/map/for-each
(define (MPI-rr-fold fn initial xs #!key (comm (MPI:get-comm-world)))
(let (
(size (MPI:comm-size comm))
(myrank (MPI:comm-rank comm))
)
(cdr
(fold
(lambda (x myindex.ax)
(let ((myindex (car myindex.ax))
(ax (cdr myindex.ax)))
(cond
((= myindex myrank)
(let ((ax1 (fn x ax))
(myindex1 (if (= myindex (- size 1)) 0 (+ 1 myindex))))
(cons myindex1 ax1)))
(else (cons (if (= myindex (- size 1)) 0 (+ 1 myindex)) ax))
)
))
(cons 0 initial) xs))
))
(define (MPI-rr-foldi fn initial is xs #!key (comm (MPI:get-comm-world)))
(let (
(size (MPI:comm-size comm))
(myrank (MPI:comm-rank comm))
)
(cdr
(fold
(lambda (x-i x myindex.ax)
(let ((myindex (car myindex.ax))
(ax (cdr myindex.ax)))
(cond
((= myindex myrank)
(let ((ax1 (fn x-i x ax))
(myindex1 (if (= myindex (- size 1)) 0 (+ 1 myindex))))
(cons myindex1 ax1)))
(else (cons (if (= myindex (- size 1)) 0 (+ 1 myindex)) ax))
)
))
(cons 0 initial) is xs))
))
(define (MPI-rr-map fn xs #!key (comm (MPI:get-comm-world)))
(let (
(size (MPI:comm-size comm))
(myrank (MPI:comm-rank comm))
)
(cdr
(fold
(lambda (x myindex.ax)
(let ((myindex (car myindex.ax))
(ax (cdr myindex.ax)))
(cond
((= myindex myrank)
(let ((x1 (fn x))
(myindex1 (if (= myindex (- size 1)) 0 (+ 1 myindex))))
(cons myindex1 (cons x1 ax))))
(else (cons (if (= myindex (- size 1)) 0 (+ 1 myindex)) ax))
)
))
(cons 0 '()) xs))
))
(define (MPI-rr-for-each fn xs #!key (comm (MPI:get-comm-world)))
(let (
(size (MPI:comm-size comm))
(myrank (MPI:comm-rank comm))
)
(fold
(lambda (x myindex)
(cond
((= myindex myrank)
(let ((myindex1 (if (= myindex (- size 1)) 0 (+ 1 myindex))))
(fn x)
myindex1))
(else (if (= myindex (- size 1)) 0 (+ 1 myindex)))
))
0 xs)
))
)