-
Notifications
You must be signed in to change notification settings - Fork 14
/
comm.go
927 lines (723 loc) · 21.7 KB
/
comm.go
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
// Copyright (c) 2013 Alexander Beifuß <7beifuss@informatik.uni-hamburg.de>
// Johann Weging <johann@weging.net>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package MPI
/*
#include <stdlib.h>
#include <mpi.h>
*/
import "C"
import (
"unsafe"
)
//Accumulate
//Combines the contents of the origin buffer with that of a target buffer.
func Accumulate(originAddr interface{},
originCount int,
originDatatype Datatype,
targetRank int,
targetDisp Aint,
targetCount int,
targetDatatype Datatype,
op Op,
win Win) int {
originAddrVoidPointer := Get_void_ptr(originAddr)
return int(
C.MPI_Accumulate(originAddrVoidPointer,
C.int(originCount),
C.MPI_Datatype(originDatatype),
C.int(targetRank),
C.MPI_Aint(targetDisp),
C.int(targetCount),
C.MPI_Datatype(targetDatatype),
C.MPI_Op(op),
C.MPI_Win(win)))
}
//Add_error_class
//Creates a new error class and returns its value
func Add_error_class() (int, int) {
var errorClass C.int
err := C.MPI_Add_error_class(&errorClass)
return int(errorClass), int(err)
}
//Add_error_code
//Creates a new error code associated with errorclass
func Add_error_code(errorClass int) (int, int) {
var errorCode C.int
err := C.MPI_Add_error_code(C.int(errorClass), &errorCode)
return int(errorCode), int(err)
}
//Add_error_string
//Associates a string with an error code or class
func Add_error_string(errorCode int, errorString string) int {
err := C.MPI_Add_error_string(C.int(errorCode), C.CString(errorString))
return int(err)
}
//Allgather
//Gathers data from all processes and distributes it to all processes.
func Allgather(sendBuffer interface{},
sendCount int,
sendType Datatype,
recvBuffer interface{},
recvCount int,
recvType Datatype,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Allgather(sendBufferVoidPointer,
C.int(sendCount),
C.MPI_Datatype(sendType),
recvBufferVoidPointer,
C.int(recvCount),
C.MPI_Datatype(recvType),
C.MPI_Comm(comm))
return int(err)
}
//Allgatherv
//Gathers data from all processes and delivers it to all.
//Each process may contribute a different amount of data.
func Allgatherv(sendBuffer interface{},
sendCount int,
sendType Datatype,
recvBuffer interface{},
recvCount []int,
displacements []int,
recvType Datatype,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Allgatherv(sendBufferVoidPointer,
C.int(sendCount),
C.MPI_Datatype(sendType),
recvBufferVoidPointer,
(*C.int)(unsafe.Pointer(&recvCount[0])),
(*C.int)(unsafe.Pointer(&displacements[0])),
C.MPI_Datatype(recvType),
C.MPI_Comm(comm))
return int(err)
}
//Gather
//Gathers together values from a group of processes
func Gather(sendBuffer interface{},
sendCount int,
sendType Datatype,
recvBuffer interface{},
recvCount int,
recvType Datatype,
rootRank int,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Gather(sendBufferVoidPointer,
C.int(sendCount),
C.MPI_Datatype(sendType),
recvBufferVoidPointer,
C.int(recvCount),
C.MPI_Datatype(recvType),
C.int(rootRank),
C.MPI_Comm(comm))
return int(err)
}
//Gatherv
//Gathers into specified locations from all processes in a group
func Gatherv(sendBuffer interface{},
sendCount int,
sendType Datatype,
recvBuffer interface{},
recvCount []int,
displacements []int,
recvType Datatype,
rootRank int,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Gatherv(sendBufferVoidPointer,
C.int(sendCount),
C.MPI_Datatype(sendType),
recvBufferVoidPointer,
(*C.int)(unsafe.Pointer(&recvCount[0])),
(*C.int)(unsafe.Pointer(&displacements[0])),
C.MPI_Datatype(recvType),
C.int(rootRank),
C.MPI_Comm(comm))
return int(err)
}
//Alltoallv
//All processes send different amount of data to,
//and receive different amount of data from, all processes
func Alltoallv(sendBuffer interface{},
sendCounts []int,
sendDisplacements []int,
sendType Datatype,
recvBuffer interface{},
recvCounts []int,
recvDisplacements []int,
recvType Datatype,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Alltoallv(sendBufferVoidPointer,
(*C.int)(unsafe.Pointer(&sendCounts[0])),
(*C.int)(unsafe.Pointer(&sendDisplacements[0])),
C.MPI_Datatype(sendType),
recvBufferVoidPointer,
(*C.int)(unsafe.Pointer(&recvCounts[0])),
(*C.int)(unsafe.Pointer(&recvDisplacements[0])),
C.MPI_Datatype(recvType),
C.MPI_Comm(comm))
return int(err)
}
//Alltoallw
//All processes send data of different types to,
//and receive data of different types from, all processes
func Alltoallw(sendBuffer interface{},
sendCounts []int,
sendDisplacements []int,
sendTypes []Datatype,
recvBuffer interface{},
recvCounts []int, recvDisplacements []int, recvTypes []Datatype, comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Alltoallw(sendBufferVoidPointer,
(*C.int)(unsafe.Pointer(&sendCounts[0])),
(*C.int)(unsafe.Pointer(&sendDisplacements[0])),
(*C.MPI_Datatype)(unsafe.Pointer(&sendTypes[0])),
recvBufferVoidPointer,
(*C.int)(unsafe.Pointer(&recvCounts[0])),
(*C.int)(unsafe.Pointer(&recvDisplacements[0])),
(*C.MPI_Datatype)(unsafe.Pointer(&recvTypes[0])),
C.MPI_Comm(comm))
return int(err)
}
//Bsend_init
//Builds a handle for a buffered send.
func MPI_Bsend_init(sendBuffer interface{},
count int,
dataType Datatype,
dest int,
tag int,
comm Comm) (Request, int) {
var request C.MPI_Request
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
err := C.MPI_Bsend_init(sendBufferVoidPointer,
C.int(count),
C.MPI_Datatype(dataType),
C.int(dest),
C.int(tag),
C.MPI_Comm(comm),
&request)
return Request(request), int(err)
}
//Comm_group
//Returns the group associated with a communicator.
func Comm_group(comm Comm) (Group, int) {
var group C.MPI_Group
err := C.MPI_Comm_group(C.MPI_Comm(comm), &group)
return Group(group), int(err)
}
//Comm_join
//Establishes communication between MPI jobs
func Comm_join(fd int) (Comm, int) {
var interComm C.MPI_Comm
err := C.MPI_Comm_join(C.int(fd), &interComm)
return Comm(interComm), int(err)
}
//Comm_accept
//Establishes communication with a client.
func Comm_accept(portName string, info Info, root int, comm Comm) (Comm, int) {
var newComm C.MPI_Comm
err := C.MPI_Comm_accept(C.CString(portName),
C.MPI_Info(info),
C.int(root),
C.MPI_Comm(comm),
&newComm)
return Comm(newComm), int(err)
}
//Comm_call_errhandler
//Passes the supplied error code to the
func Comm_call_errhandler(comm Comm, errorCode int) int {
err := C.MPI_Comm_call_errhandler(C.MPI_Comm(comm), C.int(errorCode))
return int(err)
}
//Comm_compare
//Compares two communicators.
func Comm_compare(comm1 Comm, comm2 Comm) (int, int) {
var result C.int
err := C.MPI_Comm_compare(C.MPI_Comm(comm1), C.MPI_Comm(comm2), &result)
return int(result), int(err)
}
//Comm_connect
//Establishes communication with a server.
func Comm_connect(portName string, info Info, root int, comm Comm) (Comm, int) {
var newComm C.MPI_Comm
err := C.MPI_Comm_connect(C.CString(portName),
C.MPI_Info(info),
C.int(root),
C.MPI_Comm(comm),
&newComm)
return Comm(newComm), int(err)
}
//Comm_create
//Creates a new communicator.
func Comm_create(comm Comm, group Group) (Comm, int) {
var newComm C.MPI_Comm
err := C.MPI_Comm_create(C.MPI_Comm(comm), C.MPI_Group(group), &newComm)
return Comm(newComm), int(err)
}
//Comm_disconnect
//Deallocates communicator object and sets handle to MPI_COMM_NULL.
func Comm_disconnect(comm *Comm) int {
err := C.MPI_Comm_disconnect((*C.MPI_Comm)(unsafe.Pointer(comm)))
return int(err)
}
//Comm_free
//Mark a communicator object for deallocation.
func Comm_free(comm *Comm) int {
err := C.MPI_Comm_free((*C.MPI_Comm)(unsafe.Pointer(comm)))
return int(err)
}
//Comm_rank
//Determines the rank of the calling process in the communicator.
func Comm_rank(comm Comm) (int, int) {
var rank C.int
err := C.MPI_Comm_rank(C.MPI_Comm(comm), &rank)
return int(rank), int(err)
}
//Comm_size
//Returns the size of the group associated with a communicator.
func Comm_size(comm Comm) (int, int) {
var size C.int
err := C.MPI_Comm_size(C.MPI_Comm(comm), &size)
return int(size), int(err)
}
//Comm_split
//Creates new communicators based on colors and keys.
func Comm_split(comm Comm, color, key int) (Comm, int) {
var newComm C.MPI_Comm
err := C.MPI_Comm_split(C.MPI_Comm(comm), C.int(color), C.int(key), &newComm)
return Comm(newComm), int(err)
}
//Comm_dup
//Duplicates an existing communicator with all its cached information.
func Comm_dup(comm Comm) (Comm, int) {
var newComm C.MPI_Comm
err := C.MPI_Comm_dup(C.MPI_Comm(comm), &newComm)
return Comm(newComm), int(err)
}
//Send
//Performs a standard-mode blocking send.
func Send(buffer interface{},
count int,
dataType Datatype,
dest int,
tag int,
comm Comm) int {
bufferVoidPointer := Get_void_ptr(buffer)
err := C.MPI_Send(bufferVoidPointer,
C.int(count),
C.MPI_Datatype(dataType),
C.int(dest),
C.int(tag),
C.MPI_Comm(comm))
return int(err)
}
//Recv
//Performs a standard-mode blocking receive.
func Recv(buffer interface{},
count int,
dataType Datatype,
source int,
tag int,
comm Comm) (Status, int) {
var status C.MPI_Status
bufferVoidPointer := Get_void_ptr(buffer)
err := C.MPI_Recv(bufferVoidPointer,
C.int(count),
C.MPI_Datatype(dataType),
C.int(source),
C.int(tag),
C.MPI_Comm(comm),
&status)
return Status(status), int(err)
}
//Barrier
//Blocks until all processes have reached this routine.
func Barrier(comm Comm) int {
err := C.MPI_Barrier(C.MPI_Comm(comm))
return int(err)
}
//Bcast
//Broadcasts a message from the process with rank root to all other processes of the group.
func Bcast(buffer interface{},
count int,
dataType Datatype,
root int,
comm Comm) int {
bufferVoidPointer := Get_void_ptr(buffer)
err := C.MPI_Bcast(bufferVoidPointer,
C.int(count),
C.MPI_Datatype(dataType),
C.int(root),
C.MPI_Comm(comm))
return int(err)
}
//Bsend
//Basic send with user-specified buffering.
func Bsend(buffer interface{},
count int,
dataType Datatype,
dest int,
tag int,
comm Comm) int {
bufferVoidPointer := Get_void_ptr(buffer)
err := C.MPI_Bsend(bufferVoidPointer,
C.int(count),
C.MPI_Datatype(dataType),
C.int(dest),
C.int(tag),
C.MPI_Comm(comm))
return int(err)
}
//MPI_Probe
//Blocking test for a message.
func Probe(source int, tag int, comm Comm) (Status, int) {
var status C.MPI_Status
err := C.MPI_Probe(
C.int(source),
C.int(tag),
C.MPI_Comm(comm),
&status)
return Status(status), int(err)
}
//Get_count
//Gets the number of top-level elements received.
func Get_count(status Status, dataType Datatype) (int, int) {
var count C.int
var cStatus C.MPI_Status
cStatus = C.MPI_Status(status)
err := C.MPI_Get_count(&cStatus, C.MPI_Datatype(dataType), &count)
return int(count), int(err)
}
//Allreduce
//Combines values from all processes and distributes the result back to all processes.
func Allreduce(sendBuffer interface{},
recvBuffer interface{},
count int,
dataType Datatype,
op Op,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Allreduce(sendBufferVoidPointer,
recvBufferVoidPointer,
C.int(count),
C.MPI_Datatype(dataType),
C.MPI_Op(op),
C.MPI_Comm(comm))
return int(err)
}
//Alltoall
//All processes send data to all processes
func Alltoall(sendBuffer interface{},
sendCount int,
sendType Datatype,
recvBuffer interface{},
recvCount int,
recvType Datatype,
comm Comm) int {
sendBufferVoidPointer := Get_void_ptr(sendBuffer)
recvBufferVoidPointer := Get_void_ptr(recvBuffer)
err := C.MPI_Alltoall(sendBufferVoidPointer,
C.int(sendCount),
C.MPI_Datatype(sendType),
recvBufferVoidPointer,
C.int(recvCount),
C.MPI_Datatype(recvType),
C.MPI_Comm(comm))
return int(err)
}
//Isend
//Starts a standard-mode, nonblocking send.
func Isend(buffer interface{},
sendCount int,
dataType Datatype,
dest int,
tag int,
comm Comm,
request *Request) int {
bufferVoidPointer := Get_void_ptr(buffer)
cRequestPointer := (*C.MPI_Request)(request)
err := C.MPI_Isend(bufferVoidPointer,
C.int(sendCount),
C.MPI_Datatype(dataType),
C.int(dest),
C.int(tag),
C.MPI_Comm(comm),
cRequestPointer)
return int(err)
}
// Irecv
// Begins a nonblocking receive
func Irecv(buffer interface{},
count int,
datatype Datatype,
source int,
tag int,
comm Comm,
request *Request) int {
recvBufferVoidPointer := Get_void_ptr(buffer)
err := C.MPI_Irecv(recvBufferVoidPointer,
C.int(count),
C.MPI_Datatype(datatype),
C.int(source),
C.int(tag),
C.MPI_Comm(comm),
(*C.MPI_Request)(request))
return int(err)
}
//Wait
//Waits for an MPI send or receive to complete.
func Wait(request *Request) (Status, int) {
var status C.MPI_Status
var cRequest *C.MPI_Request
cRequest = (*C.MPI_Request)(request)
err := C.MPI_Wait(cRequest, &status)
return Status(status), int(err)
}
//Waitall
//Waits for all given communications to complete.
func Waitall(sliceOfRequests []Request) ([]Status, int) {
length := len(sliceOfRequests)
cSliceOfRequests := (*C.MPI_Request)(&sliceOfRequests[0])
sliceOfStatuses := make([]Status, length)
cSliceOfStatuses := make([]C.MPI_Status, length)
err := C.MPI_Waitall(C.int(length), cSliceOfRequests, &cSliceOfStatuses[0])
for i := 0; i < length; i++ {
sliceOfStatuses[i] = Status(cSliceOfStatuses[i])
}
return sliceOfStatuses, int(err)
}
//MPI_Waitany
//Waits for any specified send or receive to complete.
func Waitany(sliceOfRequests []Request) (int, Status, int) {
length := len(sliceOfRequests)
cSliceOfRequests := (*C.MPI_Request)(&sliceOfRequests[0])
var index C.int
var status C.MPI_Status
err := C.MPI_Waitany(C.int(length), cSliceOfRequests, &index, &status)
return int(index), Status(status), int(err)
}
//MPI_Waitsome
//Waits for some given communications to complete.
func Waitsome(sliceOfRequests []Request) (int, []int, []Status, int) {
length := len(sliceOfRequests)
cSliceOfRequests := (*C.MPI_Request)(&sliceOfRequests[0])
cSliceOfIndices := make([]C.int, length)
cSliceOfStatuses := make([]C.MPI_Status, length)
sliceOfIndices := make([]int, length)
sliceOfStatuses := make([]Status, length)
var count C.int
err := C.MPI_Waitsome(C.int(length), cSliceOfRequests, &count, &cSliceOfIndices[0], &cSliceOfStatuses[0])
for i := 0; i < length; i++ {
sliceOfIndices[i] = int(cSliceOfIndices[i])
sliceOfStatuses[i] = Status(cSliceOfStatuses[i])
}
return int(count), sliceOfIndices, sliceOfStatuses, int(err)
}
// int MPI_Comm_create_keyval(MPI_Comm_copy_attr_function *comm_copy_attr_fn, MPI_Comm_delete_attr_function *comm_delete_attr_fn, int *comm_keyval, void *extra_state);
// Comm_delete_attr
// Deletes an attribute value associated with a key on a communicator
func Comm_delete_attr(comm Comm, commKeyval int) int {
return int(C.MPI_Comm_delete_attr(C.MPI_Comm(comm), C.int(commKeyval)))
}
// Comm_free_keyval
// Frees an attribute key for communicators
func Comm_free_keyval(commKeyval int) (int, int) {
var cCommKeyval C.int
cCommKeyval = C.int(commKeyval)
err := C.MPI_Comm_free_keyval(&cCommKeyval)
return int(cCommKeyval), int(err)
}
//Comm_get_attr
//Retrieves attribute value by key
func Comm_get_attr(comm Comm, commKeyval int) (uintptr, bool, int) {
var attributeVal uintptr
var cflag C.int
flag := false
err := C.MPI_Comm_get_attr(C.MPI_Comm(comm),
C.int(commKeyval),
unsafe.Pointer(attributeVal),
&cflag)
if int(cflag) != 0 {
flag = true
}
return attributeVal, flag, int(err)
}
//Comm_get_errhandler
//Get the error handler attached to a communicator
func Comm_get_errhandler(comm Comm) (Errhandler, int) {
var errhandler C.MPI_Errhandler
err := C.MPI_Comm_get_errhandler(C.MPI_Comm(comm), &errhandler)
return Errhandler(errhandler), int(err)
}
//Comm_get_name
//Return the print name from the communicator
func Comm_get_name(comm Comm) (string, int) {
// var cstr *C.char
var strLength C.int
var commName string
cstr := C.malloc(C.size_t(MAX_BUFFER_SIZE))
err := C.MPI_Comm_get_name(C.MPI_Comm(comm), (*C.char)(cstr), &strLength)
commName = C.GoStringN((*C.char)(cstr), strLength)
C.free(cstr)
return commName, int(err)
}
//Comm_get_parent
//Return the parent communicator for this process
func Comm_get_parent() (Comm, int) {
var comm C.MPI_Comm
err := C.MPI_Comm_get_parent(&comm)
return Comm(comm), int(err)
}
//Comm_remote_group
//Accesses the remote group associated with the given inter-communicator
func Comm_remote_group(comm Comm) (Group, int) {
var group C.MPI_Group
err := C.MPI_Comm_remote_group(C.MPI_Comm(comm), &group)
return Group(group), int(err)
}
//Comm_remote_size
//Determines the size of the remote group associated with an inter-communictor
func Comm_remote_size(comm Comm) (int, int) {
var size C.int
err := C.MPI_Comm_remote_size(C.MPI_Comm(comm), &size)
return int(size), int(err)
}
//Comm_set_attr
//Stores attribute value associated with a key
func Comm_set_attr(comm Comm, commKeyval int, attributeVal interface{}) int {
attributeValVoidPointer := Get_void_ptr(attributeVal)
return int(C.MPI_Comm_set_attr(C.MPI_Comm(comm),
C.int(commKeyval),
attributeValVoidPointer))
}
//Comm_set_errhandler
//Set the error handler for a communicator
func Comm_set_errhandler(comm Comm, errhandler Errhandler) (Comm, int) {
cComm := C.MPI_Comm(comm)
cErrhandler := C.MPI_Errhandler(errhandler)
err := C.MPI_Comm_set_errhandler(cComm, cErrhandler)
return Comm(cComm), int(err)
}
//Comm_set_name
//Sets the print name for a communicator
func Comm_set_name(comm Comm, commName string) int {
cCommName := C.CString(commName)
err := C.MPI_Comm_set_name(C.MPI_Comm(comm),
cCommName)
C.free(unsafe.Pointer(cCommName))
return int(err)
}
//Comm_spawn
//Spawn up to maxprocs instances of a single MPI application
func Comm_spawn(command string, arguments []string, maxProcs int,
info Info, root int, comm Comm) (Comm, []int, int) {
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
numberOfArguments := len(arguments)
var cArguments [](*C.char)
var intercomm C.MPI_Comm
cArrayOfErrorcodes := make([]C.int, maxProcs)
arrayOfErrorcodes := make([]int, maxProcs)
for i := 0; i < numberOfArguments; i++ {
cArguments[i] = C.CString(arguments[i])
}
err := C.MPI_Comm_spawn(cCommand,
&cArguments[0],
C.int(maxProcs),
C.MPI_Info(info),
C.int(root),
C.MPI_Comm(comm),
&intercomm,
(*C.int)(&cArrayOfErrorcodes[0]))
for i := 0; i < maxProcs; i++ {
arrayOfErrorcodes[i] = int(cArrayOfErrorcodes[i])
}
for i := 0; i < numberOfArguments; i++ {
C.free(unsafe.Pointer(cArguments[i]))
}
return Comm(intercomm), arrayOfErrorcodes, int(err)
}
//TODO: Double/Triple Pointers make trouble... I think we have to
//do this in c!
//Comm_spawn_multiple
//While MPI_COMM_SPAWN is sufficient for most cases, it does not
//allow the spawning of multiple binaries, or of the same binary
//with multiple sets of arguments. The following routine spawns
//multiple binaries or the same binary with multiple sets of arguments,
//establishing communication with them and placing them in the
//same MPI_COMM_WORLD.
// func Comm_spawn_multiple(count int, commands []string, arguments [][]string,
// maxProcs []int, infos []Info, root int, comm Comm) (Comm, []int, int) {
// numberOfCommands := len(commands)
// cCommands := make([](*C.char), numberOfCommands)
// cMaxProcs := make([]C.int, numberOfCommands)
// cInfos := make([]C.MPI_Info, numberOfCommands)
// cArguments := make([]([]*C.char), numberOfCommands)
// var totalProcs C.int
// totalProcs = 0
// for i := 0; i < numberOfCommands; i++ {
// cCommands[i] = C.CString(commands[i])
// cMaxProcs[i] = C.int(maxProcs[i])
// totalProcs += C.int(maxProcs[i])
// cInfos[i] = C.MPI_Info(infos[i])
// cArguments[i] = make([](*C.char), len(arguments[i]))
// for j := 0; j < len(arguments[i]); j++ {
// cArguments[i][j] = C.CString(arguments[i][j])
// }
// }
// var intercomm C.MPI_Comm
// cArrayOfErrorcodes := make([]C.int, totalProcs)
// arrayOfErrorcodes := make([]int, totalProcs)
// err := C.MPI_Comm_spawn_multiple(C.int(count),
// &cCommands[0],
// &((**C.char)(cArguments[0])),
// &cMaxProcs[0],
// &cInfos[0],
// C.int(root),
// C.MPI_Comm(comm),
// &intercomm,
// (*C.int)(&cArrayOfErrorcodes[0]))
// for i := 0; i < int(totalProcs); i++ {
// arrayOfErrorcodes[i] = int(cArrayOfErrorcodes[i])
// }
// for i := 0; i < numberOfCommands; i++ {
// C.free(unsafe.Pointer(cCommands[i]))
// for j := 0; j < len(arguments[i]); j++ {
// C.free(unsafe.Pointer(cArguments[i][j]))
// }
// }
// return Comm(intercomm), arrayOfErrorcodes, int(err)
// }
//Comm_test_inter
//Tests to see if a comm is an inter-communicator
func Comm_test_inter(comm Comm) (bool, int) {
var cFlag C.int
flag := false
err := C.MPI_Comm_test_inter(C.MPI_Comm(comm), &cFlag)
if int(cFlag) != 0 {
flag = true
}
return flag, int(err)
}