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 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'bicgstab.c') 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) { -- cgit v1.2.3