Skip to content

Commit

Permalink
add a reduction for double&
Browse files Browse the repository at this point in the history
  • Loading branch information
michel2323 committed Sep 17, 2018
1 parent 1a42c52 commit d65f2fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/plorenz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main(int argc, char* argv[]) {

double diff = (H - H_fd).norm();
diff = diff*diff;
MPI_Allreduce(MPI_IN_PLACE, &diff, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
paduprop_sum(diff);
cout << "norm(H - H_fd)" << endl << sqrt(diff) << endl;
if(diff > 1e-4) {
cerr << "ERROR: HC and AD Hessian differ." << endl;
Expand All @@ -151,7 +151,7 @@ int main(int argc, char* argv[]) {
drivers.fdT_driver(x, T_fd, start, end);
double diff = (T - T_fd).norm();
diff = diff*diff;
MPI_Allreduce(MPI_IN_PLACE, &diff, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
paduprop_sum(diff);
cout << "norm(T - T_fd)" << endl << sqrt(diff) << endl;
if(diff > 1e-5) {
cerr << "ERROR: HC and AD tensor differ." << endl;
Expand Down
1 change: 1 addition & 0 deletions include/parallel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ size_t paduprop_getend(size_t dim);

int paduprop_getrank();
int paduprop_getcommsize();
int paduprop_sum(double&);
int paduprop_sum(pMatrix<double>&);
int paduprop_sum(pVector<double> &vec);
int paduprop_gather(pTensor3<double> &ten);
Expand Down
7 changes: 7 additions & 0 deletions src/parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ int paduprop_getcommsize() {
#endif
return size;
}
int paduprop_sum(double &v) {
int ierr = 0;
#ifdef MPI_VERSION
ierr = MPI_Allreduce(MPI_IN_PLACE, &v, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
#endif
return ierr;
}
int paduprop_sum(pMatrix<double> &mat) {
size_t nrows = mat.nrows();
size_t ncols = mat.ncols();
Expand Down

0 comments on commit d65f2fa

Please sign in to comment.