Skip to content

Commit 9a71406

Browse files
authored
Guard TreeLattice::stepback OpenMP parallel-for for small tree steps (#2745)
2 parents 557cf6d + b2ba234 commit 9a71406

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ql/methods/lattices/lattice.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ namespace QuantLib {
166166
template <class Impl>
167167
void TreeLattice<Impl>::stepback(Size i, const Array& values,
168168
Array& newValues) const {
169-
#pragma omp parallel for
169+
// Early tree steps can have very few nodes, where the cost of
170+
// spawning an OpenMP thread team outweighs the work being
171+
// parallelized. Only parallelize once there's enough work to
172+
// amortize that overhead.
173+
#pragma omp parallel for if(this->impl().size(i) >= 1024)
170174
for (long j=0; j<(long)this->impl().size(i); j++) {
171175
Real value = 0.0;
172176
for (Size l=0; l<n_; l++) {

0 commit comments

Comments
 (0)