Chi-Tech
chi_math_mpi_03_vecops.cc
Go to the documentation of this file.
1#include "chi_math_mpi.h"
2
3#include "chi_math.h"
4
5namespace chi_math
6{
7
8/**Computes a global L2-norm*/
9double Vec2NormMPI(const VecDbl& x, MPI_Comm comm)
10{
11 size_t n = x.size();
12 double local_sum = 0.;
13
14 for(size_t i = 0; i != n; i++)
15 local_sum += x[i]*x[i];
16
17 double global_sum;
18 MPI_Allreduce(&local_sum, //sendbuf
19 &global_sum, //recvbuf
20 1, MPI_DOUBLE, //count + datatype
21 MPI_SUM, //operation
22 comm); //communicator
23
24 return sqrt(global_sum);
25}
26
27}//namespace chi_math
std::vector< double > VecDbl
Definition: chi_math.h:12
double Vec2NormMPI(const VecDbl &x, MPI_Comm comm)