This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfompi_win_rma.c
3062 lines (2575 loc) · 109 KB
/
fompi_win_rma.c
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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2012 The Trustees of University of Illinois. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <assert.h>
#include <dmapp.h>
#include <stdlib.h>
#include <string.h>
#include "mpitypes.h"
#include "fompi.h"
/*signatures helper functions*/
static inline int foMPI_Rma_test_wait(void *extra_state, int *flag, MPI_Status *status, int wait);
static int simple_rma_wait(void *extra_state, MPI_Status *status);
static int simple_rma_test(void *extra_state, int *flag, MPI_Status *status);
#ifdef UGNI
static int communication_and_datatype_handling_ugni_put_notify_only(const void* origin_addr,
int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp,
int target_count, MPI_Datatype target_datatype, foMPI_Win win, dmapp_pe_t target_pe,
int tag);
static int communication_and_datatype_handling_ugni_get_notify_only(const void* origin_addr,
int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp,
int target_count, MPI_Datatype target_datatype, foMPI_Win win, dmapp_pe_t target_pe,
int tag);
//static inline int _foMPI_EncodeID(uint16_t rank, uint16_t id_msg, uint32_t *id_encoded);
static inline void ugni_simple_put(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag);
static inline void ugni_simple_get(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag);
static inline void ugni_simple_rma(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dest_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag, int operation);
static inline int _foMPI_Rrma_notify(const void *origin_addr, int origin_count,
MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count,
MPI_Datatype target_datatype, foMPI_Win win, foMPI_Request *request, int tag, int operation);
static inline int _foMPI_Rma_notify(const void *origin_addr, int origin_count,
MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count,
MPI_Datatype target_datatype, foMPI_Win win, int tag, int operation);
#endif
inline void sse_memcpy(char *to, const char *from, size_t len) {
unsigned long src = (unsigned long) from;
unsigned long dst = (unsigned long) to;
int i;
/* check alignment */
if ((src ^ dst) & 0xf)
goto unaligned;
if (src & 0xf) {
int chunk = 0x10 - (src & 0xf);
if (chunk > len) {
chunk = len; /* chunk can be more than the actual amount to copy */
}
/* copy chunk until next 16-byte */
memcpy(to, from, chunk);
len -= chunk;
to += chunk;
from += chunk;
}
/*
* copy in 256 Byte portions
*/
for (i = 0; i < (len & ~0xff); i += 256) {
asm volatile(
"movaps 0x0(%0), %%xmm0\n\t"
"movaps 0x10(%0), %%xmm1\n\t"
"movaps 0x20(%0), %%xmm2\n\t"
"movaps 0x30(%0), %%xmm3\n\t"
"movaps 0x40(%0), %%xmm4\n\t"
"movaps 0x50(%0), %%xmm5\n\t"
"movaps 0x60(%0), %%xmm6\n\t"
"movaps 0x70(%0), %%xmm7\n\t"
"movaps 0x80(%0), %%xmm8\n\t"
"movaps 0x90(%0), %%xmm9\n\t"
"movaps 0xa0(%0), %%xmm10\n\t"
"movaps 0xb0(%0), %%xmm11\n\t"
"movaps 0xc0(%0), %%xmm12\n\t"
"movaps 0xd0(%0), %%xmm13\n\t"
"movaps 0xe0(%0), %%xmm14\n\t"
"movaps 0xf0(%0), %%xmm15\n\t"
"movaps %%xmm0, 0x0(%1)\n\t"
"movaps %%xmm1, 0x10(%1)\n\t"
"movaps %%xmm2, 0x20(%1)\n\t"
"movaps %%xmm3, 0x30(%1)\n\t"
"movaps %%xmm4, 0x40(%1)\n\t"
"movaps %%xmm5, 0x50(%1)\n\t"
"movaps %%xmm6, 0x60(%1)\n\t"
"movaps %%xmm7, 0x70(%1)\n\t"
"movaps %%xmm8, 0x80(%1)\n\t"
"movaps %%xmm9, 0x90(%1)\n\t"
"movaps %%xmm10, 0xa0(%1)\n\t"
"movaps %%xmm11, 0xb0(%1)\n\t"
"movaps %%xmm12, 0xc0(%1)\n\t"
"movaps %%xmm13, 0xd0(%1)\n\t"
"movaps %%xmm14, 0xe0(%1)\n\t"
"movaps %%xmm15, 0xf0(%1)\n\t"
: : "r" (from), "r" (to) : "memory");
from += 256;
to += 256;
}
goto trailer;
unaligned:
/*
* copy in 256 Byte portions unaligned
*/
for (i = 0; i < (len & ~0xff); i += 256) {
asm volatile(
"movups 0x0(%0), %%xmm0\n\t"
"movups 0x10(%0), %%xmm1\n\t"
"movups 0x20(%0), %%xmm2\n\t"
"movups 0x30(%0), %%xmm3\n\t"
"movups 0x40(%0), %%xmm4\n\t"
"movups 0x50(%0), %%xmm5\n\t"
"movups 0x60(%0), %%xmm6\n\t"
"movups 0x70(%0), %%xmm7\n\t"
"movups 0x80(%0), %%xmm8\n\t"
"movups 0x90(%0), %%xmm9\n\t"
"movups 0xa0(%0), %%xmm10\n\t"
"movups 0xb0(%0), %%xmm11\n\t"
"movups 0xc0(%0), %%xmm12\n\t"
"movups 0xd0(%0), %%xmm13\n\t"
"movups 0xe0(%0), %%xmm14\n\t"
"movups 0xf0(%0), %%xmm15\n\t"
"movups %%xmm0, 0x0(%1)\n\t"
"movups %%xmm1, 0x10(%1)\n\t"
"movups %%xmm2, 0x20(%1)\n\t"
"movups %%xmm3, 0x30(%1)\n\t"
"movups %%xmm4, 0x40(%1)\n\t"
"movups %%xmm5, 0x50(%1)\n\t"
"movups %%xmm6, 0x60(%1)\n\t"
"movups %%xmm7, 0x70(%1)\n\t"
"movups %%xmm8, 0x80(%1)\n\t"
"movups %%xmm9, 0x90(%1)\n\t"
"movups %%xmm10, 0xa0(%1)\n\t"
"movups %%xmm11, 0xb0(%1)\n\t"
"movups %%xmm12, 0xc0(%1)\n\t"
"movups %%xmm13, 0xd0(%1)\n\t"
"movups %%xmm14, 0xe0(%1)\n\t"
"movups %%xmm15, 0xf0(%1)\n\t"
: : "r" (from), "r" (to) : "memory");
from += 256;
to += 256;
}
trailer:
memcpy(to, from, len & 0xff);
}
/* some global variables */
/* some helper functions */
static int find_seg_and_size(foMPI_Win_dynamic_element_t* current, MPI_Aint size,
MPI_Aint target_offset, fompi_seg_desc_t** seg_ptr, uint64_t* real_size) {
int found = 0;
if (current != NULL) {
if ((target_offset >= current->base) && (target_offset < (current->base + current->size))) {
found = 1;
}
while ((current->next != NULL) && (found == 0)) {
current = current->next;
if ((target_offset >= current->base)
&& (target_offset < (current->base + current->size))) {
found = 1;
}
}
}
if (found == 0) {
return foMPI_ERROR_RMA_WIN_MEM_NOT_FOUND;
}
*seg_ptr = &(current->seg);
if ((target_offset + size) > (current->base + current->size)) {
*real_size = current->base + current->size - target_offset;
} else {
*real_size = size;
}
return MPI_SUCCESS;
}
static void get_dynamic_window_regions(dmapp_return_t* status, int target_rank,
dmapp_pe_t target_pe, foMPI_Win win) {
int64_t mutex;
uint32_t remote_dyn_id;
foMPI_Win_dynamic_element_t* current;
foMPI_Win_dynamic_element_t* temp;
int times;
foMPI_Win_ptr_seg_comb_t remote_list_head;
/* get the mutex */
do {
/* TODO: busy waiting */
*status = dmapp_acswap_qw(&mutex,
(void*) &(win->dynamic_list[target_rank].win_ptr->dynamic_mutex),
&(win->dynamic_list[target_rank].win_ptr_seg.dmapp), target_pe,
(int64_t) foMPI_MUTEX_NONE, (int64_t) win->commrank);
_check_dmapp_status(*status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
} while (mutex != foMPI_MUTEX_NONE);
/* get the current remote id */
*status = dmapp_get(&remote_dyn_id,
(void*) &(win->dynamic_list[target_rank].win_ptr->dynamic_id),
&(win->dynamic_list[target_rank].win_ptr_seg.dmapp), target_pe, 1, DMAPP_QW);
_check_dmapp_status(*status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
if (remote_dyn_id != win->dynamic_list[target_rank].dynamic_id) {
win->dynamic_list[target_rank].dynamic_id = remote_dyn_id;
/* delete the current list */
if (win->dynamic_list[target_rank].remote_mem_regions != NULL) {
current = win->dynamic_list[target_rank].remote_mem_regions;
while (current->next != NULL) {
temp = current;
current = current->next;
_foMPI_FREE(temp);
}
_foMPI_FREE(current);
win->dynamic_list[target_rank].remote_mem_regions = NULL;
}
assert(win->dynamic_list[target_rank].remote_mem_regions == NULL);
times = sizeof(foMPI_Win_ptr_seg_comb_t) / 8; /* TODO: what if the size is not exactly divisible by eight */
/* get new list */
/* get the pointer to the list */
*status = dmapp_get(&remote_list_head,
&(win->dynamic_list[target_rank].win_ptr->win_dynamic_mem_regions_seg.dmapp),
&(win->dynamic_list[target_rank].win_ptr_seg.dmapp), target_pe, times, DMAPP_QW);
_check_dmapp_status(*status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
if (remote_list_head.ptr != NULL) {
/* get the first element */
temp = _foMPI_ALLOC(sizeof(foMPI_Win_dynamic_element_t));
times = sizeof(foMPI_Win_dynamic_element_t) / 8; /* TODO: what if the size is not exactly divisible by eight */
*status = dmapp_get(temp, remote_list_head.ptr, &remote_list_head.seg.dmapp, target_pe,
times, DMAPP_QW);
_check_dmapp_status(*status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
win->dynamic_list[target_rank].remote_mem_regions = temp;
current = temp;
while (current->next != NULL) { /* get remaining elements */
temp = _foMPI_ALLOC(sizeof(foMPI_Win_dynamic_element_t));
*status = dmapp_get(temp, (void*) current->next, &(current->next_seg.dmapp),
target_pe, times, DMAPP_QW);
_check_dmapp_status(*status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
current->next = temp;
current = current->next;
}
} /* no else needed since win->dynamic_list[target_rank].remote_mem_regions is already NULL */
}
/* release the mutex */
/* TODO: nonblocking ? */
/* we have to do this with an atomic operation, with a simple put it was deadlocking some times */
*status = dmapp_acswap_qw(&mutex,
(void*) &(win->dynamic_list[target_rank].win_ptr->dynamic_mutex),
&(win->dynamic_list[target_rank].win_ptr_seg.dmapp), target_pe, (int64_t) win->commrank,
(int64_t) foMPI_MUTEX_NONE);
_check_dmapp_status(*status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
}
/* pointer to the last two entries */
static int dcache_init_blocks(MPI_Datatype dtype, int count, dcache_blocks_t* blocks) {
int number_blocks;
MPI_Aint lb;
MPI_Aint extent;
MPI_Aint true_extent;
MPI_Aint count_extent;
MPIT_Type_init(dtype);
MPI_Type_get_extent(dtype, &lb, &extent);
MPI_Type_get_true_extent(dtype, &lb, &true_extent);
count_extent = (count - 1) * extent + true_extent;
MPIT_Type_blockct(count, dtype, 0, count_extent, &(blocks->number_blocks));
blocks->displ = _foMPI_ALLOC(blocks->number_blocks * sizeof(MPI_Aint));
blocks->blocklen = _foMPI_ALLOC(blocks->number_blocks * sizeof(int));
/* get offsets/blocklengths of the origin and the target datatypes */
number_blocks = blocks->number_blocks;
/* the resulting offset will be relative, this assumes that MPI_Aint can handle negative offsets */
MPIT_Type_flatten(0, count, dtype, 0, count_extent, &(blocks->displ[0]), &(blocks->blocklen[0]),
&number_blocks);
blocks->type = dtype;
blocks->type_count = count;
blocks->pos = 0;
blocks->block_remaining_size = 0;
return MPI_SUCCESS;
}
/* the names target_* and origin_* arbitrarily chosen, the algorithm doesn't rely on these "position" information */
static int dcache_get_next_block(MPI_Datatype origin_dtype, int origin_count,
MPI_Aint* origin_offset, MPI_Datatype target_dtype, int target_count,
MPI_Aint* target_offset, uint64_t* size, int* last_block) {
int i;
int origin_entry;
int target_entry;
/* search for the first datatype in the cache */
i = glob_info.dcache_origin_last_entry;
origin_entry = -1;
do {
if ((glob_info.dcache_blocks[i].type == origin_dtype)
&& (glob_info.dcache_blocks[i].type_count == origin_count)) {
origin_entry = i;
glob_info.dcache_origin_last_entry = i;
}
i = (i + 1) % 10;
} while ((i != glob_info.dcache_origin_last_entry) && (origin_entry == -1));
if (origin_entry == -1) {
origin_entry = glob_info.dcache_last_entry;
glob_info.dcache_last_entry = (glob_info.dcache_last_entry + 1) % 10;
/* clean up if that cache element was already used */
if (glob_info.dcache_blocks[origin_entry].type != MPI_DATATYPE_NULL) {
_foMPI_FREE(glob_info.dcache_blocks[origin_entry].displ);
_foMPI_FREE(glob_info.dcache_blocks[origin_entry].blocklen);
}
dcache_init_blocks(origin_dtype, origin_count, &glob_info.dcache_blocks[origin_entry]);
}
/* search for the second datatype in the cache */
i = glob_info.dcache_target_last_entry;
target_entry = -1;
do {
if ((glob_info.dcache_blocks[i].type == target_dtype)
&& (glob_info.dcache_blocks[i].type_count == target_count)) {
target_entry = i;
glob_info.dcache_target_last_entry = i;
}
i = (i + 1) % 10;
} while ((i != glob_info.dcache_target_last_entry) && (target_entry == -1));
if (target_entry == -1) {
if (origin_entry == glob_info.dcache_last_entry) {
target_entry = (glob_info.dcache_last_entry + 1) % 10;
glob_info.dcache_last_entry = (glob_info.dcache_last_entry + 2) % 10;
} else {
target_entry = glob_info.dcache_last_entry;
glob_info.dcache_last_entry = (glob_info.dcache_last_entry + 1) % 10;
}
/* clean up if that cache element was already used */
if (glob_info.dcache_blocks[target_entry].type != MPI_DATATYPE_NULL) {
_foMPI_FREE(glob_info.dcache_blocks[target_entry].displ);
_foMPI_FREE(glob_info.dcache_blocks[target_entry].blocklen);
}
dcache_init_blocks(target_dtype, target_count, &glob_info.dcache_blocks[target_entry]);
}
/* find the next block */
/* begin a new block of the origin datatype */
if (glob_info.dcache_blocks[origin_entry].block_remaining_size == 0) {
i = glob_info.dcache_blocks[origin_entry].pos++;
glob_info.dcache_blocks[origin_entry].block_remaining_size =
glob_info.dcache_blocks[origin_entry].blocklen[i];
glob_info.dcache_blocks[origin_entry].block_offset =
glob_info.dcache_blocks[origin_entry].displ[i];
}
/* begin a new block of the target datatype */
if (glob_info.dcache_blocks[target_entry].block_remaining_size == 0) {
i = glob_info.dcache_blocks[target_entry].pos++;
glob_info.dcache_blocks[target_entry].block_remaining_size =
glob_info.dcache_blocks[target_entry].blocklen[i];
glob_info.dcache_blocks[target_entry].block_offset =
glob_info.dcache_blocks[target_entry].displ[i];
}
if (glob_info.dcache_blocks[origin_entry].block_remaining_size
< glob_info.dcache_blocks[target_entry].block_remaining_size) {
*size = glob_info.dcache_blocks[origin_entry].block_remaining_size;
} else {
*size = glob_info.dcache_blocks[target_entry].block_remaining_size;
}
*origin_offset = glob_info.dcache_blocks[origin_entry].block_offset;
*target_offset = glob_info.dcache_blocks[target_entry].block_offset;
/* set the remainder
* it is done with arithmetic operations instead of if statements
* one of remainder will always be zero */
/* the if statement handles the case when the two datatypes are the same */
if (origin_entry != target_entry) {
glob_info.dcache_blocks[origin_entry].block_remaining_size -= *size;
glob_info.dcache_blocks[target_entry].block_remaining_size -= *size;
glob_info.dcache_blocks[origin_entry].block_offset += *size;
glob_info.dcache_blocks[target_entry].block_offset += *size;
} else {
glob_info.dcache_blocks[origin_entry].block_remaining_size = 0;
}
if ((glob_info.dcache_blocks[origin_entry].pos
== glob_info.dcache_blocks[origin_entry].number_blocks)
&& (glob_info.dcache_blocks[target_entry].pos
== glob_info.dcache_blocks[target_entry].number_blocks)) {
*last_block = 1;
glob_info.dcache_blocks[origin_entry].pos = 0;
glob_info.dcache_blocks[target_entry].pos = 0;
glob_info.dcache_blocks[origin_entry].block_remaining_size = 0;
glob_info.dcache_blocks[target_entry].block_remaining_size = 0;
} else {
*last_block = 0;
}
return MPI_SUCCESS;
}
/* TODO: handle of MPI_COMBINER_F90_REAL, MPI_COMBINER_F90_COMPLEX, MPI_COMBINER_F90_INTEGER */
static int check_basic_type(MPI_Datatype type, int* flag, MPI_Datatype* basic_type) {
dtype_list_t* datatype_list;
dtype_list_t* current;
int num_integers;
int num_addresses;
int num_datatypes;
int combiner;
int init = 0;
MPI_Datatype* array_datatypes;
int max_alloc = 1;
int i;
int* array_int;
MPI_Aint* array_addresses;
*flag = 1;
datatype_list = _foMPI_ALLOC(sizeof(dtype_list_t));
datatype_list->next = NULL;
datatype_list->type = type;
array_datatypes = _foMPI_ALLOC(sizeof(MPI_Datatype));
array_int = _foMPI_ALLOC(sizeof(MPI_Datatype));
array_addresses = _foMPI_ALLOC(sizeof(MPI_Aint));
while (datatype_list != NULL) {
MPI_Type_get_envelope(datatype_list->type, &num_integers, &num_addresses, &num_datatypes,
&combiner);
if (combiner == MPI_COMBINER_NAMED) {
if (init == 0) {
init = 1;
*basic_type = datatype_list->type;
} else {
if (*basic_type != datatype_list->type) {
/* not the same basic datatypes */
*flag = 0;
/* clean up */
while (datatype_list != NULL) {
current = datatype_list;
datatype_list = datatype_list->next;
_foMPI_FREE(current);
}
break;
} else {
current = datatype_list;
datatype_list = datatype_list->next;
_foMPI_FREE(current);
}
}
} else {
assert(
(combiner != MPI_COMBINER_F90_REAL) || (combiner != MPI_COMBINER_F90_COMPLEX)
|| (combiner != MPI_COMBINER_F90_INTEGER));
if (num_integers > max_alloc) {
array_int = realloc(array_int, num_integers * sizeof(int));
array_addresses = realloc(array_addresses, num_integers * sizeof(MPI_Aint));
array_datatypes = realloc(array_datatypes, num_integers * sizeof(MPI_Datatype));
max_alloc = num_integers;
}
MPI_Type_get_contents(datatype_list->type, num_integers, num_addresses, num_datatypes,
&array_int[0], &array_addresses[0], &array_datatypes[0]);
/* free the datatype and remove it from the queue */
if (datatype_list->type != type) {
MPI_Type_free(&(datatype_list->type));
}
if (num_datatypes == 1) {
datatype_list->type = array_datatypes[0];
} else {
/* only with a struct there is more than one sub datatypes */
current = datatype_list;
datatype_list = datatype_list->next;
_foMPI_FREE(current);
for (i = 0; i < num_datatypes; i++) {
current = _foMPI_ALLOC(sizeof(dtype_list_t));
current->next = datatype_list;
current->type = array_datatypes[i];
datatype_list = current;
}
}
}
}
_foMPI_FREE(array_datatypes);
_foMPI_FREE(array_int);
_foMPI_FREE(array_addresses);
return MPI_SUCCESS;
}
static void accumulate_bor_8byte(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag) {
dmapp_return_t status;
int nelements;
int i;
char* origin_addr = (char*) origin_offset;
char* target_addr = (char*) target_offset;
nelements = size / 8;
for (i = 0; i < nelements; i++) {
status = dmapp_aor_qw_nbi(target_addr + i * 8, &(dst_seg_ptr->dmapp), target_pe,
*(int64_t*) (origin_addr + i * 8));
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
}
win->nbi_counter++; /* little hack, since we actually just need a flag to indicate that there are nbi operations in progress */
}
static void accumulate_band_8byte(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag) {
dmapp_return_t status;
int nelements;
int i;
char* origin_addr = (char*) origin_offset;
char* target_addr = (char*) target_offset;
nelements = size / 8;
for (i = 0; i < nelements; i++) {
status = dmapp_aand_qw_nbi(target_addr + i * 8, &(dst_seg_ptr->dmapp), target_pe,
*(int64_t*) (origin_addr + i * 8));
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
}
win->nbi_counter++; /* little hack, since we actually just need a flag to indicate that there are nbi operations in progress */
}
static void accumulate_bxor_8byte(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag) {
dmapp_return_t status;
int nelements;
int i;
char* origin_addr = (char*) origin_offset;
char* target_addr = (char*) target_offset;
nelements = size / 8;
for (i = 0; i < nelements; i++) {
status = dmapp_axor_qw_nbi(target_addr + i * 8, &(dst_seg_ptr->dmapp), target_pe,
*(int64_t*) (origin_addr + i * 8));
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
}
win->nbi_counter++; /* little hack, since we actually just need a flag to indicate that there are nbi operations in progress */
}
static void accumulate_sum_8byte(dmapp_pe_t target_pe, MPI_Aint target_offset,
MPI_Aint origin_offset, fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr,
MPI_Aint size, foMPI_Win win, int tag) {
dmapp_return_t status;
int nelements;
int i;
char* origin_addr = (char*) origin_offset;
char* target_addr = (char*) target_offset;
nelements = size / 8;
for (i = 0; i < nelements; i++) {
status = dmapp_aadd_qw_nbi(target_addr + i * 8, &(dst_seg_ptr->dmapp), target_pe,
*(int64_t*) (origin_addr + i * 8));
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
}
win->nbi_counter++; /* little hack, since we actually just need a flag to indicate that there are nbi operations in progress */
}
static void dmapp_simple_put(dmapp_pe_t target_pe, MPI_Aint target_offset, MPI_Aint origin_offset,
fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr, MPI_Aint size, foMPI_Win win,
int tag) {
dmapp_return_t status;
uint64_t nelements;
uint64_t nelements_modulo;
int offset_modulo;
char* origin_addr = (char*) origin_offset;
char* target_addr = (char*) target_offset;
nelements = size / 16;
offset_modulo = nelements * 16;
nelements_modulo = size - offset_modulo;
#ifndef NDEBUG
int check = _foMPI_is_addr_in_seg((void *) target_addr, dst_seg_ptr)
&& _foMPI_is_addr_in_seg((void *) (target_addr + size), dst_seg_ptr);
_foMPI_TRACE_LOG(2, "dmapp_put CHECK REMOTE BOUNDS -> %s \n", check ? "OK" : "ERROR");
#endif
/* just use *_nbi since it's easier and maybe even faster */
/* the problem is that we synchronize too much */
#ifdef PAPI
timing_record( 1 );
#endif
if (nelements != 0) {
status = dmapp_put_nbi(target_addr, &(dst_seg_ptr->dmapp), target_pe, origin_addr,
nelements, DMAPP_DQW);
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
_foMPI_TRACE_LOG(2,
"dmapp_put local mem: [0x%lx , 0x%lx] remote mem: [0x%lx , 0x%lx] data length: %4i\n",
origin_addr, origin_addr + size, target_addr, target_addr + size, (int ) size);
_foMPI_TRACE_LOG(2, "dmapp_put targetPE: %d tag: %d successful\n", target_pe, tag);
win->nbi_counter++;
}
if (nelements_modulo != 0) {
status = dmapp_put_nbi(target_addr + offset_modulo, &(dst_seg_ptr->dmapp), target_pe,
origin_addr + offset_modulo, nelements_modulo, DMAPP_BYTE);
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
_foMPI_TRACE_LOG(2,
"dmapp_put local mem: [0x%lx , 0x%lx] remote mem: [0x%lx , 0x%lx] data length: %4i\n",
origin_addr, origin_addr + size, target_addr, target_addr + size, (int ) size);
_foMPI_TRACE_LOG(2, "dmapp_put targetPE: %d tag: %d successful\n", target_pe, tag);
win->nbi_counter++;
}
#ifdef PAPI
timing_record( 2 );
#endif
}
#ifdef XPMEM
static void xpmem_simple_put(dmapp_pe_t target_pe, MPI_Aint target_offset, MPI_Aint origin_offset,
fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr, MPI_Aint size, foMPI_Win win,
int tag) {
#ifdef PAPI
timing_record( 1 );
#endif
if (size > 524288) {
memcpy((char* ) target_offset, (char* ) origin_offset, size);
} else {
sse_memcpy((char*) target_offset, (char*) origin_offset, size);
}
#ifdef PAPI
timing_record( 2 );
#endif
}
#endif
static void dmapp_simple_get(dmapp_pe_t target_pe, MPI_Aint target_offset, MPI_Aint origin_offset,
fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr, MPI_Aint size, foMPI_Win win,
int tag) {
dmapp_return_t status;
uint64_t nelements;
uint64_t nelements_modulo;
int offset_modulo;
char* origin_addr = (char*) origin_offset;
char* target_addr = (char*) target_offset;
nelements = size / 16;
offset_modulo = nelements * 16;
nelements_modulo = size - offset_modulo;
/* just use *_nbi since it's easier and maybe even faster */
/* the problem is that we synchronize too much */
#ifdef PAPI
timing_record( 5 );
#endif
if (nelements != 0) {
status = dmapp_get_nbi(origin_addr, target_addr, &(dst_seg_ptr->dmapp), target_pe,
nelements, DMAPP_DQW);
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
win->nbi_counter++;
}
if (nelements_modulo != 0) {
status = dmapp_get_nbi(origin_addr + offset_modulo, target_addr + offset_modulo,
&(dst_seg_ptr->dmapp), target_pe, nelements_modulo, DMAPP_BYTE);
_check_dmapp_status(status, DMAPP_RC_SUCCESS, (char*) __FILE__, __LINE__);
win->nbi_counter++;
}
#ifdef PAPI
timing_record( 6 );
#endif
}
#ifdef XPMEM
static void xpmem_simple_get(dmapp_pe_t target_pe, MPI_Aint target_offset, MPI_Aint origin_offset,
fompi_seg_desc_t* src_seg_ptr, fompi_seg_desc_t* dst_seg_ptr, MPI_Aint size, foMPI_Win win,
int tag) {
#ifdef PAPI
timing_record( 5 );
#endif
if (size > 524288) {
memcpy((char* ) origin_offset, (char* ) target_offset, size);
} else {
sse_memcpy((char*) origin_offset, (char*) target_offset, size);
}
#ifdef PAPI
timing_record( 6 );
#endif
}
#endif
static int communication_and_datatype_handling(const void* origin_addr, int origin_count,
MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count,
MPI_Datatype target_datatype, foMPI_Win win, dmapp_pe_t target_pe,
void (*commfunc)(dmapp_pe_t, MPI_Aint, MPI_Aint, fompi_seg_desc_t*, fompi_seg_desc_t*,
MPI_Aint, foMPI_Win, int), int tag) {
dmapp_return_t status;
fompi_seg_desc_t *dst_seg_ptr;
fompi_seg_desc_t *src_seg_ptr = NULL;
foMPI_Win_dynamic_element_t *dst_current;
int origin_type_size, target_type_size;
MPI_Aint lb;
MPI_Aint target_extent;
MPI_Aint target_true_extent;
MPI_Aint target_count_extent;
uint64_t transport_size;
uint64_t remaining_size;
MPI_Aint target_block_offset;
MPI_Aint origin_block_offset;
int last_block;
#ifndef NDEBUG
int res;
#endif
MPI_Aint origin_offset = (MPI_Aint) origin_addr;
MPI_Aint target_offset;
/* determine the target_addr and some other create-flavor dependent parameter */
if (win->create_flavor == foMPI_WIN_FLAVOR_DYNAMIC) {
/* checks if the local information about the remote dynamic window are up-to-date: if not, they are fetched */
get_dynamic_window_regions(&status, target_rank, target_pe, win);
target_offset = (MPI_Aint) MPI_BOTTOM + target_disp;
} else {
#ifdef XPMEM
int local_rank = foMPI_onnode_rank_global_to_local(target_rank, win);
if (local_rank != -1) {
target_offset = (MPI_Aint) win->xpmem_array[local_rank].base
+ target_disp * win->win_array[target_rank].disp_unit;
} else {
target_offset = (MPI_Aint) win->win_array[target_rank].base
+ target_disp * win->win_array[target_rank].disp_unit;
}
#else
target_offset = (MPI_Aint) win->win_array[target_rank].base
+ target_disp * win->win_array[target_rank].disp_unit;
#endif
/* TODO: other intrinsic datatypes */
if ((origin_datatype == target_datatype)
&& ((origin_datatype == MPI_CHAR) || (origin_datatype == MPI_UINT64_T)
|| (origin_datatype == MPI_DOUBLE) || (origin_datatype == MPI_INT)
|| (origin_datatype == MPI_BYTE))) {
/* fast path for intrinsic datatypes */
MPI_Type_size(origin_datatype, &origin_type_size);
dst_seg_ptr = &(win->win_array[target_rank].seg);
(*commfunc)(target_pe, target_offset, origin_offset, src_seg_ptr, dst_seg_ptr,
origin_count * origin_type_size, win, tag);
return MPI_SUCCESS;
}
}
/* process the datatypes */
MPI_Type_size(origin_datatype, &origin_type_size);
MPI_Type_size(target_datatype, &target_type_size);
/* TODO: should this return a error? */
assert((origin_type_size > 0) && (target_type_size > 0));
assert((origin_type_size * origin_count) == (target_type_size * target_count));
/* TODO: real test that the datatypes are identical */
MPI_Type_get_extent(target_datatype, &lb, &target_extent);
MPI_Type_get_true_extent(target_datatype, &lb, &target_true_extent);
target_count_extent = (target_count - 1) * target_extent + target_true_extent;
if (win->create_flavor == foMPI_WIN_FLAVOR_DYNAMIC) {
/* already checks if the requested memory region is within the boundaries */
/* check if datatype work in one memory region */
dst_current = win->dynamic_list[target_rank].remote_mem_regions;
dst_seg_ptr = NULL;
if (dst_current != NULL) {
if ((target_offset >= dst_current->base)
&& ((target_offset + target_count_extent)
<= (dst_current->base + dst_current->size))) {
dst_seg_ptr = &(dst_current->seg);
}
while (dst_current->next != NULL) {
dst_current = dst_current->next;
if ((target_offset >= dst_current->base)
&& ((target_offset + target_count_extent)
<= (dst_current->base + dst_current->size))) {
dst_seg_ptr = &(dst_current->seg);
}
}
}
} else {
dst_seg_ptr = &(win->win_array[target_rank].seg);
}
if (dst_seg_ptr != NULL) {
/* only one memory region */
do {
dcache_get_next_block(origin_datatype, origin_count, &origin_block_offset,
target_datatype, target_count, &target_block_offset, &transport_size,
&last_block);
(*commfunc)(target_pe, target_offset + target_block_offset,
origin_offset + origin_block_offset, src_seg_ptr, dst_seg_ptr, transport_size,
win, foMPI_ANY_TAG);
} while (last_block == 0);
} else {
/* more than one memory region */
do {
dcache_get_next_block(origin_datatype, origin_count, &origin_block_offset,
target_datatype, target_count, &target_block_offset, &remaining_size,
&last_block);
/* TODO: maybe we can save the last state and check if it is still true */
/* check local list for entry */
while (remaining_size > 0) {
#ifdef NDEBUG
find_seg_and_size( win->dynamic_list[target_rank].remote_mem_regions, remaining_size, target_offset+target_block_offset, &dst_seg_ptr, &transport_size );
#else
res = find_seg_and_size(win->dynamic_list[target_rank].remote_mem_regions,
remaining_size, target_offset + target_block_offset, &dst_seg_ptr,
&transport_size);
assert(res == MPI_SUCCESS); /* TODO: return a real error code? */
#endif
(*commfunc)(target_pe, target_offset + target_block_offset,
origin_offset + origin_block_offset, src_seg_ptr, dst_seg_ptr,
transport_size, win, foMPI_ANY_TAG);
target_block_offset += transport_size;
origin_block_offset += transport_size;
remaining_size -= transport_size;
}
} while (last_block == 0);
}
return MPI_SUCCESS;
}
#ifdef UGNI
static int communication_and_datatype_handling_ugni_put_notify_only(const void* origin_addr,
int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp,
int target_count, MPI_Datatype target_datatype, foMPI_Win win, dmapp_pe_t target_pe,
int tag) {
dmapp_return_t status;
fompi_seg_desc_t *dst_seg_ptr;
foMPI_Win_dynamic_element_t *dst_current;
fompi_seg_desc_t *src_seg_ptr = NULL;
foMPI_Win_dynamic_element_t *src_current;
int origin_type_size, target_type_size;
MPI_Aint lb;
MPI_Aint target_extent;
MPI_Aint target_true_extent;
MPI_Aint target_count_extent;
/*needed for finding the source segment*/
MPI_Aint lc;
MPI_Aint origin_extent;
MPI_Aint origin_true_extent;
MPI_Aint origin_count_extent;
uint64_t transport_size;
uint64_t remaining_size;
MPI_Aint target_block_offset;
MPI_Aint origin_block_offset;
int last_block;
int count_blocks = 0;
#ifndef NDEBUG
int res;
#endif
MPI_Aint origin_offset = (MPI_Aint) origin_addr;
MPI_Aint target_offset;
/* determine the target_addr and some other create-flavor dependent parameter */
if (win->create_flavor == foMPI_WIN_FLAVOR_DYNAMIC) {
/* checks if the local information about the remote dynamic window are up-to-date: if not, they are fetched */
get_dynamic_window_regions(&status, target_rank, target_pe, win);
target_offset = (MPI_Aint) MPI_BOTTOM + target_disp;
} else {
#ifdef XPMEM
int local_rank = foMPI_onnode_rank_global_to_local(target_rank, win);
if (local_rank != -1) {
target_offset = (MPI_Aint) win->xpmem_array[local_rank].base
+ target_disp * win->win_array[target_rank].disp_unit;
} else {
target_offset = (MPI_Aint) win->win_array[target_rank].base
+ target_disp * win->win_array[target_rank].disp_unit;
}
#else
target_offset = (MPI_Aint) win->win_array[target_rank].base
+ target_disp * win->win_array[target_rank].disp_unit;
#endif
/* TODO: other intrinsic datatypes */
if ((origin_datatype == target_datatype)
&& ((origin_datatype == MPI_CHAR) || (origin_datatype == MPI_UINT64_T)
|| (origin_datatype == MPI_DOUBLE) || (origin_datatype == MPI_INT)
|| (origin_datatype == MPI_BYTE))) {
/* fast path for intrinsic datatypes */
_foMPI_TRACE_LOG(1, " Communication_hdl_ugni_put -> fast path\n");
MPI_Type_size(origin_datatype, &origin_type_size);
dst_seg_ptr = &(win->win_array[target_rank].seg);
/*in order to use the uGNI API we need also the handle of the source memory segment*/
if (_foMPI_is_addr_in_seg((void *) origin_offset,
&(win->win_array[win->commrank].seg))== _foMPI_TRUE) {
src_seg_ptr = &(win->win_array[win->commrank].seg);
}
if (origin_count * origin_type_size < _foMPI_MAX_RDMA_TRANFER_LENGHT) {
ugni_simple_put(target_pe, target_offset, origin_offset, src_seg_ptr, dst_seg_ptr,
origin_count * origin_type_size, win, tag);
} else {
dmapp_simple_put(target_pe, target_offset, origin_offset, src_seg_ptr, dst_seg_ptr,
origin_count * origin_type_size, win, MPI_ANY_TAG);
foMPI_Win_flush_all(win);
ugni_simple_put(target_pe, target_offset, origin_offset, src_seg_ptr, dst_seg_ptr,
0, win, tag);
}