Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
cgcgcg committed Jul 12, 2024
1 parent 858baa8 commit 6913e89
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:

- name: Run tests
if: always()
run: python3 -m pytest --junit-xml=test-results-${{ env.BUILD_IDENTIFIER }}.xml tests/
run: python3 -m pytest --junit-xml=test-results-${{ env.BUILD_IDENTIFIER }}.xml -k "testParallelGMG[4-interval-P3-False]" tests/

- name: Run flake8
if: always()
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ list-tests:

.PHONY: tests
tests:
$(PYTHON) -m pytest -rA --html=$(TEST_RESULTS) --self-contained-html tests/
# $(PYTHON) -m pytest -rA --html=$(TEST_RESULTS) --self-contained-html tests/
$(PYTHON) -m pytest -rA --html=$(TEST_RESULTS) -k "testParallelGMG[4-interval-P3-False]" --self-contained-html tests/

prereq:
$(PYTHON) -m pip install $(PIP_FLAGS) $(PIP_INSTALL_FLAGS) setuptools wheel Cython cython numpy scipy matplotlib pyyaml h5py pybind11 MeshPy tabulate modepy mpi4py pyamg meshio
Expand Down
6 changes: 6 additions & 0 deletions base/PyNucleus_base/solvers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ cdef class lu_solver(solver):
perm_r = self.perm_r
perm_c = self.perm_c
try:
print('lu1 pre', np.linalg.norm(np.asarray(b)))
temp = self.temp_mem
n = perm_c.shape[0]
for i in range(n):
Expand All @@ -166,14 +167,19 @@ cdef class lu_solver(solver):
backward_solve_csc(self.U.indptr, self.U.indices, self.U.data, x, temp)
for i in range(n):
x[i] = temp[perm_c[i]]
print('lu1 post', np.linalg.norm(np.asarray(x)))
except AttributeError:
print('lu2 pre', np.linalg.norm(np.asarray(b)))
x[:] = self.Ainv.solve(np.array(b, copy=False, dtype=REAL))
print('lu2 post', np.linalg.norm(np.asarray(x)))
else:
from scipy.linalg import lu_solve
print('lu3 pre', np.linalg.norm(np.asarray(b)))
assign(x, b)
lu_solve((self.lu, self.perm),
np.array(x, copy=False, dtype=REAL),
overwrite_b=True)
print('lu3 post', np.linalg.norm(np.asarray(x)))
return 1

def __str__(self):
Expand Down
6 changes: 6 additions & 0 deletions drivers/runParallelGMG.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
for cycle, label in [(V, 'MG'),
(FMG_V, 'FMG')]:
if getattr(d, 'do'+label):
assert np.all(np.isfinite(rhs.toarray())), rhs.toarray()
ml.cycle = cycle
with d.timer('Solve '+label):
numIter = ml(rhs, x)
Expand All @@ -176,6 +177,7 @@
its.add('Number of iterations '+label, numIter)
res.add('Residual norm '+label, resNorm)
resHist.add(label, residuals)
print(label, r0, residuals, numIter, resNorm)

