Commit d1a483c6 authored by sfritschi's avatar sfritschi
Browse files

Minor changes to debugging build

parent dc908316
...@@ -3,8 +3,7 @@ import sys ...@@ -3,8 +3,7 @@ import sys
import numpy as np import numpy as np
from scipy.sparse import csr_matrix from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve
import pyamg
comm = MPI.COMM_WORLD comm = MPI.COMM_WORLD
rank = comm.Get_rank() rank = comm.Get_rank()
...@@ -18,13 +17,13 @@ except ImportError: ...@@ -18,13 +17,13 @@ except ImportError:
def main(): def main():
np.random.seed(42) np.random.seed(42)
n = 50 n = 10
""" """
data = [1.0, 6.0, 3.0, -1.0, 5.0, 6.0, 7.0] data = [1.0, 6.0, 3.0, -1.0, 5.0, 6.0, 7.0]
row = [0, 1, 1, 2, 3, 4, 5] row = [0, 1, 1, 2, 3, 4, 5]
col = [4, 2, 3, 2, 0, 1, 5] col = [4, 2, 3, 2, 0, 1, 5]
""" """
data = np.random.uniform(-1., 1., 2*n) data = np.random.randint(1, 4, 2*n)
row = np.arange(n) row = np.arange(n)
np.random.shuffle(row) np.random.shuffle(row)
...@@ -35,7 +34,7 @@ def main(): ...@@ -35,7 +34,7 @@ def main():
temp = np.arange(n) temp = np.arange(n)
row = np.hstack((row, temp)) row = np.hstack((row, temp))
col = np.hstack((col, temp)) col = np.hstack((col, temp))
A = csr_matrix((data, (row, col)), shape=(n, n)) A = csr_matrix((data, (row, col)), shape=(n, n))
b = np.arange(n, dtype=np.float64) b = np.arange(n, dtype=np.float64)
...@@ -46,8 +45,7 @@ def main(): ...@@ -46,8 +45,7 @@ def main():
if (rank == 0): if (rank == 0):
print("#nnz: %d" % A.data.shape[0]) print("#nnz: %d" % A.data.shape[0])
ml = pyamg.ruge_stuben_solver(A) # construct multigrid hierarchy x_ = spsolve(A, b)
x_ = ml.solve(b, tol=tol, maxiter=maxiter, cycle='W')
print("Error norm: %e" % np.linalg.norm(x - x_)) print("Error norm: %e" % np.linalg.norm(x - x_))
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -23,7 +23,8 @@ if shutil.which(mpi) == None: ...@@ -23,7 +23,8 @@ if shutil.which(mpi) == None:
sys.exit(1) sys.exit(1)
compile_args = [] compile_args = []
compile_args += ["-O3"] # Release if "--debug" not in sys.argv:
compile_args += ["-O3"] # Release
compile_args += ["-std=c99"] # For variable declarations in loop compile_args += ["-std=c99"] # For variable declarations in loop
compile_args += os.popen(mpi + " --showme:compile").read().strip().split(" ") compile_args += os.popen(mpi + " --showme:compile").read().strip().split(" ")
compile_args += ["-I" + PETSC_DIR + "/include"] compile_args += ["-I" + PETSC_DIR + "/include"]
......
...@@ -92,7 +92,8 @@ PetscErrorCode solve(const PetscScalar *data, const PetscInt *col_indices, ...@@ -92,7 +92,8 @@ PetscErrorCode solve(const PetscScalar *data, const PetscInt *col_indices,
ierr = KSPGetPC(ksp, &pc); CHKERRQ(ierr); ierr = KSPGetPC(ksp, &pc); CHKERRQ(ierr);
ierr = PCSetType(pc, PCHYPRE); CHKERRQ(ierr); ierr = PCSetType(pc, PCHYPRE); CHKERRQ(ierr);
ierr = PCHYPRESetType(pc, "boomeramg"); CHKERRQ(ierr); ierr = PCHYPRESetType(pc, "boomeramg"); CHKERRQ(ierr);
ierr = KSPSetTolerances(ksp, rtol, PETSC_DEFAULT, PETSC_DEFAULT, maxiter); CHKERRQ(ierr); ierr = KSPSetTolerances(ksp, rtol, PETSC_DEFAULT, PETSC_DEFAULT, maxiter);
CHKERRQ(ierr);
ierr = PCSetFromOptions(pc); CHKERRQ(ierr); ierr = PCSetFromOptions(pc); CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr); ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);
...@@ -109,6 +110,7 @@ PetscErrorCode solve(const PetscScalar *data, const PetscInt *col_indices, ...@@ -109,6 +110,7 @@ PetscErrorCode solve(const PetscScalar *data, const PetscInt *col_indices,
const char *convergence_reason; const char *convergence_reason;
ierr = KSPGetConvergedReasonString(ksp, &convergence_reason); CHKERRQ(ierr); ierr = KSPGetConvergedReasonString(ksp, &convergence_reason); CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD, "Reason: %s\n", convergence_reason); PetscPrintf(PETSC_COMM_WORLD, "Reason: %s\n", convergence_reason);
ierr = KSPView(ksp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr);
} }
// Displacements in global array (inscan of n_locals array) // Displacements in global array (inscan of n_locals array)
PetscMPIInt *displs = NULL; PetscMPIInt *displs = NULL;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment