Skip to content

Commit

Permalink
Enable warnings and a small refactor (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb authored Mar 20, 2021
1 parent 9690625 commit b2a77e4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 104 deletions.
98 changes: 97 additions & 1 deletion src/genmap-components.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <time.h>

#include <genmap-impl.h>
#include <parRSB.h>
#include <sort.h>

struct unmarked {
uint index;
Expand Down Expand Up @@ -130,3 +130,99 @@ sint get_components(sint *component, struct rsb_element *elements,

return count;
}

void split_and_repair_partitions(genmap_handle h, struct comm *lc, int level) {
sint np = lc->np;
int bin = 1;
if (lc->id < (np + 1) / 2)
bin = 0;
struct comm tc;
genmap_comm_split(lc, bin, lc->id, &tc);

struct rsb_element *e = genmap_get_elements(h);
uint nelt = genmap_get_nel(h);
int nv = genmap_get_nvertices(h);

/* Check for disconnected components */
GenmapInitLaplacianWeighted(h, &tc);

sint *comp_ids = NULL;
GenmapMalloc(nelt, &comp_ids);
sint ncomp_global, ncomp, buf;
ncomp_global = ncomp = get_components(comp_ids, e, &tc, &h->buf, nelt, nv);
comm_allreduce(lc, gs_int, gs_max, &ncomp_global, 1, &buf);

while (ncomp_global > 1) {
if (lc->id == 0) {
printf("\tWarning: There are %d disconnected components in level = %d!\n",
ncomp_global, level);
fflush(stdout);
}

sint *comp_count = NULL;
GenmapCalloc(2 * ncomp_global, &comp_count);
uint i;
for (i = 0; i < nelt; i++)
comp_count[comp_ids[i]]++;
comm_allreduce(&tc, gs_int, gs_add, comp_count, ncomp_global,
&comp_count[ncomp_global]);

sint min_count = INT_MAX, min_id = -1;
for (i = 0; i < ncomp; i++) {
if (comp_count[i] < min_count) {
min_count = comp_count[i];
min_id = i;
}
}
sint min_count_global = min_count;
comm_allreduce(lc, gs_int, gs_min, &min_count_global, 1, &buf);
sint id_global = (min_count_global == min_count) ? lc->id : lc->np;
comm_allreduce(lc, gs_int, gs_min, &id_global, 1, &buf);

struct crystal cr;
crystal_init(&cr, lc);

for (i = 0; i < nelt; i++)
e[i].proc = lc->id;

sint low_np = (np + 1) / 2;
sint high_np = np - low_np;
sint start = !bin * low_np;
sint P = bin * low_np + !bin * high_np;
sint size = (min_count_global + P - 1) / P;

sint current = 0;
if (min_count_global == min_count && lc->id == id_global) {
for (i = 0; i < nelt; i++) {
if (comp_ids[i] == min_id) {
e[i].proc = start + current / size;
current++;
}
}
assert(min_count == current && "min_count != current");
}

sarray_transfer(struct rsb_element, h->elements, proc, 1, &cr);
crystal_free(&cr);

// do a load balanced sort in each partition
parallel_sort(struct rsb_element, h->elements, fiedler, gs_double, 0, 1,
&tc, &h->buf);

genmap_comm_scan(h, &tc);

e = genmap_get_elements(h);
nelt = genmap_get_nel(h);
GenmapRealloc(nelt, &comp_ids);
GenmapInitLaplacianWeighted(h, &tc);
ncomp_global = ncomp = get_components(comp_ids, e, &tc, &h->buf, nelt, nv);
comm_allreduce(lc, gs_int, gs_max, &ncomp_global, 1, &buf);

GenmapFree(comp_count);
}

GenmapFree(comp_ids);
comm_free(lc);
comm_dup(lc, &tc);
comm_free(&tc);
}
1 change: 1 addition & 0 deletions src/genmap-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef struct {
sint get_components(sint *component, struct rsb_element *elements,
struct comm *c, buffer *buf, uint nelt, uint nv);

void split_and_repair_partitions(genmap_handle h, struct comm *lc, int level);
/* Matrix inverse */
void matrix_inverse(int N, double *A);

Expand Down
102 changes: 2 additions & 100 deletions src/genmap-rsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <time.h>

#include <genmap-impl.h>
#include <parRSB.h>
#include <sort.h>

static int dump_fiedler_if_discon(genmap_handle h, int level, int max_levels) {
Expand Down Expand Up @@ -48,102 +47,6 @@ static int dump_fiedler_if_discon(genmap_handle h, int level, int max_levels) {
}
}

static void split_and_repair_partitions(genmap_handle h, struct comm *lc,
int level) {
sint np = lc->np;
int bin = 1;
if (lc->id < (np + 1) / 2)
bin = 0;
struct comm tc;
genmap_comm_split(lc, bin, lc->id, &tc);

struct rsb_element *e = genmap_get_elements(h);
uint nelt = genmap_get_nel(h);
int nv = genmap_get_nvertices(h);

/* Check for disconnected components */
sint *comp_ids = NULL;
GenmapMalloc(nelt, &comp_ids);
GenmapInitLaplacianWeighted(h, &tc);
sint ncomp_global, ncomp, buf;
ncomp_global = ncomp = get_components(comp_ids, e, &tc, &h->buf, nelt, nv);
comm_allreduce(lc, gs_int, gs_max, &ncomp_global, 1, &buf);

while (ncomp_global > 1) {
if (lc->id == 0) {
printf("\tWarning: There are %d disconnected components in level = %d!\n",
ncomp_global, level);
fflush(stdout);
}

sint *comp_count = NULL;
GenmapCalloc(2 * ncomp_global, &comp_count);
uint i;
for (i = 0; i < nelt; i++)
comp_count[comp_ids[i]]++;
comm_allreduce(&tc, gs_int, gs_add, comp_count, ncomp_global,
&comp_count[ncomp_global]);

sint min_count = INT_MAX, min_id = -1;
for (i = 0; i < ncomp; i++) {
if (comp_count[i] < min_count) {
min_count = comp_count[i];
min_id = i;
}
}
sint min_count_global = min_count;
comm_allreduce(lc, gs_int, gs_min, &min_count_global, 1, &buf);
sint id_global = (min_count_global == min_count) ? lc->id : lc->np;
comm_allreduce(lc, gs_int, gs_min, &id_global, 1, &buf);

struct crystal cr;
crystal_init(&cr, lc);

for (i = 0; i < nelt; i++)
e[i].proc = lc->id;

sint low_np = (np + 1) / 2;
sint high_np = np - low_np;
sint start = !bin * low_np;
sint P = bin * low_np + !bin * high_np;
sint size = (min_count_global + P - 1) / P;

sint current = 0;
if (min_count_global == min_count && lc->id == id_global) {
for (i = 0; i < nelt; i++) {
if (comp_ids[i] == min_id) {
e[i].proc = start + current / size;
current++;
}
}
assert(min_count == current && "min_count != current");
}

sarray_transfer(struct rsb_element, h->elements, proc, 1, &cr);
crystal_free(&cr);

// do a load balanced sort in each partition
parallel_sort(struct rsb_element, h->elements, fiedler, gs_double, 0, 1,
&tc, &h->buf);

genmap_comm_scan(h, &tc);

e = genmap_get_elements(h);
nelt = genmap_get_nel(h);
GenmapRealloc(nelt, &comp_ids);
GenmapInitLaplacianWeighted(h, &tc);
ncomp_global = ncomp = get_components(comp_ids, e, &tc, &h->buf, nelt, nv);
comm_allreduce(lc, gs_int, gs_max, &ncomp_global, 1, &buf);

GenmapFree(comp_count);
}

GenmapFree(comp_ids);
comm_free(lc);
comm_dup(lc, &tc);
comm_free(&tc);
}

int genmap_rsb(genmap_handle h) {
int verbose = h->options->debug_level > 1;
int max_iter = 50;
Expand Down Expand Up @@ -221,7 +124,6 @@ int genmap_rsb(genmap_handle h) {
level++;
}

#if 0
/* Check if Fidler converged */
sint converged = 1;
for (i = 0; i < metric_get_levels(); i++) {
Expand All @@ -234,8 +136,8 @@ int genmap_rsb(genmap_handle h) {
}
comm_allreduce(gc, gs_int, gs_min, &converged, 1, bfr); // min
if (converged == 0 && gc->id == 0)
printf("\tWARNING: Lanczos failed to converge while partitioning, Level=%d!\n", level);
#endif
printf("\tWARNING: Failed to converge while partitioning, Level=%d!\n",
level);

return 0;
}
1 change: 0 additions & 1 deletion tests/t230-flex-cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <gencon-impl.h>
#include <genmap-impl.h>
#include <genmap-multigrid-precon.h>
#include <parRSB.h>

int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
Expand Down
1 change: 0 additions & 1 deletion tests/t235-project-pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <gencon-impl.h>
#include <genmap-impl.h>
#include <genmap-multigrid-precon.h>
#include <parRSB.h>

int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
Expand Down
1 change: 0 additions & 1 deletion tests/t240-rqi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <gencon-impl.h>
#include <genmap-impl.h>
#include <genmap-multigrid-precon.h>
#include <parRSB.h>

int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
Expand Down

0 comments on commit b2a77e4

Please sign in to comment.