-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntracomm.java
More file actions
956 lines (853 loc) · 36.9 KB
/
Copy pathIntracomm.java
File metadata and controls
956 lines (853 loc) · 36.9 KB
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
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
/*
* File : Intracommm.java
* Author : Sang Lim, Xinying Li, Bryan Carpenter
* Created : Thu Apr 9 12:22:15 1998
* Revision : $Revision: 1.14 $
* Updated : $Date: 2002/12/16 15:25:13 $
* Copyright: Northeast Parallel Architectures Center
* at Syracuse University 1998
*/
package mpi;
public class Intracomm extends Comm {
Intracomm() {}
void setType(int type) {
super.setType(type) ;
shadow = new Comm(dup()) ;
}
protected Intracomm(long handle) throws MPIException {
super(handle) ;
shadow = new Comm(dup()) ;
}
public Object clone() {
try {
return new Intracomm(dup()) ;
}
catch (MPIException e) {
throw new RuntimeException(e.getMessage()) ;
}
}
/**
* Partition the group associated with this communicator and create
* a new communicator within each subgroup.
* <p>
* <table>
* <tr><td><tt> color </tt></td><td> control of subset assignment </tr>
* <tr><td><tt> key </tt></td><td> control of rank assignment </tr>
* <tr><td><em> returns: </em></td><td> new communicator </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_COMM_SPLIT</tt>.
*/
public Intracomm Split(int colour, int key) throws MPIException {
long splitHandle = split(colour,key) ;
if(splitHandle == nullHandle)
return null ;
else
return new Intracomm(splitHandle) ;
}
private native long split(int colour, int key);
/**
* Create a new communicator.
* <p>
* <table>
* <tr><td><tt> group </tt></td><td> group which is a subset of the
* group of this communicator </tr>
* <tr><td><em> returns: </em></td><td> new communicator </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_COMM_CREATE</tt>.
*/
public Intracomm Creat(Group group) throws MPIException {
long creatHandle = creat(group) ;
if(creatHandle == nullHandle)
return null ;
else
return new Intracomm(creatHandle) ;
}
private native long creat(Group group);
// Collective Communication
/**
* A call to <tt>Barrier</tt> blocks the caller until all process
* in the group have called it.
* <p>
* Java binding of the MPI operation <tt>MPI_BARRIER</tt>.
*/
public native void Barrier() throws MPIException ;
/*
* The type signature of `incount * intype' must be equal to the type
* signature of `outcount * outtype' (ie they must represent the same
* number of basic elements of the same type).
*/
private void copyBuffer(Object inbuf,
int inoffset, int incount, Datatype intype,
Object outbuf,
int outoffset, int outcount, Datatype outtype)
throws MPIException {
if(intype.isObject()) {
Object [] inbufArray = (Object[])inbuf;
Object [] outbufArray = (Object[])outbuf;
int outbase = outoffset, inbase = inoffset ;
int kout = 0 ;
for (int j = 0 ; j < incount ; j++) {
for (int k = 0 ; k < intype.displacements.length ; k++)
outbufArray [outbase + outtype.displacements [kout]] =
inbufArray [inbase + intype.displacements [k]] ;
inbase += intype.Extent() ;
kout++;
if (kout == outtype.displacements.length){
kout = 0;
outbase += outtype.Extent() ;
}
}
}
else {
byte [] tmpbuf = new byte [Pack_size(incount, intype)] ;
Pack(inbuf, inoffset, incount, intype, tmpbuf, 0) ;
Unpack(tmpbuf, 0, outbuf, outoffset, outcount, outtype) ;
}
}
private Object newBuffer(Object template) {
if(template instanceof Object[])
return new Object [((Object[]) template).length] ;
if(template instanceof byte[])
return new byte [((byte[]) template).length] ;
if(template instanceof char[])
return new char [((char[]) template).length] ;
if(template instanceof short[])
return new short [((short[]) template).length] ;
if(template instanceof boolean[])
return new boolean [((boolean[]) template).length] ;
if(template instanceof int[])
return new int [((int[]) template).length] ;
if(template instanceof long[])
return new long [((long[]) template).length] ;
if(template instanceof float[])
return new float [((float[]) template).length] ;
if(template instanceof double[])
return new double [((double[]) template).length] ;
return null ;
}
/**
* Broadcast a message from the process with rank <tt>root</tt>
* to all processes of the group.
* <p>
* <table>
* <tr><td><tt> buf </tt></td><td> buffer array </tr>
* <tr><td><tt> offset </tt></td><td> initial offset in buffer </tr>
* <tr><td><tt> count </tt></td><td> number of items in buffer </tr>
* <tr><td><tt> datatype </tt></td><td> datatype of each item in
* buffer </tr>
* <tr><td><tt> root </tt></td><td> rank of broadcast root </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_BCST</tt>.
*/
public void Bcast(Object buf,
int offset,
int count,
Datatype type,
int root) throws MPIException {
if (type.isObject()){
if (Rank() == root){
for (int dst = 0; dst < Size(); dst++)
if (dst != root)
shadow.Send(buf, offset, count, type, dst, 0);
}
else
shadow.Recv(buf, offset, count, type, root, 0);
}
else
bcast(buf, offset*type.Size(), count, type, root);
}
private native void bcast(Object buf,
int offset,
int count,
Datatype type,
int root);
/**
* Each process sends the contents of its send buffer to the
* root process.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcount </tt></td><td> number of items to send </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype of each item in send
* buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcount </tt></td><td> number of items to receive </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* <tr><td><tt> root </tt></td><td> rank of receiving process </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_GATHER</tt>.
*/
public void Gather(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype,
int root) throws MPIException {
if (sendtype.isObject()) {
if (Rank() == root) {
for (int src = 0; src < Size(); src++) {
int dstOffset = recvoffset + recvcount * recvtype.Extent() * src ;
if (src == root)
copyBuffer(sendbuf, sendoffset, sendcount, sendtype,
recvbuf, dstOffset, recvcount, recvtype) ;
else
shadow.Recv(recvbuf, dstOffset, recvcount, recvtype, src, 0);
}
}
else
shadow.Send(sendbuf, sendoffset, sendcount, sendtype, root, 0);
}
else
gather(sendbuf, sendoffset*sendtype.Size(), sendcount,sendtype,
recvbuf, recvoffset*recvtype.Size(), recvcount,recvtype,
root);
}
private native void gather(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype,
int root);
/**
* Extends functionality of <tt>Gather</tt> by allowing varying
* counts of data from each process.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcount </tt></td><td> number of items to send </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype of each item in send
* buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcounts </tt></td><td> number of elements received from
* each process </tr>
* <tr><td><tt> displs </tt></td><td> displacements at which to place
* incoming data </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* <tr><td><tt> root </tt></td><td> rank of receiving process </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_GATHERV</tt>.
* <p>
* The sizes of arrays <tt>recvcounts</tt> and <tt>displs</tt> should be the
* size of the group. Entry <em>i</em> of <tt>displs</tt> specifies the
* displacement relative to element <tt>recvoffset</tt> of <tt>recvbuf</tt>
* at which to place incoming data.
*/
public void Gatherv(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int [] recvcount,
int [] displs,
Datatype recvtype,
int root) throws MPIException {
if (sendtype.isObject()){
if (Rank() == root){
for (int src = 0; src < Size(); src++){
int dstOffset = recvoffset + sendtype.Extent() * displs[src] ;
if (src == root)
copyBuffer(sendbuf, sendoffset, sendcount,sendtype,
recvbuf, dstOffset, recvcount[src], recvtype);
else
shadow.Recv(recvbuf, dstOffset, recvcount[src], recvtype, src, 0);
}
}
else
shadow.Send(sendbuf, sendoffset, sendcount, sendtype, root, 0);
}
else
gatherv(sendbuf , sendoffset*sendtype.Size(),
sendcount, sendtype,
recvbuf , recvoffset*recvtype.Size(),
recvcount, displs,
recvtype , root);
}
private native void gatherv(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int [] recvcount,
int [] displs,
Datatype recvtype,
int root);
/**
* Inverse of the operation <tt>Gather</tt>.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcount </tt></td><td> number of items to send </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype of each item in send
* buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcount </tt></td><td> number of items to receive </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* <tr><td><tt> root </tt></td><td> rank of sending process </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_SCATTER</tt>.
*/
public void Scatter(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype,
int root) throws MPIException {
if (sendtype.isObject()){
if (Rank() == root){
for (int dst = 0; dst < Size() ; dst++){
int srcOffset = sendoffset + sendcount * sendtype.Extent() * dst ;
if (dst == root)
copyBuffer(sendbuf, srcOffset, sendcount, sendtype,
recvbuf, recvoffset, recvcount, recvtype);
else
shadow.Send(sendbuf, srcOffset, sendcount, sendtype, dst, 0);
}
}
else
shadow.Recv(recvbuf, recvoffset, recvcount, recvtype, root, 0);
}
else
scatter(sendbuf, sendoffset*sendtype.Size(), sendcount, sendtype,
recvbuf, recvoffset*recvtype.Size(), recvcount, recvtype,
root);
}
private native void scatter(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype,
int root);
/**
* Inverse of the operation <tt>Gatherv</tt>.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcounts </tt></td><td> number of items sent to each
* process </tr>
* <tr><td><tt> displs </tt></td><td> displacements from which to take
* outgoing data </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype of each item in send
* buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcount </tt></td><td> number of items to receive </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* <tr><td><tt> root </tt></td><td> rank of sending process </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_SCATTERV</tt>.
*/
public void Scatterv(Object sendbuf,
int sendoffset,
int [] sendcount,
int [] displs,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype,
int root) throws MPIException {
if (sendtype.isObject()){
if (Rank() == root){
for (int dst = 0 ; dst < Size() ; dst++){
int srcOffset = sendoffset + sendtype.Extent() * displs[dst] ;
if (dst == root)
copyBuffer(sendbuf, srcOffset, sendcount[dst], sendtype,
recvbuf, recvoffset, recvcount, recvtype);
else
shadow.Send(sendbuf, srcOffset, sendcount[dst], sendtype, dst, 0);
}
}
else
shadow.Recv(recvbuf, recvoffset, recvcount, recvtype, root, 0);
}
else
scatterv(sendbuf, sendoffset * sendtype.Size(), sendcount,
displs, sendtype,
recvbuf, recvoffset * recvtype.Size(), recvcount, recvtype,
root);
}
private native void scatterv(Object sendbuf,
int sendoffset,
int [] sendcount,
int [] displs,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype,
int root);
/**
* Similar to <tt>Gather</tt>, but all processes receive the result.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcount </tt></td><td> number of items to send </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype of each item in send
* buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcount </tt></td><td> number of items to receive </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_ALLGATHER</tt>.
*/
public void Allgather(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype) throws MPIException {
if (sendtype.isObject()){
Gather(sendbuf, sendoffset, sendcount, sendtype,
recvbuf, recvoffset, recvcount, recvtype, 0);
Bcast(recvbuf, recvoffset, Size() * recvcount, recvtype, 0);
}
else
allgather(sendbuf, sendoffset*sendtype.Size(),
sendcount, sendtype,
recvbuf, recvoffset*recvtype.Size(),
recvcount, recvtype);
}
private native void allgather(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype);
/**
* Similar to <tt>Gatherv</tt>, but all processes receive the result.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcount </tt></td><td> number of items to send </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype of each item in send
* buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcounts </tt></td><td> number of elements received from
* each process </tr>
* <tr><td><tt> displs </tt></td><td> displacements at which to place
* incoming data </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_ALLGATHERV</tt>.
*/
public void Allgatherv(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int [] recvcount,
int [] displs,
Datatype recvtype) throws MPIException {
if (sendtype.isObject()){
Gatherv(sendbuf, sendoffset, sendcount, sendtype,
recvbuf, recvoffset, recvcount, displs, recvtype, 0);
for (int src = 0; src < Size(); src++){
int dstOffset = recvoffset + sendtype.Extent() * displs[src] ;
Bcast(recvbuf, dstOffset, recvcount[src], recvtype, 0);
}
}
else
allgatherv(sendbuf , sendoffset*sendtype.Size(),
sendcount, sendtype,
recvbuf , recvoffset*recvtype.Size(),
recvcount, displs,
recvtype);
}
private native void allgatherv(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int [] recvcount,
int [] displs,
Datatype recvtype);
/**
* Extension of <tt>Allgather</tt> to the case where each process sends
* distinct data to each of the receivers.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcount </tt></td><td> number of items sent to each
* process </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype send buffer items </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcount </tt></td><td> number of items received from any
* process
* <tr><td><tt> recvtype </tt></td><td> datatype of receive buffer
* items </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_ALLTOALL</tt>.
*/
public void Alltoall(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype) throws MPIException {
if (sendtype.isObject())
for (int dst = 0; dst < Size(); dst++) {
int srcOffset = sendoffset + sendcount * sendtype.Extent() * dst ;
Gather(sendbuf, srcOffset, sendcount, sendtype,
recvbuf, recvoffset, recvcount, recvtype, dst);
}
else
alltoall(sendbuf, sendoffset*sendtype.Size(),
sendcount, sendtype,
recvbuf, recvoffset*recvtype.Size(),
recvcount, recvtype);
}
private native void alltoall(Object sendbuf,
int sendoffset,
int sendcount,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int recvcount,
Datatype recvtype);
/**
* Adds flexibility to <tt>Alltoall</tt>: location of data for send is
* specified by <tt>sdispls</tt> and location to place data on receive
* side is specified by <tt>rdispls</tt>.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> sendcounts </tt></td><td> number of items sent to each
* process </tr>
* <tr><td><tt> sdispls </tt></td><td> displacements from which to take
* outgoing data </tr>
* <tr><td><tt> sendtype </tt></td><td> datatype send buffer items </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcounts </tt></td><td> number of elements received from
* each process
* <tr><td><tt> rdispls </tt></td><td> displacements at which to place
* incoming data </tr>
* <tr><td><tt> recvtype </tt></td><td> datatype of each item in receive
* buffer </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_ALLTOALLV</tt>.
*/
public void Alltoallv(Object sendbuf,
int sendoffset,
int [] sendcount,
int [] sdispls,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int [] recvcount,
int [] rdispls,
Datatype recvtype) throws MPIException {
if (sendtype.isObject())
for (int dst = 0; dst < Size(); dst++) {
int srcOffset = sendoffset + sendtype.Extent() * sdispls[dst] ;
Gatherv(sendbuf, srcOffset, sendcount[dst], sendtype,
recvbuf, recvoffset, recvcount, rdispls, recvtype, dst);
}
else
alltoallv(sendbuf, sendoffset*sendtype.Size(),
sendcount, sdispls, sendtype,
recvbuf, recvoffset*recvtype.Size(),
recvcount, rdispls, recvtype);
}
private native void alltoallv(Object sendbuf,
int sendoffset,
int [] sendcount,
int [] sdispls,
Datatype sendtype,
Object recvbuf,
int recvoffset,
int [] recvcount,
int [] displs,
Datatype recvtype);
/**
* Combine elements in input buffer of each process using the reduce
* operation, and return the combined value in the output buffer of the
* root process.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> count </tt></td><td> number of items in send buffer </tr>
* <tr><td><tt> datatype </tt></td><td> data type of each item in send
* buffer </tr>
* <tr><td><tt> op </tt></td><td> reduce operation </tr>
* <tr><td><tt> root </tt></td><td> rank of root process </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_REDUCE</tt>.
* <p>
* The predefined operations are available in Java as <tt>MPI.MAX</tt>,
* <tt>MPI.MIN</tt>, <tt>MPI.SUM</tt>, <tt>MPI.PROD</tt>, <tt>MPI.LAND</tt>,
* <tt>MPI.BAND</tt>, <tt>MPI.LOR</tt>, <tt>MPI.BOR</tt>, <tt>MPI.LXOR</tt>,
* <tt>MPI.BXOR</tt>, <tt>MPI.MINLOC</tt> and <tt>MPI.MAXLOC</tt>.
*/
public void Reduce(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int count,
Datatype datatype, Op op, int root) throws MPIException {
if (op.isUser()) {
if (Rank() == root) {
copyBuffer(sendbuf,sendoffset,count,datatype,
recvbuf,recvoffset,count,datatype);
Object tempbuf = newBuffer(recvbuf) ;
for (int src = 0; src < Size(); src++)
if(src != root) {
shadow.Recv(tempbuf, 0, count, datatype, src, 0);
op.Call(tempbuf, 0, recvbuf, recvoffset, count, datatype);
}
}
else
shadow.Send(sendbuf, sendoffset, count, datatype, root, 0);
}
else
reduce(sendbuf, sendoffset, recvbuf, recvoffset, count,
datatype, op, root) ;
}
private native void reduce(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int count,
Datatype datatype, Op op, int root);
/**
* Same as <tt>reduce</tt> except that the result appears in receive
* buffer of all process in the group.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> count </tt></td><td> number of items in send buffer </tr>
* <tr><td><tt> datatype </tt></td><td> data type of each item in send
* buffer </tr>
* <tr><td><tt> op </tt></td><td> reduce operation </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_ALLREDUCE</tt>.
*/
public void Allreduce(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int count,
Datatype datatype, Op op) throws MPIException {
if (op.isUser()){
Reduce(sendbuf, sendoffset,
recvbuf, recvoffset, count, datatype, op, 0);
Bcast(recvbuf, recvoffset, count, datatype, 0);
}
else {
allreduce(sendbuf, sendoffset, recvbuf, recvoffset, count,
datatype, op) ;
}
}
private native void allreduce(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int count,
Datatype datatype, Op op) ;
/**
* Combine elements in input buffer of each process using the reduce
* operation, and scatter the combined values over the output buffers
* of the processes.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> recvcounts </tt></td><td> numbers of result elements
* distributed to each process </tr>
* <tr><td><tt> datatype </tt></td><td> data type of each item in send
* buffer </tr>
* <tr><td><tt> op </tt></td><td> reduce operation </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_REDUCE_SCATTER</tt>.
*/
public void Reduce_scatter(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int [] recvcounts,
Datatype datatype, Op op) throws MPIException {
if (op.isUser()) {
int [] displs = new int [recvcounts.length] ;
int count = 0 ;
for (int i = 0; i < recvcounts.length; i++) {
displs [i] = count ;
count += recvcounts [i] ;
}
Object tempbuf = newBuffer(sendbuf) ;
copyBuffer(sendbuf,sendoffset,count,datatype,
tempbuf,sendoffset,count,datatype);
Reduce(tempbuf, sendoffset, sendbuf, sendoffset, count,
datatype, op, 0);
Scatterv(tempbuf, sendoffset, recvcounts, displs, datatype,
recvbuf, recvoffset, recvcounts[Rank()], datatype, 0);
}
else
reduce_scatter(sendbuf, sendoffset, recvbuf, recvoffset, recvcounts,
datatype, op) ;
}
private native void reduce_scatter(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset,
int [] recvcounts,
Datatype datatype, Op op) ;
/**
* Perform a prefix reduction on data distributed across the group.
* <p>
* <table>
* <tr><td><tt> sendbuf </tt></td><td> send buffer array </tr>
* <tr><td><tt> sendoffset </tt></td><td> initial offset in send buffer </tr>
* <tr><td><tt> recvbuf </tt></td><td> receive buffer array </tr>
* <tr><td><tt> recvoffset </tt></td><td> initial offset in receive
* buffer </tr>
* <tr><td><tt> count </tt></td><td> number of items in input
* buffer </tr>
* <tr><td><tt> datatype </tt></td><td> data type of each item in input
* buffer </tr>
* <tr><td><tt> op </tt></td><td> reduce operation </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_SCAN</tt>.
*/
public void Scan(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int count,
Datatype datatype, Op op) throws MPIException {
if (op.isUser()){
if (Rank() == 0)
copyBuffer(sendbuf,sendoffset,count,datatype,
recvbuf,recvoffset,count,datatype);
else{
shadow.Recv(recvbuf, recvoffset, count, datatype, Rank() - 1, 0);
op.Call(sendbuf, sendoffset, recvbuf, recvoffset, count, datatype);
}
if (Rank() < Size() - 1)
shadow.Send(recvbuf, recvoffset, count, datatype, Rank() + 1, 0);
}
else
scan(sendbuf, sendoffset, recvbuf, recvoffset, count, datatype, op);
}
private native void scan(Object sendbuf, int sendoffset,
Object recvbuf, int recvoffset, int count,
Datatype datatype, Op op) ;
// Topology Constructors
/**
* Create a Cartesian topology communicator whose group is a subset
* of the group of this communicator.
* <p>
* <table>
* <tr><td><tt> dims </tt></td><td> the number of processes in each
* dimension </tr>
* <tr><td><tt> periods </tt></td><td> <tt>true</tt> if grid is periodic,
* <tt>false</tt> if not, in each
* dimension </tr>
* <tr><td><tt> reorder </tt></td><td> <tt>true</tt> if ranking may be
* reordered, <tt>false</tt> if not </tr>
* <tr><td><em> returns: </em></td><td> new Cartesian topology
* communicator </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_CART_CREATE</tt>.
* <p>
* The number of dimensions of the Cartesian grid is taken to be the size
* of the <tt>dims</tt> argument. The array <tt>periods</tt> must be the
* same size.
*/
public Cartcomm Create_cart(int [] dims, boolean [] periods,
boolean reorder) throws MPIException {
long cartHandle = GetCart(dims, periods, reorder) ;
if(cartHandle == nullHandle)
return null ;
else
return new Cartcomm(cartHandle) ;
}
private native long GetCart(int [] dims, boolean [] periods,
boolean reorder) ;
/**
* Create a graph topology communicator whose group is a subset
* of the group of this communicator.
* <p>
* <table>
* <tr><td><tt> index </tt></td><td> node degrees </tr>
* <tr><td><tt> edges </tt></td><td> graph edges </tr>
* <tr><td><tt> reorder </tt></td><td> <tt>true</tt> if ranking may be
* reordered, <tt>false</tt> if not </tr>
* <tr><td><em> returns: </em></td><td> new graph topology communicator </tr>
* </table>
* <p>
* Java binding of the MPI operation <tt>MPI_GRAPH_CREATE</tt>.
* <p>
* The number of nodes in the graph, <em>nnodes</em>, is taken
* to be size of the <tt>index</tt> argument. The size of array
* <tt>edges</tt> must be <tt>index [nnodes} - 1]</tt>.
*/
public Graphcomm Create_graph(int [] index, int [] edges, boolean reorder)
throws MPIException {
long graphHandle = GetGraph(index,edges,reorder) ;
if(graphHandle == nullHandle)
return null ;
else
return new Graphcomm(graphHandle) ;
}
private native long GetGraph(int [] index,int [] edges, boolean reorder);
private Comm shadow ; // Used by non-native collectives.
}
// Things to do
//