def PMIS(S): """C/F splitting using the Parallel Modified Independent Set method Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) Returns ------- splitting : ndarray Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical import PMIS >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = PMIS(S) See Also -------- MIS References ---------- .. [1] Hans De Sterck, Ulrike M Yang, and Jeffrey J Heys "Reducing complexity in parallel algebraic multigrid preconditioners" SIAM Journal on Matrix Analysis and Applications 2006; 27:1019-1039. """ S = remove_diagonal(S) weights, G, S, T = preprocess(S) return MIS(G, weights)
def RS(S, second_pass=False): """Compute a C/F splitting using Ruge-Stuben coarsening Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) second_pass : bool, default False Perform second pass of classical AMG coarsening. Can be important for classical AMG interpolation. Typically not done in parallel (e.g. Hypre). Returns ------- splitting : ndarray Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical import RS >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = RS(S) See Also -------- amg_core.rs_cf_splitting References ---------- .. [1] Ruge JW, Stuben K. "Algebraic multigrid (AMG)" In Multigrid Methods, McCormick SF (ed.), Frontiers in Applied Mathematics, vol. 3. SIAM: Philadelphia, PA, 1987; 73-130. """ if not isspmatrix_csr(S): raise TypeError('expected csr_matrix') S = remove_diagonal(S) T = S.T.tocsr() # transpose S for efficient column access splitting = np.empty(S.shape[0], dtype='intc') influence = np.zeros((S.shape[0],), dtype='intc') amg_core.rs_cf_splitting(S.shape[0], S.indptr, S.indices, T.indptr, T.indices, influence, splitting) if second_pass: amg_core.rs_cf_splitting_pass2(S.shape[0], S.indptr, S.indices, splitting) return splitting
def CLJP(S, color=False): """Compute a C/F splitting using the parallel CLJP algorithm Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) color : bool use the CLJP coloring approach Returns ------- splitting : array Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical.split import CLJP >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = CLJP(S) See Also -------- MIS, PMIS, CLJPc References ---------- .. [1] David M. Alber and Luke N. Olson "Parallel coarse-grid selection" Numerical Linear Algebra with Applications 2007; 14:611-643. """ if not isspmatrix_csr(S): raise TypeError('expected csr_matrix') S = remove_diagonal(S) colorid = 0 if color: colorid = 1 T = S.T.tocsr() # transpose S for efficient column access splitting = np.empty(S.shape[0], dtype='intc') amg_core.cljp_naive_splitting(S.shape[0], S.indptr, S.indices, T.indptr, T.indices, splitting, colorid) return splitting
def CLJP(S, color=False): """Compute a C/F splitting using the parallel CLJP algorithm Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) color : bool use the CLJP coloring approach Returns ------- splitting : array Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical.split import CLJP >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = CLJP(S) See Also -------- MIS, PMIS, CLJPc References ---------- .. [1] David M. Alber and Luke N. Olson "Parallel coarse-grid selection" Numerical Linear Algebra with Applications 2007; 14:611-643. """ if not isspmatrix_csr(S): raise TypeError('expected csr_matrix') S = remove_diagonal(S) colorid = 0 if color: colorid = 1 T = S.T.tocsr() # transpose S for efficient column access splitting = numpy.empty(S.shape[0], dtype='intc') amg_core.cljp_naive_splitting(S.shape[0], S.indptr, S.indices, T.indptr, T.indices, splitting, colorid) return splitting
def MIS(G, weights, maxiter=None): """Compute a maximal independent set of a graph in parallel Parameters ---------- G : csr_matrix Matrix graph, G[i,j] != 0 indicates an edge weights : ndarray Array of weights for each vertex in the graph G maxiter : int Maximum number of iterations (default: None) Returns ------- mis : array Array of length of G of zeros/ones indicating the independent set Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical import MIS >>> import numpy as np >>> G = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> w = np.ones((G.shape[0],1)).ravel() >>> mis = MIS(G,w) See Also -------- fn = amg_core.maximal_independent_set_parallel """ if not isspmatrix_csr(G): raise TypeError('expected csr_matrix') G = remove_diagonal(G) mis = np.empty(G.shape[0], dtype='intc') mis[:] = -1 fn = amg_core.maximal_independent_set_parallel if maxiter is None: fn(G.shape[0], G.indptr, G.indices, -1, 1, 0, mis, weights, -1) else: if maxiter < 0: raise ValueError('maxiter must be >= 0') fn(G.shape[0], G.indptr, G.indices, -1, 1, 0, mis, weights, maxiter) return mis
def MIS(G, weights, maxiter=None): """Compute a maximal independent set of a graph in parallel Parameters ---------- G : csr_matrix Matrix graph, G[i,j] != 0 indicates an edge weights : ndarray Array of weights for each vertex in the graph G maxiter : int Maximum number of iterations (default: None) Returns ------- mis : array Array of length of G of zeros/ones indicating the independent set Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical import MIS >>> import numpy as np >>> G = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> w = np.ones((G.shape[0],1)).ravel() >>> mis = MIS(G,w) See Also -------- fn = amg_core.maximal_independent_set_parallel """ if not isspmatrix_csr(G): raise TypeError('expected csr_matrix') G = remove_diagonal(G) mis = np.empty(G.shape[0], dtype='intc') mis[:] = -1 fn = amg_core.maximal_independent_set_parallel if maxiter is None: fn(G.shape[0], G.indptr, G.indices, -1, 1, 0, mis, weights) else: if maxiter < 0: raise ValueError('maxiter must be >= 0') fn(G.shape[0], G.indptr, G.indices, -1, 1, 0, mis, weights, maxiter) return mis
def PMISc(S, method='JP'): """C/F splitting using Parallel Modified Independent Set (in color). PMIS-c, or PMIS in color, improves PMIS by perturbing the initial random weights with weights determined by a vertex coloring. Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) method : string Algorithm used to compute the initial vertex coloring: * 'MIS' - Maximal Independent Set * 'JP' - Jones-Plassmann (parallel) * 'LDF' - Largest-Degree-First (parallel) Returns ------- splitting : array Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical.split import PMISc >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = PMISc(S) See Also -------- MIS References ---------- .. [7] David M. Alber and Luke N. Olson "Parallel coarse-grid selection" Numerical Linear Algebra with Applications 2007; 14:611-643. """ S = remove_diagonal(S) weights, G, S, T = _preprocess(S, coloring_method=method) del S, T return MIS(G, weights)
def PMISc(S, method='JP'): """C/F splitting using Parallel Modified Independent Set (in color) PMIS-c, or PMIS in color, improves PMIS by perturbing the initial random weights with weights determined by a vertex coloring. Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) method : string Algorithm used to compute the initial vertex coloring: * 'MIS' - Maximal Independent Set * 'JP' - Jones-Plassmann (parallel) * 'LDF' - Largest-Degree-First (parallel) Returns ------- splitting : array Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical import PMISc >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = PMISc(S) See Also -------- MIS References ---------- .. [1] David M. Alber and Luke N. Olson "Parallel coarse-grid selection" Numerical Linear Algebra with Applications 2007; 14:611-643. """ S = remove_diagonal(S) weights, G, S, T = preprocess(S, coloring_method=method) return MIS(G, weights)
def CLJPc(S): """Compute a C/F splitting using the parallel CLJP-c algorithm CLJP-c, or CLJP in color, improves CLJP by perturbing the initial random weights with weights determined by a vertex coloring. Parameters ---------- S : csr_matrix Strength of connection matrix indicating the strength between nodes i and j (S_ij) Returns ------- splitting : array Array of length of S of ones (coarse) and zeros (fine) Examples -------- >>> from pyamg.gallery import poisson >>> from pyamg.classical.split import CLJPc >>> S = poisson((7,), format='csr') # 1D mesh with 7 vertices >>> splitting = CLJPc(S) See Also -------- MIS, PMIS, CLJP References ---------- .. [1] David M. Alber and Luke N. Olson "Parallel coarse-grid selection" Numerical Linear Algebra with Applications 2007; 14:611-643. """ S = remove_diagonal(S) return CLJP(S, color=True)