9 void vddiv(vector<double> & x, vector<double>
const& y,
10 vector<double>
const& z)
12 assert( x.size()==y.size() && y.size()==z.size() );
15 #pragma omp parallel for
16 for (
size_t k = 0; k < n; ++k)
25 void vdaxpy(std::vector<double> & x, std::vector<double>
const& y,
26 double alpha, std::vector<double>
const& z )
28 assert( x.size()==y.size() && y.size()==z.size() );
31 #pragma omp parallel for
32 for (
size_t k = 0; k < n; ++k)
34 x[k] = y[k] + alpha * z[k];
40 double dscapr(std::vector<double>
const& x, std::vector<double>
const& y)
42 assert( x.size()==y.size());
46 #pragma omp parallel for reduction(+:s)
47 for (
size_t k = 0; k < n; ++k)
56 bool CompareVectors(std::vector<double>
const& x,
int const n,
double const y[],
double const eps)
58 bool bn = (
static_cast<int>(x.size())==n);
61 cout <<
"######### Error: " <<
"number of elements" << endl;
64 bool bv = equal(x.cbegin(),x.cend(),y,
65 [eps](
double a,
double b) ->
bool
66 { return std::abs(a-b)<eps*(1.0+0.5*(std::abs(a)+ std::abs(a))); }
70 assert(
static_cast<int>(x.size())==n);
71 cout <<
"######### Error: " <<
"values" << endl;
77 double par_scalar(vector<double>
const &x, vector<double>
const &y, MPI_Comm
const& icomm)
79 const double s =
dscapr(x,y);
81 MPI_Allreduce(&s,&sg,1,MPI_DOUBLE,MPI_SUM,icomm);
87 void ExchangeAll(vector<double>
const &xin, vector<double> &yout, MPI_Comm
const &icomm)
89 int myrank, numprocs,ierr(-1);
90 MPI_Comm_rank(icomm, &myrank);
91 MPI_Comm_size(icomm, &numprocs);
92 int const N=xin.size();
93 int const sendcount = N/numprocs;
94 assert(sendcount*numprocs==N);
95 assert(xin.size()==yout.size());
97 auto sendbuf = xin.data();
98 auto recvbuf = yout.data();
99 ierr = MPI_Alltoall(sendbuf, sendcount, MPI_DOUBLE,
100 recvbuf, sendcount, MPI_DOUBLE, icomm);
109 int myrank, numprocs,ierr(-1);
110 MPI_Comm_rank(icomm, &myrank);
111 MPI_Comm_size(icomm, &numprocs);
112 int const N=xin.size();
113 int const sendcount = N/numprocs;
114 assert(sendcount*numprocs==N);
116 auto sendbuf = xin.data();
117 ierr = MPI_Alltoall(MPI_IN_PLACE, sendcount, MPI_DOUBLE,
118 sendbuf, sendcount, MPI_DOUBLE, icomm);