Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel cyclic reduction #2330

Merged
merged 45 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c6b0eae
Initial inclusion of PCR solver
JosephThomasParker May 12, 2021
a503dc5
Tidy source and header
JosephThomasParker May 12, 2021
25d0cd9
Update buffers to Arrays
JosephThomasParker May 13, 2021
1dc9972
Change auto to Array
JosephThomasParker May 13, 2021
d6d202a
Change MPI_Request buffers to Arrays
JosephThomasParker May 13, 2021
70007e4
Merge remote-tracking branch 'origin/cmake-coverage-sanitizers' into …
JosephThomasParker May 13, 2021
bb32b8b
Working version with same structure a cyclic laplace
JosephThomasParker May 14, 2021
05796e3
Add solution verify routine to PCR
JosephThomasParker May 15, 2021
324db57
Add solution verify routine to cyclic laplace
JosephThomasParker May 15, 2021
115707a
Working for zero bcs
JosephThomasParker May 19, 2021
eafd6ae
Swap API for eliminate_boundary_rows interface
JosephThomasParker May 19, 2021
3bac821
Add r modification in eliminate bdy rows
JosephThomasParker May 19, 2021
4244689
Make pcr solver interface take a b c in expected order
JosephThomasParker May 19, 2021
7df08d0
Give a b c correct meaning inside pcr_solve function
JosephThomasParker May 19, 2021
85c202c
Give correct meaning to a b c in eliminate_boundary_rows
JosephThomasParker May 19, 2021
6f5dceb
Add correct r operation to eliminate boundary rows
JosephThomasParker May 19, 2021
a267d8d
Make input to eliminate_boundary_rows const as appropriate
JosephThomasParker May 19, 2021
cdf8d27
Remove unnecessary b copy
JosephThomasParker May 19, 2021
01df955
Tidy and remove diagnostic writes
JosephThomasParker May 19, 2021
c3f22c0
Tidy and remove unused variables
JosephThomasParker May 19, 2021
f635c1f
Remove diagnostic writes
JosephThomasParker May 19, 2021
895989f
Merge branch 'next' into pcr_cyclic_copy+asan
JosephThomasParker May 19, 2021
f3fc1a7
Add information on PCR library
JosephThomasParker May 19, 2021
4a1003a
Remove NXPE==1 requirement
JosephThomasParker May 19, 2021
144b991
Use GlobalNxNoBoundaries variable
JosephThomasParker May 19, 2021
f59ec6f
Tidy int declaration
JosephThomasParker May 19, 2021
d59ff25
Use std::max instead of iff
JosephThomasParker May 19, 2021
337c57b
Use std::max instead of iff
JosephThomasParker May 19, 2021
de45ee8
Run clang tidy
JosephThomasParker May 19, 2021
794d9e9
Tidy comment
JosephThomasParker May 19, 2021
a26e415
Use GlobalNxNoBoundaries
JosephThomasParker May 19, 2021
4450965
Inline the setup function
JosephThomasParker May 19, 2021
9a6f144
Allow NYPE != 1
JosephThomasParker May 20, 2021
400d0e9
clang format
JosephThomasParker May 20, 2021
f622b97
Add PCR case to the test-laplace integrated test
JosephThomasParker May 20, 2021
30b93e4
Remove const int input
JosephThomasParker May 20, 2021
888ea14
Keep const in cxx
JosephThomasParker May 20, 2021
f5a4ce4
Fix use of reserved identifier for header guard
ZedThree May 21, 2021
d9b5f57
Fix some clang-tidy warnings
ZedThree May 21, 2021
0edf17d
Reduce scope of some local variables and immediately initialise them
ZedThree May 21, 2021
2e066d7
Make some LaplacePCR methods const
ZedThree May 21, 2021
e737ff5
Use override on overridden virtual functions
ZedThree May 21, 2021
3d5d949
Fix clang-tidy warning about uninitialised members
ZedThree May 21, 2021
f9c648e
Remove some unused private members
ZedThree May 21, 2021
f24aa25
Delete some commented out code
ZedThree May 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ set(BOUT_SOURCES
./src/invert/laplace/impls/multigrid/multigrid_solver.cxx
./src/invert/laplace/impls/naulin/naulin_laplace.cxx
./src/invert/laplace/impls/naulin/naulin_laplace.hxx
./src/invert/laplace/impls/pcr/pcr.cxx
./src/invert/laplace/impls/pcr/pcr.hxx
./src/invert/laplace/impls/pdd/pdd.cxx
./src/invert/laplace/impls/pdd/pdd.hxx
./src/invert/laplace/impls/petsc/petsc_laplace.cxx
Expand Down
1 change: 1 addition & 0 deletions include/invert_laplace.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ constexpr auto LAPLACE_CYCLIC = "cyclic";
constexpr auto LAPLACE_MULTIGRID = "multigrid";
constexpr auto LAPLACE_NAULIN = "naulin";
constexpr auto LAPLACE_IPT = "ipt";
constexpr auto LAPLACE_PCR = "pcr";

// Inversion flags for each boundary
/// Zero-gradient for DC (constant in Z) component. Default is zero value
Expand Down
83 changes: 83 additions & 0 deletions src/invert/laplace/impls/cyclic/cyclic_laplace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ Field3D LaplaceCyclic::solve(const Field3D& rhs, const Field3D& x0) {
// Solve tridiagonal systems
cr->setCoefs(a3D, b3D, c3D);
cr->solve(bcmplx3D, xcmplx3D);
// verify_solution(a3D,b3D,c3D,bcmplx3D,xcmplx3D,nsys);

// FFT back to real space
BOUT_OMP(parallel) {
Expand Down Expand Up @@ -476,3 +477,85 @@ Field3D LaplaceCyclic::solve(const Field3D& rhs, const Field3D& x0) {

return x;
}

void LaplaceCyclic ::verify_solution(const Matrix<dcomplex>& a_ver,
const Matrix<dcomplex>& b_ver,
const Matrix<dcomplex>& c_ver,
const Matrix<dcomplex>& r_ver,
const Matrix<dcomplex>& x_sol, const int nsys) {
output.write("Verify solution\n");
const int nx = xe - xs + 1; // Number of X points on this processor,
// including boundaries but not guard cells
const int xproc = localmesh->getXProcIndex();
const int yproc = localmesh->getYProcIndex();
const int nprocs = localmesh->getNXPE();
const int myrank = yproc * nprocs + xproc;
Matrix<dcomplex> y_ver(nsys, nx + 2);
Matrix<dcomplex> error(nsys, nx + 2);

MPI_Status status;
Array<MPI_Request> request(4);
Array<dcomplex> sbufup(nsys);
Array<dcomplex> sbufdown(nsys);
Array<dcomplex> rbufup(nsys);
Array<dcomplex> rbufdown(nsys);

// nsys = nmode * ny; // Number of systems of equations to solve
Matrix<dcomplex> x_ver(nsys, nx + 2);

for (int kz = 0; kz < nsys; kz++) {
for (int ix = 0; ix < nx; ix++) {
x_ver(kz, ix + 1) = x_sol(kz, ix);
}
}

if (xproc > 0) {
MPI_Irecv(&rbufdown[0], nsys, MPI_DOUBLE_COMPLEX, myrank - 1, 901, MPI_COMM_WORLD,
&request[1]);
for (int kz = 0; kz < nsys; kz++) {
sbufdown[kz] = x_ver(kz, 1);
}
MPI_Isend(&sbufdown[0], nsys, MPI_DOUBLE_COMPLEX, myrank - 1, 900, MPI_COMM_WORLD,
&request[0]);
}
if (xproc < nprocs - 1) {
MPI_Irecv(&rbufup[0], nsys, MPI_DOUBLE_COMPLEX, myrank + 1, 900, MPI_COMM_WORLD,
&request[3]);
for (int kz = 0; kz < nsys; kz++) {
sbufup[kz] = x_ver(kz, nx);
}
MPI_Isend(&sbufup[0], nsys, MPI_DOUBLE_COMPLEX, myrank + 1, 901, MPI_COMM_WORLD,
&request[2]);
}

if (xproc > 0) {
MPI_Wait(&request[0], &status);
MPI_Wait(&request[1], &status);
for (int kz = 0; kz < nsys; kz++) {
x_ver(kz, 0) = rbufdown[kz];
}
}
if (xproc < nprocs - 1) {
MPI_Wait(&request[2], &status);
MPI_Wait(&request[3], &status);
for (int kz = 0; kz < nsys; kz++) {
x_ver(kz, nx + 1) = rbufup[kz];
}
}

BoutReal max_error = 0.0;
for (int kz = 0; kz < nsys; kz++) {
for (int i = 0; i < nx; i++) {
y_ver(kz, i) = a_ver(kz, i) * x_ver(kz, i) + b_ver(kz, i) * x_ver(kz, i + 1)
+ c_ver(kz, i) * x_ver(kz, i + 2);
error(kz, i) = y_ver(kz, i) - r_ver(kz, i);
max_error = std::max(max_error, std::abs(error(kz, i)));
output.write("abs error {}, r={}, y={}, kz {}, i {}, a={}, b={}, c={}, x-= {}, "
"x={}, x+ = {}\n",
error(kz, i).real(), r_ver(kz, i).real(), y_ver(kz, i).real(), kz, i,
a_ver(kz, i).real(), b_ver(kz, i).real(), c_ver(kz, i).real(),
x_ver(kz, i).real(), x_ver(kz, i + 1).real(), x_ver(kz, i + 2).real());
}
}
output.write("max abs error {}\n", max_error);
}
4 changes: 4 additions & 0 deletions src/invert/laplace/impls/cyclic/cyclic_laplace.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public:

Field3D solve(const Field3D &b) override {return solve(b,b);}
Field3D solve(const Field3D &b, const Field3D &x0) override;
void verify_solution(const Matrix<dcomplex>& a_ver, const Matrix<dcomplex>& b_ver,
const Matrix<dcomplex>& c_ver, const Matrix<dcomplex>& r_ver,
const Matrix<dcomplex>& x_sol, const int nsys);
ZedThree marked this conversation as resolved.
Show resolved Hide resolved

private:
Field2D Acoef, C1coef, C2coef, Dcoef;

Expand Down
2 changes: 1 addition & 1 deletion src/invert/laplace/impls/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

BOUT_TOP = ../../../..

DIRS = serial_tri serial_band pdd spt petsc cyclic multigrid naulin petsc3damg iterative_parallel_tri
DIRS = serial_tri serial_band pdd spt petsc cyclic multigrid naulin petsc3damg iterative_parallel_tri pcr

include $(BOUT_TOP)/make.config
8 changes: 8 additions & 0 deletions src/invert/laplace/impls/pcr/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

BOUT_TOP = ../../../../..

SOURCEC = pcr.cxx
SOURCEH = pcr.hxx
TARGET = lib

include $(BOUT_TOP)/make.config
Loading