Stan Math Library
4.9.0
Automatic Differentiation
|
|
inline |
Call an instance of the function ReduceFunction
on every element of an input sequence and sum these terms.
This specialization is parallelized using tbb and works only for arithmetic types.
ReduceFunction must define an operator() with the same signature as: double f(Vec&& vmapped_subset, int start, int end, std::ostream* msgs, Args&&... args)
ReduceFunction
must be default constructible without any arguments
Each call to ReduceFunction
is responsible for computing the start through end (inclusive) terms of the overall sum. All args are passed from this function through to the ReduceFunction
instances. However, only the start through end (inclusive) elements of the vmapped argument are passed to the ReduceFunction
instances (as the vmapped_subset
argument).
This function distributes computation of the desired sum over multiple threads by coordinating calls to ReduceFunction
instances.
If auto partitioning is true, break work into pieces automatically, taking grainsize as a recommended work size. The partitioning is not deterministic nor is the order guaranteed in which partial sums are accumulated. Due to floating point imprecisions this will likely lead to slight differences in the accumulated results between multiple runs. If false, break work deterministically into pieces smaller than or equal to grainsize and accumulate all the partial sums in the same order. This still may not achieve bitwise reproducibility.
grainsize must be greater than or equal to 1
vmapped | Vector containing one element per term of sum | |
auto_partitioning | Work partitioning style | |
grainsize | Suggested grainsize for tbb | |
[in,out] | msgs | The print stream for warning messages |
args | Shared arguments used in every sum term |
Definition at line 145 of file reduce_sum.hpp.