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());
47 for (
size_t k = 0; k < n; ++k)
69 bool CompareVectors(std::vector<double>
const& x,
int const n,
double const y[],
double const eps)
71 bool bn = (
static_cast<int>(x.size())==n);
74 cout <<
"######### Error: " <<
"number of elements" << endl;
77 bool bv = equal(x.cbegin(),x.cend(),y,
78 [eps](
double a,
double b) ->
bool
79 { return std::abs(a-b)<eps*(1.0+0.5*(std::abs(a)+ std::abs(a))); }
83 assert(
static_cast<int>(x.size())==n);
84 cout <<
"######### Error: " <<
"values" << endl;
90 double par_scalar(vector<double>
const &x, vector<double>
const &y, MPI_Comm
const& icomm)
92 const double s =
dscapr(x,y);
94 MPI_Allreduce(&s,&sg,1,MPI_DOUBLE,MPI_SUM,icomm);
100 void ExchangeAll(vector<double>
const &xin, vector<double> &yout, MPI_Comm
const &icomm)
102 int myrank, numprocs,ierr(-1);
103 MPI_Comm_rank(icomm, &myrank);
104 MPI_Comm_size(icomm, &numprocs);
105 int const N=xin.size();
106 int const sendcount = N/numprocs;
107 assert(sendcount*numprocs==N);
108 assert(xin.size()==yout.size());
110 auto sendbuf = xin.data();
111 auto recvbuf = yout.data();
112 ierr = MPI_Alltoall(sendbuf, sendcount, MPI_DOUBLE,
113 recvbuf, sendcount, MPI_DOUBLE, icomm);
122 int myrank, numprocs,ierr(-1);
123 MPI_Comm_rank(icomm, &myrank);
124 MPI_Comm_size(icomm, &numprocs);
125 int const N=xin.size();
126 int const sendcount = N/numprocs;
127 assert(sendcount*numprocs==N);
129 auto sendbuf = xin.data();
130 ierr = MPI_Alltoall(MPI_IN_PLACE, sendcount, MPI_DOUBLE,
131 sendbuf, sendcount, MPI_DOUBLE, icomm);