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