From 27e273fba5c38acbc0a6afd75720957f30ba3adf Mon Sep 17 00:00:00 2001 From: ammarhakim Date: Sat, 9 Sep 2023 12:19:09 -0400 Subject: [PATCH 1/4] Fixed memory leaks in superlup_ops code. The problems here were many: the A, B, L, U matrix pointers were not freed. Further, by mistake the incorrect free method was called on brhs: this is a gkyl_array. Instead of calling gkyl_array_release the method gkyl_free was being called. This meant that the array was not actually freed at all. This likely does not fix all the problems with fem_poisson but step at a time! --- zero/fem_poisson.c | 3 ++- zero/superlu_ops.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/zero/fem_poisson.c b/zero/fem_poisson.c index bfb052002..58ee44c8f 100644 --- a/zero/fem_poisson.c +++ b/zero/fem_poisson.c @@ -52,6 +52,7 @@ gkyl_fem_poisson_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis } else { up->ishelmholtz = false; kSq_ho = gkyl_array_new(GKYL_DOUBLE, 1, 1); + //kSq_ho = gkyl_array_new(GKYL_DOUBLE, 1, 10); gkyl_array_clear(kSq_ho, 0.); } @@ -314,7 +315,7 @@ void gkyl_fem_poisson_release(gkyl_fem_poisson *up) #endif gkyl_free(up->globalidx); - gkyl_free(up->brhs); + gkyl_array_release(up->brhs); gkyl_free(up->kernels); gkyl_free(up); } diff --git a/zero/superlu_ops.c b/zero/superlu_ops.c index bc05e3e66..98c7c3aa6 100644 --- a/zero/superlu_ops.c +++ b/zero/superlu_ops.c @@ -254,9 +254,11 @@ gkyl_superlu_prob_release(struct gkyl_superlu_prob *prob) { SUPERLU_FREE (prob->rhs); SUPERLU_FREE (prob->perm_c); + for (size_t k=0; knprob; k++) { SUPERLU_FREE (prob->perm_r[k]); Destroy_CompCol_Matrix(prob->A[k]); + gkyl_free(prob->A[k]); if (prob->assigned_rhs) Destroy_SuperMatrix_Store(prob->B[k]); @@ -265,6 +267,10 @@ gkyl_superlu_prob_release(struct gkyl_superlu_prob *prob) Destroy_SuperNode_Matrix(prob->L[k]); Destroy_CompCol_Matrix(prob->U[k]); } + + gkyl_free(prob->B[k]); + gkyl_free(prob->L[k]); + gkyl_free(prob->U[k]); } StatFree(&prob->stat); gkyl_free(prob->A); From 08539c013af5b071e9aa73a05ea41043ac62d2e4 Mon Sep 17 00:00:00 2001 From: ammarhakim Date: Sat, 9 Sep 2023 13:01:57 -0400 Subject: [PATCH 2/4] Removing the commented out line left behind from debugging --- zero/fem_poisson.c | 1 - 1 file changed, 1 deletion(-) diff --git a/zero/fem_poisson.c b/zero/fem_poisson.c index 58ee44c8f..d778a76e9 100644 --- a/zero/fem_poisson.c +++ b/zero/fem_poisson.c @@ -52,7 +52,6 @@ gkyl_fem_poisson_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis } else { up->ishelmholtz = false; kSq_ho = gkyl_array_new(GKYL_DOUBLE, 1, 1); - //kSq_ho = gkyl_array_new(GKYL_DOUBLE, 1, 10); gkyl_array_clear(kSq_ho, 0.); } From a71c1dd6bd26c3ef1b3faf409f685137c79c6c60 Mon Sep 17 00:00:00 2001 From: ammarhakim Date: Sat, 9 Sep 2023 13:08:46 -0400 Subject: [PATCH 3/4] Fixed the incorrectly allocated kSq_ho array. It should have num_basis elements and not 1 element. --- zero/fem_poisson.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zero/fem_poisson.c b/zero/fem_poisson.c index d778a76e9..6e7277ca9 100644 --- a/zero/fem_poisson.c +++ b/zero/fem_poisson.c @@ -51,7 +51,7 @@ gkyl_fem_poisson_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis gkyl_array_copy(kSq_ho, kSq); } else { up->ishelmholtz = false; - kSq_ho = gkyl_array_new(GKYL_DOUBLE, 1, 1); + kSq_ho = gkyl_array_new(GKYL_DOUBLE, up->num_basis, 1); gkyl_array_clear(kSq_ho, 0.); } From 71fcd4a65c61b8aa9a2c91ca69671228607ea2d5 Mon Sep 17 00:00:00 2001 From: manauref Date: Sat, 9 Sep 2023 16:39:01 -0700 Subject: [PATCH 4/4] Fixing similar errors in fem_poisson_perp. This exercise has made me realize a potential reason for the periodic case to not work in fem_poisson_perp: the size of rhs_cellavg is wrong because it is likely using local instead of local_ext. I will fix this in another branch, where I'll in fact move the calculation of rhs_cellavg out of fem_poisson. --- zero/fem_poisson_perp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zero/fem_poisson_perp.c b/zero/fem_poisson_perp.c index 118fdca40..32c70f29e 100644 --- a/zero/fem_poisson_perp.c +++ b/zero/fem_poisson_perp.c @@ -34,7 +34,7 @@ gkyl_fem_poisson_perp_new(const struct gkyl_range *solve_range, const struct gky gkyl_array_copy(kSq_ho, kSq); } else { up->ishelmholtz = false; - kSq_ho = gkyl_array_new(GKYL_DOUBLE, 1, 1); + kSq_ho = gkyl_array_new(GKYL_DOUBLE, up->num_basis, 1); gkyl_array_clear(kSq_ho, 0.); } @@ -367,7 +367,7 @@ void gkyl_fem_poisson_perp_release(struct gkyl_fem_poisson_perp *up) gkyl_superlu_prob_release(up->prob); #endif - gkyl_free(up->brhs); + gkyl_array_release(up->brhs); gkyl_free(up->kernels); gkyl_free(up->perp_range); gkyl_free(up->globalidx);