Skip to content

Commit 3a8f185

Browse files
committed
[Minuit2] Restore thread safety of numerical gradient
Just like the input vector `x` needs to be replicated per thread, the function evaluator needs to be instantiated per thread too since it caches the transformed parameters.
1 parent cb8987a commit 3a8f185

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

math/minuit2/src/Numerical2PGradientCalculator.cxx

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ operator()(const MinimumParameters &par, const FunctionGradient &Gradient) const
5454
// std::cout<<"position: "<<par.Vec()<<std::endl;
5555
MnPrint print("Numerical2PGradientCalculator");
5656

57-
MnFcnCaller mfcnCaller{fFcn};
58-
5957
assert(par.IsValid());
6058

6159
double fcnmin = par.Fval();
@@ -88,6 +86,7 @@ operator()(const MinimumParameters &par, const FunctionGradient &Gradient) const
8886

8987
// for serial execution this can be outside the loop
9088
MnAlgebraicVector x = par.Vec();
89+
MnFcnCaller mfcnCaller{fFcn};
9190

9291
unsigned int startElementIndex = mpiproc.StartElementIndex();
9392
unsigned int endElementIndex = mpiproc.EndElementIndex();
@@ -109,6 +108,7 @@ operator()(const MinimumParameters &par, const FunctionGradient &Gradient) const
109108
#ifdef _OPENMP
110109
// create in loop since each thread will use its own copy
111110
MnAlgebraicVector x = par.Vec();
111+
MnFcnCaller mfcnCaller{fFcn};
112112
#endif
113113

114114
double xtf = x(i);
@@ -139,10 +139,6 @@ operator()(const MinimumParameters &par, const FunctionGradient &Gradient) const
139139
}
140140
gstep(i) = step;
141141
stepb4 = step;
142-
// MnAlgebraicVector pstep(n);
143-
// pstep(i) = step;
144-
// double fs1 = mfcnCaller(pstate + pstep);
145-
// double fs2 = mfcnCaller(pstate - pstep);
146142

147143
x(i) = xtf + step;
148144
double fs1 = mfcnCaller(x);

0 commit comments

Comments
 (0)