Last active
April 5, 2023 14:36
-
-
Save ddemidov/02800e856192b289d80e to your computer and use it in GitHub Desktop.
PyAMG vs AMGCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PyAMG | |
---------------- | |
multilevel_solver | |
Number of Levels: 5 | |
Operator Complexity: 1.338 | |
Grid Complexity: 1.188 | |
Coarse Solver: 'pinv2' | |
level unknowns nonzeros | |
0 1048576 5238784 [74.73%] | |
1 175104 1572176 [22.43%] | |
2 19537 175673 [ 2.51%] | |
3 2154 21246 [ 0.30%] | |
4 219 2365 [ 0.03%] | |
residual norm is 8.29613125832e-07 | |
setup: 4.93 sec | |
solve: 2.83 sec | |
AMGCL | |
---------------- | |
Number of levels: 4 | |
Operator complexity: 1.34 | |
Grid complexity: 1.19 | |
level unknowns nonzeros | |
--------------------------------- | |
0 1048576 5238784 (74.75%) | |
1 175104 1572176 (22.43%) | |
2 19579 175863 ( 2.51%) | |
3 2259 21465 ( 0.31%) | |
residual norm is 1.92973750974e-06 | |
setup: 0.47 sec | |
solve: 1.05 sec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import numpy as np | |
from scipy import * | |
from scipy.linalg import * | |
from scipy.sparse.linalg import cg | |
from pyamg import * | |
from pyamg.gallery import * | |
import pyamgcl as amg | |
from time import time | |
A = poisson((1024,1024), format='csr') | |
b = rand(A.shape[0]) # pick a random right hand side | |
print "PyAMG" | |
print "----------------\n" | |
tic = time() | |
ml = smoothed_aggregation_solver(A) | |
tm_setup = time() - tic | |
print ml | |
tic = time() | |
x,info = cg(A, b, tol=1e-8, M=ml.aspreconditioner(cycle='V')) | |
tm_solve = time() - tic | |
print "residual norm is", norm(b - A*x) | |
print "setup: %.2f sec" % tm_setup | |
print "solve: %.2f sec" % tm_solve | |
print "\nAMGCL" | |
print "----------------\n" | |
tic = time() | |
solve = amg.make_solver(A, solver=amg.solver_type.cg, prm={"tol" : 1e-8}) | |
tm_setup = time() - tic | |
print solve | |
tic = time() | |
x = solve(b) | |
tm_solve = time() - tic | |
print "residual norm is", norm(b - A*x) | |
print "setup: %.2f sec" % tm_setup | |
print "solve: %.2f sec" % tm_solve |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment