accu.template
Loading...
Searching...
No Matches
vdop.h
Go to the documentation of this file.
1#ifndef VDOP_FILE
2#define VDOP_FILE
3#include <iostream>
4#include <mpi.h> // MPI
5#include <string>
6#include <vector>
7
15void vddiv(std::vector<double> &x, std::vector<double> const &y,
16 std::vector<double> const &z);
17
26void vdaxpy(std::vector<double> &x, std::vector<double> const &y,
27 double alpha, std::vector<double> const &z );
28
29
37double dscapr(std::vector<double> const &x, std::vector<double> const &y);
38
39
40inline
41double L2_scapr(std::vector<double> const &x, std::vector<double> const &y)
42{
43 return dscapr(x, y) / x.size();
44}
45
46
53double par_scalar(std::vector<double> const &x, std::vector<double> const &y,
54 MPI_Comm const& icomm=MPI_COMM_WORLD);
55
56
57
58/* ReadId : Input and broadcast of an integer */
59inline
60int ReadIn(std::string const &ss = std::string(), MPI_Comm const &icomm = MPI_COMM_WORLD)
61{
62 MPI_Barrier(icomm);
63 int myrank; /* my rank number */
64 MPI_Comm_rank(icomm, &myrank);
65 int id;
66
67 if (myrank == 0) {
68 std::cout << "\n\n " << ss << " : Which process do you want to debug ? \n";
69 std::cin >> id;
70 }
71 MPI_Bcast(&id, 1, MPI_INT, 0, icomm);
72
73 return id;
74}
75
84//void DebugVector(std::vector<double> const &v);
85template <class T>
86void DebugVector(std::vector<T> const &v, std::string const &ss = std::string(), MPI_Comm const &icomm = MPI_COMM_WORLD)
87{
88 MPI_Barrier(icomm);
89 int numprocs; /* # processes */
90 MPI_Comm_size(icomm, &numprocs);
91 int myrank; /* my rank number */
92 MPI_Comm_rank(icomm, &myrank);
93
94 int readid = ReadIn(ss); /* Read readid */
95
96 while ( (0 <= readid) && (readid < numprocs) ) {
97 if (myrank == readid) {
98 std::cout << "\n\n process " << readid;
99 std::cout << "\n .... " << ss << " (nnode = " << v.size() << ")\n";
100 for (size_t j = 0; j < v.size(); ++j) {
101 std::cout.setf(std::ios::right, std::ios::adjustfield);
102 std::cout << v[j] << " ";
103 }
104 std::cout << std::endl;
105 fflush(stdout);
106 }
107
108 readid = ReadIn(ss, icomm); /* Read readid */
109 }
110 MPI_Barrier(icomm);
111 return;
112}
113
127bool CompareVectors(std::vector<double> const &x, int n, double const y[], double const eps = 0.0);
128
129
136template <class T>
137std::ostream &operator<<(std::ostream &s, std::vector<T> const &v)
138{
139 for (auto vp : v) {
140 s << vp << " ";
141 }
142 return s;
143}
144
153void ExchangeAll(std::vector<double> const &xin, std::vector<double> &yout, MPI_Comm const &icomm = MPI_COMM_WORLD);
154
162void ExchangeAllInPlace(std::vector<double> &xin, MPI_Comm const &icomm = MPI_COMM_WORLD);
163
164
165
166#endif
void ExchangeAll(std::vector< double > const &xin, std::vector< double > &yout, MPI_Comm const &icomm=MPI_COMM_WORLD)
double L2_scapr(std::vector< double > const &x, std::vector< double > const &y)
Definition vdop.h:41
void DebugVector(std::vector< T > const &v, std::string const &ss=std::string(), MPI_Comm const &icomm=MPI_COMM_WORLD)
Definition vdop.h:86
int ReadIn(std::string const &ss=std::string(), MPI_Comm const &icomm=MPI_COMM_WORLD)
Definition vdop.h:60
void vdaxpy(std::vector< double > &x, std::vector< double > const &y, double alpha, std::vector< double > const &z)
Element-wise daxpy operation x(k) = y(k) + alpha*z(k).
Definition vdop.cpp:25
void vddiv(std::vector< double > &x, std::vector< double > const &y, std::vector< double > const &z)
Element-wise vector divison x_k = y_k/z_k.
double par_scalar(std::vector< double > const &x, std::vector< double > const &y, MPI_Comm const &icomm=MPI_COMM_WORLD)
double dscapr(std::vector< double > const &x, std::vector< double > const &y)
Calculates the Euclidean inner product of two vectors.
Definition vdop.cpp:40
bool CompareVectors(std::vector< double > const &x, int n, double const y[], double const eps=0.0)
Compares an STL vector with POD vector.
Definition vdop.cpp:69
void ExchangeAllInPlace(std::vector< double > &xin, MPI_Comm const &icomm=MPI_COMM_WORLD)
std::ostream & operator<<(std::ostream &s, std::vector< T > const &v)
Definition vdop.h:137