@@ -86,6 +86,57 @@ void Geocode<T>::geoGrid(double geoGridStartX, double geoGridStartY,
86
86
_epsgOut = epsgcode;
87
87
}
88
88
89
+
90
+ void getBlocksNumberAndLength (const int array_length, const int array_width,
91
+ const int nbands, const size_t type_size,
92
+ pyre::journal::info_t * channel,
93
+ int * block_length, int * nblocks_y,
94
+ const long long max_block_size) {
95
+
96
+ const int max_block_length = max_block_size /
97
+ (nbands * array_width * type_size);
98
+
99
+ int _block_length = std::min (array_length, max_block_length);
100
+
101
+ // update nblocks
102
+ int _nblocks_y = std::ceil ((static_cast <float >(array_length)) / _block_length);
103
+
104
+ if (nblocks_y != nullptr )
105
+ *nblocks_y = _nblocks_y;
106
+
107
+ if (channel != nullptr ) {
108
+ *channel << " array length: " << array_length << pyre::journal::newline;
109
+ *channel << " array width: " << array_width << pyre::journal::newline;
110
+ *channel << " number of block(s): " << _nblocks_y
111
+ << pyre::journal::newline;
112
+ }
113
+
114
+ if (block_length != nullptr ) {
115
+ *block_length = _block_length;
116
+ if (channel != nullptr ) {
117
+ *channel << " block length: " << *block_length
118
+ << pyre::journal::newline;
119
+ *channel << " block width: " << array_width
120
+ << pyre::journal::newline;
121
+ }
122
+ }
123
+
124
+ if (channel != nullptr ) {
125
+
126
+ long long block_size_bytes =
127
+ ((static_cast <long long >(_block_length)) *
128
+ array_width * nbands * type_size);
129
+
130
+ std::string block_size_bytes_str = geometry::getNbytesStr (block_size_bytes);
131
+ if (nbands > 1 )
132
+ block_size_bytes_str += " (" + std::to_string (nbands) + " bands)" ;
133
+
134
+ *channel << " block size: " << block_size_bytes_str
135
+ << pyre::journal::endl;
136
+ }
137
+ }
138
+
139
+
89
140
template <class T >
90
141
void Geocode<T>::geocode(
91
142
const isce3::product::RadarGridParameters& radar_grid,
@@ -597,23 +648,91 @@ void _getUpsampledBlock(
597
648
{
598
649
int nbands = input_raster.numBands ();
599
650
rdrData.reserve (nbands);
651
+ bool flag_parallel_radargrid_read = geocode_memory_mode ==
652
+ geocodeMemoryMode::BLOCKS_GEOGRID_AND_RADARGRID;
600
653
for (int band = 0 ; band < nbands; ++band) {
601
- if (geocode_memory_mode !=
602
- geocodeMemoryMode::BLOCKS_GEOGRID_AND_RADARGRID) {
654
+ if (!flag_parallel_radargrid_read) {
603
655
info << " reading input raster band: " << band + 1
604
656
<< pyre::journal::endl;
605
657
}
658
+
606
659
rdrData.emplace_back (
607
660
std::make_unique<isce3::core::Matrix<T_out>>(size_y, size_x));
608
- if (!flag_upsample_radar_grid && std::is_same<T, T_out>::value) {
609
- #pragma omp critical
661
+
662
+ if (!flag_upsample_radar_grid && std::is_same<T, T_out>::value &&
663
+ !flag_parallel_radargrid_read) {
664
+ /*
665
+ Enter here if:
666
+ 1. No upsampling is required;
667
+ 2. No type convertion is required (input and output have same
668
+ types);
669
+ 3. Not parallel (which allows messages to be printed to stdout).
670
+ */
671
+
672
+ int radargrid_nblocks, radar_block_length;
673
+ const int max_block_size = 1 << 28 ; // 256MB
674
+ isce3::geocode::getBlocksNumberAndLength (size_y, size_x, 1 , sizeof (T),
675
+ nullptr , &radar_block_length, &radargrid_nblocks,
676
+ max_block_size);
677
+
678
+ for (size_t block = 0 ; block < (size_t ) radargrid_nblocks;
679
+ ++block) {
680
+
681
+ int this_radar_block_length = radar_block_length;
682
+ if ((block + 1 ) * radar_block_length > size_y) {
683
+ this_radar_block_length = size_y % radar_block_length;
684
+ }
685
+ if (radargrid_nblocks > 1 ) {
686
+ std::cout << " reading band " << band + 1 << " progress: "
687
+ << static_cast <int >((100.0 * block) / radargrid_nblocks)
688
+ << " % \r " ;
689
+ std::cout.flush ();
690
+ }
691
+ auto ptr = rdrData[band]->data ();
692
+ input_raster.getBlock (ptr +
693
+ block * radar_block_length * size_x,
694
+ xidx, block * radar_block_length + yidx, size_x,
695
+ this_radar_block_length, band + 1 );
696
+ }
697
+
698
+ if (radargrid_nblocks > 1 ) {
699
+ std::cout << " reading band " << band + 1
700
+ << " progress: 100%" << std::endl;
701
+ }
702
+ }
703
+ else if (!flag_upsample_radar_grid && std::is_same<T, T_out>::value) {
704
+ /*
705
+ Enter here if:
706
+ 1. No upsampling is required;
707
+ 2. No type convertion is required (input and output have same
708
+ types);
709
+ 3. Is parallel (which does not allow messages to be printed to
710
+ stdout).
711
+ */
712
+ _Pragma (" omp critical" )
713
+ {
610
714
input_raster.getBlock (rdrData[band]->data (), xidx, yidx, size_x,
611
715
size_y, band + 1 );
612
- } else if (!flag_upsample_radar_grid) {
716
+ }
717
+ }
718
+ else if (!flag_upsample_radar_grid) {
719
+ /*
720
+ Enter here if:
721
+ 1. No upsampling is required;
722
+ 2. Type convertion is required (input and output have different
723
+ types).
724
+ */
613
725
isce3::core::Matrix<T> radar_data_in (size_y, size_x);
614
- #pragma omp critical
615
- input_raster.getBlock (radar_data_in.data (), xidx, yidx, size_x,
616
- size_y, band + 1 );
726
+ if (flag_parallel_radargrid_read) {
727
+ _Pragma (" omp critical" )
728
+ {
729
+ input_raster.getBlock (radar_data_in.data (), xidx, yidx, size_x,
730
+ size_y, band + 1 );
731
+ }
732
+ } else {
733
+ input_raster.getBlock (radar_data_in.data (), xidx, yidx, size_x,
734
+ size_y, band + 1 );
735
+ }
617
736
618
737
/*
619
738
Iteratively converts input pixel (ptr_1) to output pixel (ptr_2).
@@ -630,10 +749,20 @@ void _getUpsampledBlock(
630
749
_convertToOutputType (*ptr_1++, *ptr_2++);
631
750
}
632
751
} else if (flag_upsample_radar_grid && !isce3::is_complex<T>()) {
752
+ /*
753
+ Enter here if:
754
+ 1. Upsampling is required;
755
+ 2. Input is not complex.
756
+ */
633
757
std::string error_msg = " radar-grid upsampling is only available" ;
634
758
error_msg += " for complex inputs" ;
635
759
throw isce3::except::InvalidArgument (ISCE_SRCINFO (), error_msg);
636
760
} else {
761
+ /*
762
+ Enter here if:
763
+ 1. Upsampling is required;
764
+ 2. Input is complex.
765
+ */
637
766
int radargrid_nblocks, radar_block_size;
638
767
if (geocode_memory_mode == geocodeMemoryMode::SINGLE_BLOCK ||
639
768
geocode_memory_mode ==
0 commit comments