# set up cg
cg = solverFactory.build('cg', A=A, maxIter=d.maxiter, tolerance=tol, setup=True)
Expand All @@ -192,6 +194,7 @@
(gmres, 'GMRES'),
(bicgstab, 'BICGSTAB')]:
if getattr(d, 'do'+label):
assert np.all(np.isfinite(rhs.toarray())), rhs.toarray()
solver.setPreconditioner(acc)
solver.setInitialGuess()
with d.timer('Solve '+label):
Expand All @@ -203,14 +206,17 @@
its.add('Number of iterations '+label, numIter)
res.add('Residual norm '+label, resNorm)
resHist.add(label, residuals)
print(label, r0, residuals, numIter, resNorm)
if getattr(d, 'doP'+label):
assert np.all(np.isfinite(rhs.toarray())), rhs.toarray()
solver.setPreconditioner(ml.asPreconditioner(cycle=V), False)
solver.setInitialGuess()
with d.timer('Solve P'+label):
numIter = solver(rhs, x)
residuals = solver.residuals
A.residual_py(x, rhs, r)
resNorm = r.norm(False)
print(label, r0, residuals, numIter, resNorm)
rate.add('Rate of convergence P'+label, (resNorm/r0)**(1/numIter), tested=False if label == 'BICGSTAB' else None)
its.add('Number of iterations P'+label, numIter, aTol=2 if label == 'BICGSTAB' else None)
res.add('Residual norm P'+label, resNorm)
Expand Down
2 changes: 2 additions & 0 deletions fem/PyNucleus_fem/algebraicOverlaps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ cdef class algebraicOverlapManager:
algebraicOverlapOneSidedGet ov1S
algebraicOverlapOneSidedPut ov1SP
algebraicOverlapOneSidedPutLockAll ov1SPLA
print('pre-receive', self.comm.rank, np.linalg.norm(np.asarray(return_vec)))
requestsOneSidedGet = []
requestsOneSidedPut = []
requestsOneSidedPutLockAll = []
Expand Down Expand Up @@ -1215,6 +1216,7 @@ cdef class algebraicOverlapManager:
ov1SPLA = self.overlaps[subdomainNo]
ov1SPLA.receive(return_vec, vecNo=vecNo, flushOp=flushOp)
ov1SPLA.accumulateProcess(return_vec, vecNo=vecNo)
print('post-receive', self.comm.rank, np.linalg.norm(np.asarray(return_vec)))
if setBarrier:
self.comm.Barrier()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ cdef class {SCALAR_label}coarseSolver({SCALAR_label_lc_}iterative_solver):
cdef BOOL_t solve_cg(self):
self.rhs[:] = 0.
self.overlapsCoarse.receive{SCALAR_label}(self.rhs)
print('receive rhs', np.linalg.norm(np.asarray(self.rhs)))
if self.intraLevelCoarse is not None:
self.intraLevelCoarse.distribute{SCALAR_label}(self.rhs)
with self.PLogger.Timer('solveTimeLocal'):
Expand All @@ -134,11 +135,13 @@ cdef class {SCALAR_label}coarseSolver({SCALAR_label_lc_}iterative_solver):
if (self.overlapsFine is not None) or (b.shape[0] != self.Ainv.num_rows):
with self.PLogger.Timer('solveTime'):
if self.inSubdomain and self.canWriteRHS():
print('send rhs', np.linalg.norm(np.asarray(b)))
self.sendRHS(b)
if self.inCG:
ret = self.solve_cg()
if self.inSubdomain:
self.getSolution(x)
print('send solution', np.linalg.norm(np.asarray(x)))
else:
with self.PLogger.Timer('solveTime'):
if isinstance(self.Ainv, {SCALAR_label_lc_}iterative_solver):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ cdef class {SCALAR_label}multigrid({SCALAR_label_lc_}iterative_solver):
str label = str(lvlNo)
FakeTimer Timer = self.PLogger.Timer(label, manualDataEntry=True)
{SCALAR_label}levelMemory lvl, lvlCoarse
print('RHS on ', lvlNo, 'rank', self.overlap.comm.rank, np.linalg.norm(np.asarray(b)))
print('X pre on ', lvlNo, 'rank', self.overlap.comm.rank, np.linalg.norm(np.asarray(x)))
if lvlNo == 0:
Timer.start()
if isinstance(self.coarse_solver, {SCALAR_label_lc_}iterative_solver):
Expand Down Expand Up @@ -289,6 +291,7 @@ cdef class {SCALAR_label}multigrid({SCALAR_label_lc_}iterative_solver):
lvl.smoother.eval(b, x, postsmoother=True)
Timer.end()
Timer.enterData()
print('X post on ', lvlNo, 'rank', self.overlap.comm.rank, np.linalg.norm(np.asarray(x)))

def asPreconditioner(self, INDEX_t maxIter=1, CycleType cycle=V):
return {SCALAR_label}multigridPreconditioner(self, cycle, maxIter)
Expand Down

0 comments on commit 6913e89

Please sign in to comment.