From 40f16f2d2155bde6a6cc00d9946a7a424aae36d9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 27 Apr 2018 16:20:23 +0200 Subject: bicgstab: make the number of iterations runtime-configurable --- bicgstab.c | 11 ++++++----- bicgstab.h | 2 +- pssolve.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bicgstab.c b/bicgstab.c index 9b4d330..ab3e862 100644 --- a/bicgstab.c +++ b/bicgstab.c @@ -31,11 +31,11 @@ #include "bicgstab.h" #include "common.h" -#define BICGSTAB_MAXITER 16 #define BICGSTAB_TOL (1e-15) struct BiCGStabContext { int N; + int maxiter; double *x; double *p, *v, *y, *z, *t; @@ -164,7 +164,7 @@ static int solve_cl(BiCGStabContext *ctx, rho_prev = rho; } - if (i == BICGSTAB_MAXITER) + if (i == ctx->maxiter) return -1; clEnqueueReadBuffer(ocl_q, ctx->cl_x, 1, 0, sizeof(double) * N, @@ -200,7 +200,7 @@ static int solve_sw(BiCGStabContext *ctx, memcpy(res0, res, N * sizeof(*res0)); memcpy(p, res, N * sizeof(*p)); - for (i = 0; i < BICGSTAB_MAXITER; i++) { + for (i = 0; i < ctx->maxiter; i++) { rho = cblas_ddot(N, res, 1, res0, 1); if (i) { @@ -239,7 +239,7 @@ static int solve_sw(BiCGStabContext *ctx, rho_prev = rho; } - if (i == BICGSTAB_MAXITER) + if (i == ctx->maxiter) return -1; memcpy(x, ctx->x, sizeof(*x) * ctx->N); @@ -298,7 +298,7 @@ int tdi_bicgstab_init(BiCGStabContext *ctx, const double *k, const double *x0) return 0; } -int tdi_bicgstab_context_alloc(BiCGStabContext **pctx, int N, +int tdi_bicgstab_context_alloc(BiCGStabContext **pctx, int N, int maxiter, cl_context ocl_ctx, cl_command_queue ocl_q) { BiCGStabContext *ctx; @@ -309,6 +309,7 @@ int tdi_bicgstab_context_alloc(BiCGStabContext **pctx, int N, return -ENOMEM; ctx->N = N; + ctx->maxiter = maxiter; #if HAVE_OPENCL if (ocl_ctx) { diff --git a/bicgstab.h b/bicgstab.h index 338a4a9..cecc06d 100644 --- a/bicgstab.h +++ b/bicgstab.h @@ -36,7 +36,7 @@ typedef struct BiCGStabContext BiCGStabContext; * If the OpenCL context and command queue are provided (non-NULL), the solver * will run using clBLAS. */ -int tdi_bicgstab_context_alloc(BiCGStabContext **ctx, int N, +int tdi_bicgstab_context_alloc(BiCGStabContext **ctx, int N, int maxiter, cl_context ocl_ctx, cl_command_queue ocl_q); /** diff --git a/pssolve.c b/pssolve.c index f2288c2..906ec00 100644 --- a/pssolve.c +++ b/pssolve.c @@ -406,7 +406,7 @@ int tdi_pssolve_context_init(PSSolveContext *ctx) s->steps_since_inverse = INT_MAX; /* init the BiCGStab solver */ - ret = tdi_bicgstab_context_alloc(&s->bicgstab, N, ctx->ocl_ctx, ctx->ocl_queue); + ret = tdi_bicgstab_context_alloc(&s->bicgstab, N, 64, ctx->ocl_ctx, ctx->ocl_queue); if (ret < 0) return ret; -- cgit v1.2.3