@@ -28,6 +28,33 @@ static ADIOI_Flatlist_node *flatlist_node_new(MPI_Datatype datatype, MPI_Count c
28
28
return flat ;
29
29
}
30
30
31
+ /*
32
+ * I don't really expect this to ever trigger, but without the below safety
33
+ * valve, the design relies on the Count function coming out >= whatever
34
+ * the Flatten function comes up with. There are enough differences between
35
+ * the two that it's hard to be positive this will always be true. So every
36
+ * time something's added to flat's arrays, let's make sure they're big enough
37
+ * and re-alloc if not.
38
+ */
39
+ static void flatlist_node_grow (ADIOI_Flatlist_node * flat , int idx )
40
+ {
41
+ if (idx >= flat -> count ) {
42
+ ADIO_Offset * new_blocklens ;
43
+ ADIO_Offset * new_indices ;
44
+ int new_count = (flat -> count * 1.25 + 4 );
45
+ new_blocklens = (ADIO_Offset * ) ADIOI_Calloc (new_count * 2 , sizeof (ADIO_Offset ));
46
+ new_indices = new_blocklens + new_count ;
47
+ if (flat -> count ) {
48
+ memcpy (new_blocklens , flat -> blocklens , flat -> count * sizeof (ADIO_Offset ));
49
+ memcpy (new_indices , flat -> indices , flat -> count * sizeof (ADIO_Offset ));
50
+ ADIOI_Free (flat -> blocklens );
51
+ }
52
+ flat -> blocklens = new_blocklens ;
53
+ flat -> indices = new_indices ;
54
+ flat -> count = new_count ;
55
+ }
56
+ }
57
+
31
58
void ADIOI_Optimize_flattened (ADIOI_Flatlist_node * flat_type );
32
59
/* flatten datatype and add it to Flatlist */
33
60
ADIOI_Flatlist_node * ADIOI_Flatten_datatype (MPI_Datatype datatype )
@@ -83,6 +110,16 @@ ADIOI_Flatlist_node *ADIOI_Flatten_datatype(MPI_Datatype datatype)
83
110
DBG_FPRINTF (stderr , "ADIOI_Flatten_datatype:: ADIOI_Flatten\n" );
84
111
#endif
85
112
113
+ /*
114
+ * Setting flat->count to curr_index, since curr_index is the most fundamentally
115
+ * correct updated value that represents what's in the indices/blocklens arrays.
116
+ * It would be nice if the counter function and the flatten function were in sync,
117
+ * but the numerous cases that decrement flat->count in the flatten function show
118
+ * that syncing them is a hack, and as long as the counter doesn't under-count
119
+ * it's good enough.
120
+ */
121
+ flat -> count = curr_index ;
122
+
86
123
ADIOI_Optimize_flattened (flat );
87
124
/* debug */
88
125
#ifdef FLATTEN_DEBUG
@@ -228,6 +265,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
228
265
if (prev_index == * curr_index ) {
229
266
/* simplest case, made up of basic or contiguous types */
230
267
j = * curr_index ;
268
+ flatlist_node_grow (flat , j );
231
269
flat -> indices [j ] = st_offset ;
232
270
MPI_Type_size_x (types [0 ], & old_size );
233
271
flat -> blocklens [j ] = top_count * old_size ;
@@ -279,10 +317,12 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
279
317
* avoid >2G integer arithmetic problems */
280
318
ADIO_Offset blocklength = ints [1 ], stride = ints [2 ];
281
319
j = * curr_index ;
320
+ flatlist_node_grow (flat , j );
282
321
flat -> indices [j ] = st_offset ;
283
322
MPI_Type_size_x (types [0 ], & old_size );
284
323
flat -> blocklens [j ] = blocklength * old_size ;
285
324
for (i = j + 1 ; i < j + top_count ; i ++ ) {
325
+ flatlist_node_grow (flat , i );
286
326
flat -> indices [i ] = flat -> indices [i - 1 ] + stride * old_size ;
287
327
flat -> blocklens [i ] = flat -> blocklens [j ];
288
328
}
@@ -342,10 +382,12 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
342
382
* avoid >2G integer arithmetic problems */
343
383
ADIO_Offset blocklength = ints [1 ];
344
384
j = * curr_index ;
385
+ flatlist_node_grow (flat , j );
345
386
flat -> indices [j ] = st_offset ;
346
387
MPI_Type_size_x (types [0 ], & old_size );
347
388
flat -> blocklens [j ] = blocklength * old_size ;
348
389
for (i = j + 1 ; i < j + top_count ; i ++ ) {
390
+ flatlist_node_grow (flat , i );
349
391
flat -> indices [i ] = flat -> indices [i - 1 ] + adds [0 ];
350
392
flat -> blocklens [i ] = flat -> blocklens [j ];
351
393
}
@@ -376,6 +418,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
376
418
num = * curr_index - prev_index ;
377
419
for (i = 1 ; i < top_count ; i ++ ) {
378
420
for (m = 0 ; m < num ; m ++ ) {
421
+ flatlist_node_grow (flat , j );
379
422
flat -> indices [j ] = flat -> indices [j - num ] + adds [0 ];
380
423
flat -> blocklens [j ] = flat -> blocklens [j - num ];
381
424
j ++ ;
@@ -417,11 +460,9 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
417
460
flat -> blocklens [nonzeroth ] =
418
461
blocklength * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
419
462
nonzeroth ++ ;
420
- } else {
421
- flat -> count -- ; /* don't count/consider any zero-length blocklens */
422
463
}
423
464
}
424
- * curr_index = i ;
465
+ * curr_index = nonzeroth ;
425
466
} else {
426
467
/* indexed type made up of noncontiguous derived types */
427
468
@@ -440,8 +481,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
440
481
flat -> blocklens [nonzeroth ] = flat -> blocklens [nonzeroth - num ];
441
482
j ++ ;
442
483
nonzeroth ++ ;
443
- } else {
444
- flat -> count -- ;
445
484
}
446
485
}
447
486
}
@@ -462,8 +501,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
462
501
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - num ];
463
502
j ++ ;
464
503
nonzeroth ++ ;
465
- } else {
466
- flat -> count -- ;
467
504
}
468
505
}
469
506
* curr_index = j ;
@@ -476,8 +513,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
476
513
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - basic_num ];
477
514
j ++ ;
478
515
nonzeroth ++ ;
479
- } else {
480
- flat -> count -- ;
481
516
}
482
517
}
483
518
}
@@ -523,9 +558,11 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
523
558
* avoid >2G integer arithmetic problems */
524
559
ADIO_Offset blocklength = ints [1 ];
525
560
if (is_hindexed_block ) {
561
+ flatlist_node_grow (flat , i );
526
562
flat -> indices [i ] = st_offset + adds [i - j ];
527
563
} else {
528
564
ADIO_Offset stride = ints [1 + 1 + i - j ];
565
+ flatlist_node_grow (flat , i );
529
566
flat -> indices [i ] = st_offset +
530
567
stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
531
568
}
@@ -547,6 +584,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
547
584
* extent of a type */
548
585
MPI_Type_get_extent (types [0 ], & lb , & old_extent );
549
586
}
587
+ flatlist_node_grow (flat , j );
550
588
flat -> indices [j ] = flat -> indices [j - num ] +
551
589
ADIOI_AINT_CAST_TO_OFFSET old_extent ;
552
590
flat -> blocklens [j ] = flat -> blocklens [j - num ];
@@ -560,11 +598,13 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
560
598
for (i = 1 ; i < top_count ; i ++ ) {
561
599
for (m = 0 ; m < num ; m ++ ) {
562
600
if (is_hindexed_block ) {
601
+ flatlist_node_grow (flat , j );
563
602
flat -> indices [j ] = flat -> indices [j - num ] + adds [i ] - adds [i - 1 ];
564
603
} else {
565
604
/* By using ADIO_Offset we preserve +/- sign and
566
605
* avoid >2G integer arithmetic problems */
567
606
ADIO_Offset stride = ints [2 + i ] - ints [1 + i ];
607
+ flatlist_node_grow (flat , j );
568
608
flat -> indices [j ] = flat -> indices [j - num ] +
569
609
stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
570
610
}
@@ -599,14 +639,13 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
599
639
/* By using ADIO_Offset we preserve +/- sign and
600
640
* avoid >2G integer arithmetic problems */
601
641
ADIO_Offset blocklength = ints [1 + i - j ];
642
+ flatlist_node_grow (flat , nonzeroth );
602
643
flat -> indices [nonzeroth ] = st_offset + adds [i - j ];
603
644
flat -> blocklens [nonzeroth ] = blocklength * old_size ;
604
645
nonzeroth ++ ;
605
- } else {
606
- flat -> count -- ;
607
646
}
608
647
}
609
- * curr_index = i ;
648
+ * curr_index = nonzeroth ;
610
649
} else {
611
650
/* indexed type made up of noncontiguous derived types */
612
651
@@ -625,8 +664,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
625
664
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - num ];
626
665
j ++ ;
627
666
nonzeroth ++ ;
628
- } else {
629
- flat -> count -- ;
630
667
}
631
668
}
632
669
}
@@ -643,8 +680,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
643
680
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - num ];
644
681
j ++ ;
645
682
nonzeroth ++ ;
646
- } else {
647
- flat -> count -- ;
648
683
}
649
684
}
650
685
* curr_index = j ;
@@ -686,6 +721,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
686
721
if (ints [1 + n ] > 0 || types [n ] == MPI_LB || types [n ] == MPI_UB ) {
687
722
ADIO_Offset blocklength = ints [1 + n ];
688
723
j = * curr_index ;
724
+ flatlist_node_grow (flat , j );
689
725
flat -> indices [j ] = st_offset + adds [n ];
690
726
MPI_Type_size_x (types [n ], & old_size );
691
727
flat -> blocklens [j ] = blocklength * old_size ;
@@ -700,9 +736,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
700
736
n , adds [n ], j , flat -> indices [j ], j , flat -> blocklens [j ]);
701
737
#endif
702
738
(* curr_index )++ ;
703
- } else {
704
- flat -> count -- ; /* don't count/consider any zero-length
705
- * blocklens */
706
739
}
707
740
} else {
708
741
/* current type made up of noncontiguous derived types */
@@ -746,6 +779,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
746
779
* bound based on the inner type, but the lower bound based on the
747
780
* upper type. check both lb and ub to prevent mixing updates */
748
781
if (flat -> lb_idx == -1 && flat -> ub_idx == -1 ) {
782
+ flatlist_node_grow (flat , j );
749
783
flat -> indices [j ] = st_offset + adds [0 ];
750
784
/* this zero-length blocklens[] element, unlike elsewhere in the
751
785
* flattening code, is correct and is used to indicate a lower bound
@@ -765,7 +799,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
765
799
} else {
766
800
/* skipped over this chunk because something else higher-up in the
767
801
* type construction set this for us already */
768
- flat -> count -- ;
769
802
st_offset -= adds [0 ];
770
803
}
771
804
@@ -779,6 +812,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
779
812
} else {
780
813
/* current type is basic or contiguous */
781
814
j = * curr_index ;
815
+ flatlist_node_grow (flat , j );
782
816
flat -> indices [j ] = st_offset ;
783
817
MPI_Type_size_x (types [0 ], & old_size );
784
818
flat -> blocklens [j ] = old_size ;
@@ -797,6 +831,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
797
831
/* see note above about mixing updates for why we check lb and ub */
798
832
if ((flat -> lb_idx == -1 && flat -> ub_idx == -1 ) || lb_updated ) {
799
833
j = * curr_index ;
834
+ flatlist_node_grow (flat , j );
800
835
flat -> indices [j ] = st_offset + adds [0 ] + adds [1 ];
801
836
/* again, zero-element ok: an upper-bound marker explicitly set by the
802
837
* constructor of this resized type */
@@ -805,7 +840,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node * flat,
805
840
} else {
806
841
/* skipped over this chunk because something else higher-up in the
807
842
* type construction set this for us already */
808
- flat -> count -- ;
809
843
(* curr_index )-- ;
810
844
}
811
845
0 commit comments