1 |
gezelter |
1741 |
#ifdef IS_MPI |
2 |
|
|
#include <mpi.h> |
3 |
|
|
#endif |
4 |
|
|
|
5 |
gezelter |
1938 |
#include "config.h" |
6 |
|
|
#include "optimization/Problem.hpp" |
7 |
gezelter |
1741 |
|
8 |
|
|
namespace QuantLib { |
9 |
|
|
RealType Problem::DotProduct(DynamicVector<RealType>& v1, |
10 |
|
|
DynamicVector<RealType>& v2){ |
11 |
|
|
RealType dp = dot(v1, v2); |
12 |
|
|
#ifdef IS_MPI |
13 |
|
|
// in parallel, we need to add up the contributions from all |
14 |
|
|
// processors: |
15 |
|
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &dp, 1, MPI::REALTYPE, |
16 |
|
|
MPI::SUM); |
17 |
|
|
#endif |
18 |
|
|
return dp; |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
RealType Problem::computeGradientNormValue(DynamicVector<RealType>& grad_f) { |
22 |
|
|
|
23 |
|
|
RealType dot = grad_f.lengthSquare(); |
24 |
|
|
#ifdef IS_MPI |
25 |
|
|
// in parallel, we need to add up the contributions from all |
26 |
|
|
// processors: |
27 |
|
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &dot, 1, MPI::REALTYPE, |
28 |
|
|
MPI::SUM); |
29 |
|
|
#endif |
30 |
|
|
return dot; |
31 |
|
|
|
32 |
|
|
} |
33 |
|
|
} |