aboutsummaryrefslogtreecommitdiff
path: root/mg2d.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-01-25 16:16:17 +0100
committerAnton Khirnov <anton@khirnov.net>2019-01-25 17:01:20 +0100
commitd76687285a032e25cbd258035321cb8d6d8e0330 (patch)
tree658d4a98c471129dd193efec43a4e61dd65e841b /mg2d.c
parentc570c02ea4a427ed6dbf74652ba4f7936cb371e8 (diff)
mg2d: factor out the boundary condition-related API
Diffstat (limited to 'mg2d.c')
-rw-r--r--mg2d.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/mg2d.c b/mg2d.c
index af33450..3406030 100644
--- a/mg2d.c
+++ b/mg2d.c
@@ -30,6 +30,8 @@
#include "ell_relax.h"
#include "log.h"
#include "mg2d.h"
+#include "mg2d_boundary.h"
+#include "mg2d_boundary_internal.h"
#include "mg2d_constants.h"
#define LEVELS_MAX 16
@@ -64,8 +66,6 @@ struct MG2DInternal {
int64_t time_solve;
int64_t count_solve;
-
- double *boundaries_base[4];
};
static void log_callback(MG2DLogger *log, int level, const char *fmt, va_list vl)
@@ -374,7 +374,7 @@ finish:
return 0;
}
-static void bnd_zero(EllRelaxBoundary *bdst, size_t nb_rows, size_t domain_size)
+static void bnd_zero(MG2DBoundary *bdst, size_t nb_rows, size_t domain_size)
{
for (size_t i = 0; i < nb_rows; i++) {
memset(bdst->val + i * bdst->val_stride - i, 0,
@@ -382,7 +382,7 @@ static void bnd_zero(EllRelaxBoundary *bdst, size_t nb_rows, size_t domain_size)
}
}
-static void bnd_copy(EllRelaxBoundary *bdst, const double *src, ptrdiff_t src_stride,
+static void bnd_copy(MG2DBoundary *bdst, const double *src, ptrdiff_t src_stride,
size_t nb_rows, size_t domain_size)
{
for (size_t i = 0; i < nb_rows; i++) {
@@ -431,7 +431,7 @@ static int mg_levels_init(MG2DContext *ctx)
for (int i = 0; i < ARRAY_ELEMS(cur->solver->boundaries); i++) {
MG2DBoundary *bsrc = ctx->boundaries[i];
- EllRelaxBoundary *bdst = &cur->solver->boundaries[i];
+ MG2DBoundary *bdst = cur->solver->boundaries[i];
bdst->type = bsrc->type;
switch (bsrc->type) {
case MG2D_BC_TYPE_FIXVAL:
@@ -647,18 +647,11 @@ MG2DContext *mg2d_solver_alloc(size_t domain_size)
priv->cpuflags = mg2di_cpu_flags_get();
for (int i = 0; i < ARRAY_ELEMS(ctx->boundaries); i++) {
- const size_t boundary_len_max = domain_size + 2 * (FD_STENCIL_MAX - 1);
-
- ctx->boundaries[i] = calloc(1, sizeof(*ctx->boundaries[i]));
- if (!ctx->boundaries[i])
- goto fail;
-
- ret = posix_memalign((void**)&priv->boundaries_base[i], 32,
- sizeof(*ctx->boundaries[i]->val) * boundary_len_max * FD_STENCIL_MAX);
- if (ret != 0)
+ ctx->boundaries[i] = mg2di_bc_alloc(domain_size);
+ if (!ctx->boundaries[i]) {
+ ret = -ENOMEM;
goto fail;
- ctx->boundaries[i]->val = priv->boundaries_base[i] + FD_STENCIL_MAX - 1;
- ctx->boundaries[i]->val_stride = boundary_len_max;
+ }
}
ret = mg_levels_alloc(ctx, domain_size);
@@ -707,10 +700,8 @@ void mg2d_solver_free(MG2DContext **pctx)
ctx->priv->root = next;
}
- for (int i = 0; i < ARRAY_ELEMS(ctx->boundaries); i++) {
- free(ctx->priv->boundaries_base[i]);
- free(ctx->boundaries[i]);
- }
+ for (int i = 0; i < ARRAY_ELEMS(ctx->boundaries); i++)
+ mg2di_bc_free(&ctx->boundaries[i]);
tp_free(&ctx->priv->tp);
free(ctx->priv);