jacobi.template
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 
15 void vddiv(std::vector<double> &x, std::vector<double> const &y,
16  std::vector<double> const &z);
17 
26 void vdaxpy(std::vector<double> &x, std::vector<double> const &y,
27  double alpha, std::vector<double> const &z );
28 
29 
37 double dscapr(std::vector<double> const &x, std::vector<double> const &y);
38 
39 
40 inline
41 double L2_scapr(std::vector<double> const &x, std::vector<double> const &y)
42 {
43  return dscapr(x, y) / x.size();
44 }
45 
46 
53 double 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 */
59 inline
60 int 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 template <class T>
85 void DebugVector(std::vector<T> const &v, std::string const &ss = std::string(), MPI_Comm const &icomm = MPI_COMM_WORLD)
86 {
87  MPI_Barrier(icomm);
88  std::cout.flush();
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 << "[" << j << "] "<< v[j] << " ";
103  }
104  std::cout << std::endl;
105  std::cout.flush();
106  }
107 
108  readid = ReadIn(ss, icomm); /* Read readid */
109  }
110  MPI_Barrier(icomm);
111  return;
112 }
113 
127 bool CompareVectors(std::vector<double> const &x, int n, double const y[], double const eps = 0.0);
128 
129 
136 template <class T>
137 std::ostream& operator<<(std::ostream &s, std::vector<T> const &v)
138 {
139  for (auto vp: v)
140  {
141  s << vp << " ";
142  }
143  return s;
144 }
145 
154 void ExchangeAll(std::vector<double> const &xin, std::vector<double> &yout, MPI_Comm const &icomm = MPI_COMM_WORLD);
155 
163 void ExchangeAllInPlace(std::vector<double> &xin, MPI_Comm const &icomm = MPI_COMM_WORLD);
164 
165 
166 
167 #endif
vddiv
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.
CompareVectors
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:56
DebugVector
void DebugVector(std::vector< T > const &v, std::string const &ss=std::string(), MPI_Comm const &icomm=MPI_COMM_WORLD)
Definition: vdop.h:85
v
v
Definition: ascii_read_meshvector.m:40
vdaxpy
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
operator<<
std::ostream & operator<<(std::ostream &s, std::vector< T > const &v)
Definition: vdop.h:137
ExchangeAllInPlace
void ExchangeAllInPlace(std::vector< double > &xin, MPI_Comm const &icomm=MPI_COMM_WORLD)
ReadIn
int ReadIn(std::string const &ss=std::string(), MPI_Comm const &icomm=MPI_COMM_WORLD)
Definition: vdop.h:60
L2_scapr
double L2_scapr(std::vector< double > const &x, std::vector< double > const &y)
Definition: vdop.h:41
par_scalar
double par_scalar(std::vector< double > const &x, std::vector< double > const &y, MPI_Comm const &icomm=MPI_COMM_WORLD)
dscapr
double dscapr(std::vector< double > const &x, std::vector< double > const &y)
Calculates the Euclidean inner product of two vectors.
Definition: vdop.cpp:40
ExchangeAll
void ExchangeAll(std::vector< double > const &xin, std::vector< double > &yout, MPI_Comm const &icomm=MPI_COMM_WORLD)