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
5
namespace
chi_math
6
{
7
8
/**Computes a global L2-norm*/
9
double
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
chi_math.h
VecDbl
std::vector< double > VecDbl
Definition:
chi_math.h:12
chi_math_mpi.h
chi_math
Definition:
chi_runtime.h:42
chi_math::Vec2NormMPI
double Vec2NormMPI(const VecDbl &x, MPI_Comm comm)
Definition:
chi_math_mpi_03_vecops.cc:9
framework
math
chi_math_mpi_03_vecops.cc
Generated by
1.9.3