32 grid->delete_top_level_A =
false;
39 if (
grid->level == 0) {
40 if (
grid->delete_top_level_A) {
54 int i, ii, j, *ia, *ja, m, n, *p =
NULL;
58 int *matched, nz, nz0;
60 int nsuper, *super =
NULL, *superp =
NULL;
63 assert(
A->is_pattern_symmetric);
70 *clusterp =
gv_calloc(m + 1,
sizeof(
int));
73 for (i = 0; i < m; i++) matched[i] = i;
85 for (i = 0; i < nsuper; i++){
86 if (superp[i+1] - superp[i] <= 1)
continue;
87 nz0 = (*clusterp)[*ncluster];
88 for (j = superp[i]; j < superp[i+1]; j++){
89 matched[super[j]] = MATCHED;
90 (*cluster)[nz++] = super[j];
92 (*clusterp)[++(*ncluster)] = nz;
96 if (nz > nz0) (*clusterp)[++(*ncluster)] = nz;
100 for (ii = 0; ii < m; ii++){
103 if (matched[i] == MATCHED)
continue;
104 for (j = ia[i]; j < ia[i+1]; j++){
105 if (i == ja[j])
continue;
106 if (matched[ja[j]] != MATCHED && matched[i] != MATCHED){
120 matched[jamax] = MATCHED;
121 matched[i] = MATCHED;
122 (*cluster)[nz++] = i;
123 (*cluster)[nz++] = jamax;
124 (*clusterp)[++(*ncluster)] = nz;
128 for (i = 0; i < m; i++){
129 if (matched[i] == i){
130 (*cluster)[nz++] = i;
131 (*clusterp)[++(*ncluster)] = nz;
149 int *cluster=
NULL, *clusterp=
NULL, ncluster;
151 assert(
A->m ==
A->n);
158 assert(ncluster <= n);
163 fprintf(stderr,
"nc = %d, nf = %d, minsz = %d, coarsen_factor = %f coarsening stops\n",nc, n,
minsize,
min_coarsen_factor);
171 for (i = 0; i < ncluster; i++){
172 for (j = clusterp[i]; j < clusterp[i+1]; j++){
173 assert(clusterp[i+1] > clusterp[i]);
174 irn[nzc] = cluster[j];
188 (*cA)->is_symmetric =
true;
189 (*cA)->is_pattern_symmetric =
true;
215 if (
Verbose) fprintf(stderr,
"nc=%d n = %d\n",nc,n);
242 for (i = 0; i < n; i++) fputs (
" ", stderr);
253 fprintf(stderr,
"level -- %d, n = %d, nz = %d nz/n = %f\n",
grid->level,
grid->n,
grid->A->nz,
grid->A->nz/(
double)
grid->n);
261 fprintf(stderr,
" maxlevel reached, coarsening stops\n");
267 if (!cA)
return grid;
292 if (
A != A0)
grid->delete_top_level_A =
true;
void print_padding(int n)
static const double min_coarsen_factor
Multilevel Multilevel_get_coarsest(Multilevel grid)
static void maximal_independent_edge_set_heavest_edge_pernode_supernodes_first(SparseMatrix A, int **cluster, int **clusterp, int *ncluster)
void Multilevel_delete(Multilevel grid)
static void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA, SparseMatrix *P, SparseMatrix *R)
static Multilevel Multilevel_init(SparseMatrix A)
static Multilevel Multilevel_establish(Multilevel grid, const Multilevel_control ctrl)
Multilevel Multilevel_new(SparseMatrix A0, const Multilevel_control ctrl)
static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, SparseMatrix *P, SparseMatrix *R)
void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
bool SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only)
SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B)
SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A)
SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val0, int type, size_t sz)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix C)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
static void * gv_alloc(size_t size)
int * random_permutation(int n)