@@ -98,6 +98,33 @@ int ADIOI_Type_get_contents (MPI_Datatype datatype, int max_integers,
98
98
return rc ;
99
99
}
100
100
101
+ /*
102
+ * I don't really expect this to ever trigger, but without the below safety
103
+ * valve, the design relies on the Count function coming out >= whatever
104
+ * the Flatten function comes up with. There are enough differences between
105
+ * the two that it's hard to be positive this will always be true. So every
106
+ * time something's added to flat's arrays, let's make sure they're big enough
107
+ * and re-alloc if not.
108
+ */
109
+ static void flatlist_node_grow (ADIOI_Flatlist_node * flat , int idx )
110
+ {
111
+ if (idx >= flat -> count ) {
112
+ ADIO_Offset * new_blocklens ;
113
+ ADIO_Offset * new_indices ;
114
+ int new_count = (flat -> count * 1.25 + 4 );
115
+ new_blocklens = (ADIO_Offset * ) ADIOI_Calloc (new_count * 2 , sizeof (ADIO_Offset ));
116
+ new_indices = new_blocklens + new_count ;
117
+ if (flat -> count ) {
118
+ memcpy (new_blocklens , flat -> blocklens , flat -> count * sizeof (ADIO_Offset ));
119
+ memcpy (new_indices , flat -> indices , flat -> count * sizeof (ADIO_Offset ));
120
+ ADIOI_Free (flat -> blocklens );
121
+ }
122
+ flat -> blocklens = new_blocklens ;
123
+ flat -> indices = new_indices ;
124
+ flat -> count = new_count ;
125
+ }
126
+ }
127
+
101
128
void ADIOI_Optimize_flattened (ADIOI_Flatlist_node * flat_type );
102
129
/* flatten datatype and add it to Flatlist */
103
130
void ADIOI_Flatten_datatype (MPI_Datatype datatype )
@@ -168,6 +195,16 @@ void ADIOI_Flatten_datatype(MPI_Datatype datatype)
168
195
DBG_FPRINTF (stderr ,"ADIOI_Flatten_datatype:: ADIOI_Flatten\n" );
169
196
#endif
170
197
198
+ /*
199
+ * Setting flat->count to curr_index, since curr_index is the most fundamentally
200
+ * correct updated value that represents what's in the indices/blocklens arrays.
201
+ * It would be nice if the counter function and the flatten function were in sync,
202
+ * but the numerous cases that decrement flat->count in the flatten function show
203
+ * that syncing them is a hack, and as long as the counter doesn't under-count
204
+ * it's good enough.
205
+ */
206
+ flat -> count = curr_index ;
207
+
171
208
ADIOI_Optimize_flattened (flat );
172
209
#endif
173
210
/* debug */
@@ -318,6 +355,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
318
355
if (prev_index == * curr_index ) {
319
356
/* simplest case, made up of basic or contiguous types */
320
357
j = * curr_index ;
358
+ flatlist_node_grow (flat , j );
321
359
flat -> indices [j ] = st_offset ;
322
360
MPI_Type_size_x (types [0 ], & old_size );
323
361
flat -> blocklens [j ] = top_count * old_size ;
@@ -335,6 +373,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
335
373
MPI_Type_get_extent (types [0 ], & lb , & old_extent );
336
374
for (m = 1 ; m < top_count ; m ++ ) {
337
375
for (i = 0 ; i < num ; i ++ ) {
376
+ flatlist_node_grow (flat , j );
338
377
flat -> indices [j ] = flat -> indices [j - num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
339
378
flat -> blocklens [j ] = flat -> blocklens [j - num ];
340
379
#ifdef FLATTEN_DEBUG
@@ -366,10 +405,12 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
366
405
avoid >2G integer arithmetic problems */
367
406
ADIO_Offset blocklength = ints [1 ], stride = ints [2 ];
368
407
j = * curr_index ;
408
+ flatlist_node_grow (flat , j );
369
409
flat -> indices [j ] = st_offset ;
370
410
MPI_Type_size_x (types [0 ], & old_size );
371
411
flat -> blocklens [j ] = blocklength * old_size ;
372
412
for (i = j + 1 ; i < j + top_count ; i ++ ) {
413
+ flatlist_node_grow (flat , i );
373
414
flat -> indices [i ] = flat -> indices [i - 1 ] + stride * old_size ;
374
415
flat -> blocklens [i ] = flat -> blocklens [j ];
375
416
}
@@ -389,6 +430,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
389
430
MPI_Type_get_extent (types [0 ], & lb , & old_extent );
390
431
for (m = 1 ; m < blocklength ; m ++ ) {
391
432
for (i = 0 ; i < num ; i ++ ) {
433
+ flatlist_node_grow (flat , j );
392
434
flat -> indices [j ] = flat -> indices [j - num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
393
435
flat -> blocklens [j ] = flat -> blocklens [j - num ];
394
436
j ++ ;
@@ -400,6 +442,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
400
442
num = * curr_index - prev_index ;
401
443
for (i = 1 ; i < top_count ; i ++ ) {
402
444
for (m = 0 ; m < num ; m ++ ) {
445
+ flatlist_node_grow (flat , j );
403
446
flat -> indices [j ] = flat -> indices [j - num ] + stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
404
447
flat -> blocklens [j ] = flat -> blocklens [j - num ];
405
448
j ++ ;
@@ -429,10 +472,12 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
429
472
avoid >2G integer arithmetic problems */
430
473
ADIO_Offset blocklength = ints [1 ];
431
474
j = * curr_index ;
475
+ flatlist_node_grow (flat , j );
432
476
flat -> indices [j ] = st_offset ;
433
477
MPI_Type_size_x (types [0 ], & old_size );
434
478
flat -> blocklens [j ] = blocklength * old_size ;
435
479
for (i = j + 1 ; i < j + top_count ; i ++ ) {
480
+ flatlist_node_grow (flat , i );
436
481
flat -> indices [i ] = flat -> indices [i - 1 ] + adds [0 ];
437
482
flat -> blocklens [i ] = flat -> blocklens [j ];
438
483
}
@@ -452,6 +497,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
452
497
MPI_Type_get_extent (types [0 ], & lb , & old_extent );
453
498
for (m = 1 ; m < blocklength ; m ++ ) {
454
499
for (i = 0 ; i < num ; i ++ ) {
500
+ flatlist_node_grow (flat , j );
455
501
flat -> indices [j ] = flat -> indices [j - num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
456
502
flat -> blocklens [j ] = flat -> blocklens [j - num ];
457
503
j ++ ;
@@ -463,6 +509,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
463
509
num = * curr_index - prev_index ;
464
510
for (i = 1 ; i < top_count ; i ++ ) {
465
511
for (m = 0 ; m < num ; m ++ ) {
512
+ flatlist_node_grow (flat , j );
466
513
flat -> indices [j ] = flat -> indices [j - num ] + adds [0 ];
467
514
flat -> blocklens [j ] = flat -> blocklens [j - num ];
468
515
j ++ ;
@@ -500,16 +547,15 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
500
547
avoid >2G integer arithmetic problems */
501
548
ADIO_Offset blocklength = ints [1 + i - j ], stride = ints [top_count + 1 + i - j ];
502
549
if (blocklength > 0 ) {
550
+ flatlist_node_grow (flat , nonzeroth );
503
551
flat -> indices [nonzeroth ] =
504
552
st_offset + stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
505
553
flat -> blocklens [nonzeroth ] =
506
554
blocklength * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
507
555
nonzeroth ++ ;
508
- } else {
509
- flat -> count -- ; /* don't count/consider any zero-length blocklens */
510
556
}
511
557
}
512
- * curr_index = i ;
558
+ * curr_index = nonzeroth ;
513
559
}
514
560
else {
515
561
/* indexed type made up of noncontiguous derived types */
@@ -523,14 +569,13 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
523
569
for (m = 1 ; m < ints [1 ]; m ++ ) {
524
570
for (i = 0 , nonzeroth = j ; i < num ; i ++ ) {
525
571
if (flat -> blocklens [j - num ] > 0 ) {
572
+ flatlist_node_grow (flat , nonzeroth );
526
573
flat -> indices [nonzeroth ] =
527
574
flat -> indices [nonzeroth - num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
528
575
flat -> blocklens [nonzeroth ] =
529
576
flat -> blocklens [nonzeroth - num ];
530
577
j ++ ;
531
578
nonzeroth ++ ;
532
- } else {
533
- flat -> count -- ;
534
579
}
535
580
}
536
581
}
@@ -545,26 +590,24 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
545
590
avoid >2G integer arithmetic problems */
546
591
ADIO_Offset stride = ints [top_count + 1 + i ]- ints [top_count + i ];
547
592
if (flat -> blocklens [j - num ] > 0 ) {
593
+ flatlist_node_grow (flat , nonzeroth );
548
594
flat -> indices [nonzeroth ] =
549
595
flat -> indices [j - num ] + stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
550
596
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - num ];
551
597
j ++ ;
552
598
nonzeroth ++ ;
553
- } else {
554
- flat -> count -- ;
555
599
}
556
600
}
557
601
* curr_index = j ;
558
602
for (m = 1 ; m < ints [1 + i ]; m ++ ) {
559
603
for (k = 0 , nonzeroth = j ; k < basic_num ; k ++ ) {
560
604
if (flat -> blocklens [j - basic_num ] > 0 ) {
605
+ flatlist_node_grow (flat , nonzeroth );
561
606
flat -> indices [nonzeroth ] =
562
607
flat -> indices [j - basic_num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
563
608
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - basic_num ];
564
609
j ++ ;
565
610
nonzeroth ++ ;
566
- } else {
567
- flat -> count -- ;
568
611
}
569
612
}
570
613
}
@@ -611,9 +654,11 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
611
654
avoid >2G integer arithmetic problems */
612
655
ADIO_Offset blocklength = ints [1 ];
613
656
if (is_hindexed_block ) {
657
+ flatlist_node_grow (flat , i );
614
658
flat -> indices [i ] = st_offset + adds [i - j ];
615
659
} else {
616
660
ADIO_Offset stride = ints [1 + 1 + i - j ];
661
+ flatlist_node_grow (flat , i );
617
662
flat -> indices [i ] = st_offset +
618
663
stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
619
664
}
@@ -636,6 +681,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
636
681
* extent of a type */
637
682
MPI_Type_get_extent (types [0 ], & lb , & old_extent );
638
683
}
684
+ flatlist_node_grow (flat , j );
639
685
flat -> indices [j ] = flat -> indices [j - num ] +
640
686
ADIOI_AINT_CAST_TO_OFFSET old_extent ;
641
687
flat -> blocklens [j ] = flat -> blocklens [j - num ];
@@ -649,12 +695,14 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
649
695
for (i = 1 ; i < top_count ; i ++ ) {
650
696
for (m = 0 ; m < num ; m ++ ) {
651
697
if (is_hindexed_block ) {
698
+ flatlist_node_grow (flat , j );
652
699
flat -> indices [j ] = flat -> indices [j - num ] +
653
700
adds [i ] - adds [i - 1 ];
654
701
} else {
655
702
/* By using ADIO_Offset we preserve +/- sign and
656
703
avoid >2G integer arithmetic problems */
657
704
ADIO_Offset stride = ints [2 + i ]- ints [1 + i ];
705
+ flatlist_node_grow (flat , j );
658
706
flat -> indices [j ] = flat -> indices [j - num ] +
659
707
stride * ADIOI_AINT_CAST_TO_OFFSET old_extent ;
660
708
}
@@ -691,14 +739,13 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
691
739
/* By using ADIO_Offset we preserve +/- sign and
692
740
avoid >2G integer arithmetic problems */
693
741
ADIO_Offset blocklength = ints [1 + i - j ];
742
+ flatlist_node_grow (flat , nonzeroth );
694
743
flat -> indices [nonzeroth ] = st_offset + adds [i - j ];
695
744
flat -> blocklens [nonzeroth ] = blocklength * old_size ;
696
745
nonzeroth ++ ;
697
- } else {
698
- flat -> count -- ;
699
746
}
700
747
}
701
- * curr_index = i ;
748
+ * curr_index = nonzeroth ;
702
749
}
703
750
else {
704
751
/* indexed type made up of noncontiguous derived types */
@@ -713,13 +760,12 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
713
760
for (m = 1 ; m < ints [1 ]; m ++ ) {
714
761
for (i = 0 , nonzeroth = j ; i < num ; i ++ ) {
715
762
if (flat -> blocklens [j - num ] > 0 ) {
763
+ flatlist_node_grow (flat , nonzeroth );
716
764
flat -> indices [nonzeroth ] =
717
765
flat -> indices [j - num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
718
766
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - num ];
719
767
j ++ ;
720
768
nonzeroth ++ ;
721
- } else {
722
- flat -> count -- ;
723
769
}
724
770
}
725
771
}
@@ -731,19 +777,19 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
731
777
prev_index = * curr_index ;
732
778
for (m = 0 , nonzeroth = j ; m < basic_num ; m ++ ) {
733
779
if (flat -> blocklens [j - num ] > 0 ) {
780
+ flatlist_node_grow (flat , nonzeroth );
734
781
flat -> indices [nonzeroth ] =
735
782
flat -> indices [j - num ] + adds [i ] - adds [i - 1 ];
736
783
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - num ];
737
784
j ++ ;
738
785
nonzeroth ++ ;
739
- } else {
740
- flat -> count -- ;
741
786
}
742
787
}
743
788
* curr_index = j ;
744
789
for (m = 1 ; m < ints [1 + i ]; m ++ ) {
745
790
for (k = 0 ,nonzeroth = j ; k < basic_num ; k ++ ) {
746
791
if (flat -> blocklens [j - basic_num ] > 0 ) {
792
+ flatlist_node_grow (flat , nonzeroth );
747
793
flat -> indices [nonzeroth ] =
748
794
flat -> indices [j - basic_num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
749
795
flat -> blocklens [nonzeroth ] = flat -> blocklens [j - basic_num ];
@@ -779,6 +825,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
779
825
if (ints [1 + n ] > 0 ) {
780
826
ADIO_Offset blocklength = ints [1 + n ];
781
827
j = * curr_index ;
828
+ flatlist_node_grow (flat , j );
782
829
flat -> indices [j ] = st_offset + adds [n ];
783
830
MPI_Type_size_x (types [n ], & old_size );
784
831
flat -> blocklens [j ] = blocklength * old_size ;
@@ -798,6 +845,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
798
845
MPI_Type_get_extent (types [n ], & lb , & old_extent );
799
846
for (m = 1 ; m < ints [1 + n ]; m ++ ) {
800
847
for (i = 0 ; i < num ; i ++ ) {
848
+ flatlist_node_grow (flat , j );
801
849
flat -> indices [j ] =
802
850
flat -> indices [j - num ] + ADIOI_AINT_CAST_TO_OFFSET old_extent ;
803
851
flat -> blocklens [j ] = flat -> blocklens [j - num ];
@@ -827,6 +875,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
827
875
* bound based on the inner type, but the lower bound based on the
828
876
* upper type. check both lb and ub to prevent mixing updates */
829
877
if (flat -> lb_idx == -1 && flat -> ub_idx == -1 ) {
878
+ flatlist_node_grow (flat , j );
830
879
flat -> indices [j ] = st_offset + adds [0 ];
831
880
/* this zero-length blocklens[] element, unlike eleswhere in the
832
881
* flattening code, is correct and is used to indicate a lower bound
@@ -843,7 +892,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
843
892
} else {
844
893
/* skipped over this chunk because something else higher-up in the
845
894
* type construction set this for us already */
846
- flat -> count -- ;
847
895
st_offset -= adds [0 ];
848
896
}
849
897
@@ -859,6 +907,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
859
907
else {
860
908
/* current type is basic or contiguous */
861
909
j = * curr_index ;
910
+ flatlist_node_grow (flat , j );
862
911
flat -> indices [j ] = st_offset ;
863
912
MPI_Type_size_x (types [0 ], & old_size );
864
913
flat -> blocklens [j ] = old_size ;
@@ -874,6 +923,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
874
923
/* see note above about mixing updates for why we check lb and ub */
875
924
if ((flat -> lb_idx == -1 && flat -> ub_idx == -1 ) || lb_updated ) {
876
925
j = * curr_index ;
926
+ flatlist_node_grow (flat , j );
877
927
flat -> indices [j ] = st_offset + adds [0 ] + adds [1 ];
878
928
/* again, zero-element ok: an upper-bound marker explicitly set by the
879
929
* constructor of this resized type */
@@ -882,7 +932,6 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
882
932
} else {
883
933
/* skipped over this chunk because something else higher-up in the
884
934
* type construction set this for us already */
885
- flat -> count -- ;
886
935
(* curr_index )-- ;
887
936
}
888
937
0 commit comments