58 template <
bool IsExclusive,
typename DataType,
typename Operator,
59 typename InputIterator,
typename OutputIterator>
61 InputIterator input, OutputIterator output,
62 DataType init_value, Operator op)
65 auto multiple_getter_func = [=](
Int32 input_index,
Int32 nb_value) -> DataType {
66 DataType partial_value = Operator::defaultValue();
67 for (
Int32 x = 0; x < nb_value; ++x)
68 partial_value = op(input[x + input_index], partial_value);
72 auto multiple_setter_func = [=](DataType previous_sum,
Int32 input_index,
Int32 nb_value) {
73 for (
Int32 x = 0; x < nb_value; ++x) {
74 if constexpr (IsExclusive) {
75 output[x + input_index] = previous_sum;
76 previous_sum = op(input[x + input_index], previous_sum);
79 previous_sum = op(input[x + input_index], previous_sum);
80 output[x + input_index] = previous_sum;
85 const Int32 nb_block = 10;
89 SmallArray<DataType> partial_values(nb_block);
92 auto partial_value_func = [=](
Int32 a,
Int32 n) {
93 for (
Int32 i = 0; i < n; ++i) {
94 Int32 interval_index = i + a;
96 Int32 input_index = 0;
97 Int32 nb_value_in_interval = 0;
98 _subInterval<Int32>(nb_value, interval_index, nb_block, &input_index, &nb_value_in_interval);
100 DataType partial_value = multiple_getter_func(input_index, nb_value_in_interval);
102 out_partial_values[interval_index] = partial_value;
108 run_info.addOptions(loop_options);
114 for (
Int32 i = 0; i < n; ++i) {
115 Int32 interval_index = i + a;
117 DataType previous_sum = init_value;
118 for (
Int32 z = 0; z < interval_index; ++z)
119 previous_sum = op(out_partial_values[z], previous_sum);
121 Int32 input_index = 0;
122 Int32 nb_value_in_interval = 0;
123 _subInterval<Int32>(nb_value, interval_index, nb_block, &input_index, &nb_value_in_interval);
125 multiple_setter_func(previous_sum, input_index, nb_value_in_interval);
133 template <
bool InPlace,
typename InputIterator,
typename OutputIterator,
typename SelectLambda>
135 InputIterator input, OutputIterator output,
136 SelectLambda select_lambda)
139 using IndexType =
Int32;
144 auto multiple_getter_func = [=](
Int32 input_index,
Int32 nb_value) -> IndexType {
145 IndexType partial_value = 0;
146 for (
Int32 x = 0; x < nb_value; ++x) {
147 const Int32 index = x + input_index;
148 bool is_select = select_lambda(input[index]);
149 select_flags_view[index] = is_select;
153 return partial_value;
156 auto multiple_setter_func = [=](IndexType partial_value,
Int32 input_index,
Int32 nb_value) {
157 for (
Int32 x = 0; x < nb_value; ++x) {
158 const Int32 index = x + input_index;
159 if (select_flags_view[index]) {
160 output[partial_value] = input[index];
167 const Int32 nb_block = 10;
171 SmallArray<Int32> partial_values(nb_block, 0);
172 Span<Int32> out_partial_values = partial_values;
174 auto partial_value_func = [=](Int32 a, Int32 n) {
175 for (Int32 i = 0; i < n; ++i) {
176 Int32 interval_index = i + a;
178 Int32 input_index = 0;
179 Int32 nb_value_in_interval = 0;
180 _subInterval<Int32>(nb_value, interval_index, nb_block, &input_index, &nb_value_in_interval);
182 out_partial_values[interval_index] = multiple_getter_func(input_index, nb_value_in_interval);
186 ParallelLoopOptions loop_options(run_info.options().value_or(ParallelLoopOptions{}));
187 loop_options.setGrainSize(1);
188 run_info.addOptions(loop_options);
196 for (Int32 i = 0; i < nb_block; ++i) {
197 Int32 x = partial_values[i];
199 partial_values[i] = nb_filter;
202 auto filter_func = [=](Int32 a, Int32 n) {
203 for (Int32 i = 0; i < n; ++i) {
204 Int32 interval_index = i + a;
206 IndexType partial_value = 0;
207 if (interval_index > 0)
208 partial_value = out_partial_values[interval_index - 1];
210 Int32 input_index = 0;
211 Int32 nb_value_in_interval = 0;
212 _subInterval<Int32>(nb_value, interval_index, nb_block, &input_index, &nb_value_in_interval);
214 multiple_setter_func(partial_value, input_index, nb_value_in_interval);
221 filter_func(0, nb_block);
230 template <
typename SizeType>
231 static void _subInterval(SizeType size, SizeType interval_index, SizeType nb_interval,
232 SizeType* out_begin_index, SizeType* out_interval_size)
234 *out_begin_index = 0;
235 *out_interval_size = 0;
236 if (nb_interval <= 0)
238 if (interval_index < 0 || interval_index >= nb_interval)
240 SizeType isize = size / nb_interval;
241 SizeType ibegin = interval_index * isize;
243 if ((interval_index + 1) == nb_interval)
244 isize = size - ibegin;
245 *out_begin_index = ibegin;
246 *out_interval_size = isize;
void arcaneParallelFor(Integer i0, Integer size, InstanceType *itype, void(InstanceType::*lambda_function)(Integer i0, Integer size))
Applique en concurrence la fonction lambda lambda_function sur l'intervalle d'itération [i0,...