aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-01-11 16:36:29 +0100
committerAnton Khirnov <anton@khirnov.net>2023-01-11 16:38:57 +0100
commitda6889fcec7cc0772f351752f37eb42380da6630 (patch)
tree246cd7bc9d911e5f132907de53f73d5b1d2dc42a
parent66eb0f74a2811b53eac353b07873718798985e98 (diff)
{ps,nl}solve: constify exported colloc grid
Reduces compiler warnings.
-rw-r--r--nlsolve.h2
-rw-r--r--pssolve.c32
-rw-r--r--pssolve.h2
3 files changed, 20 insertions, 16 deletions
diff --git a/nlsolve.h b/nlsolve.h
index d0e3c38..3f3987c 100644
--- a/nlsolve.h
+++ b/nlsolve.h
@@ -82,7 +82,7 @@ typedef struct NLSolveContext {
*
* Set by the solver after tdi_nlsolve_context_init().
*/
- double *(*colloc_grid)[2];
+ const double * const (*colloc_grid)[2];
// solver parameters
unsigned int maxiter;
diff --git a/pssolve.c b/pssolve.c
index 5de63f6..dd62391 100644
--- a/pssolve.c
+++ b/pssolve.c
@@ -58,6 +58,9 @@ struct PSSolvePriv {
int *ipiv;
double *mat;
+ // same as public colloc_grid, except non-const
+ double *(*colloc_grid)[2];
+
TPContext *tp;
TPContext *tp_internal;
};
@@ -371,9 +374,10 @@ int tdi_pssolve_context_init(PSSolveContext *ctx)
s->nb_coeffs = N;
- ctx->colloc_grid = calloc(ctx->nb_equations, sizeof(*ctx->colloc_grid));
- if (!ctx->colloc_grid)
+ s->colloc_grid = calloc(ctx->nb_equations, sizeof(*s->colloc_grid));
+ if (!s->colloc_grid)
return -ENOMEM;
+ ctx->colloc_grid = (const double * const (*)[2])s->colloc_grid;
/* initialize the per-equation state */
for (int i = 0; i < ctx->nb_equations; i++) {
@@ -392,15 +396,15 @@ int tdi_pssolve_context_init(PSSolveContext *ctx)
eq_ctx->mat = s->eqs[i - 1].mat + NB_COLLOC_POINTS(&s->eqs[i - 1]);
/* compute the collocation grid */
- posix_memalign((void**)&ctx->colloc_grid[i][0], 32, eq_ctx->nb_colloc_points[0] * sizeof(*ctx->colloc_grid[i][0]));
- posix_memalign((void**)&ctx->colloc_grid[i][1], 32, eq_ctx->nb_colloc_points[1] * sizeof(*ctx->colloc_grid[i][1]));
- if (!ctx->colloc_grid[i][0] || !ctx->colloc_grid[i][1])
+ posix_memalign((void**)&s->colloc_grid[i][0], 32, eq_ctx->nb_colloc_points[0] * sizeof(*s->colloc_grid[i][0]));
+ posix_memalign((void**)&s->colloc_grid[i][1], 32, eq_ctx->nb_colloc_points[1] * sizeof(*s->colloc_grid[i][1]));
+ if (!s->colloc_grid[i][0] || !s->colloc_grid[i][1])
return -ENOMEM;
for (int j = 0; j < eq_ctx->nb_colloc_points[0]; j++)
- ctx->colloc_grid[i][0][j] = tdi_basis_colloc_point(ctx->basis[i][0], eq_ctx->colloc_grid_order[0], j);
+ s->colloc_grid[i][0][j] = tdi_basis_colloc_point(ctx->basis[i][0], eq_ctx->colloc_grid_order[0], j);
for (int j = 0; j < eq_ctx->nb_colloc_points[1]; j++)
- ctx->colloc_grid[i][1][j] = tdi_basis_colloc_point(ctx->basis[i][1], eq_ctx->colloc_grid_order[1], j);
+ s->colloc_grid[i][1][j] = tdi_basis_colloc_point(ctx->basis[i][1], eq_ctx->colloc_grid_order[1], j);
}
@@ -477,6 +481,13 @@ void tdi_pssolve_context_free(PSSolveContext **pctx)
free(eq_ctx->basis_val);
}
}
+ if (ctx->priv->colloc_grid) {
+ for (int i = 0; i < ctx->nb_equations; i++)
+ for (int j = 0; j < ARRAY_ELEMS(ctx->priv->colloc_grid[i]); j++)
+ free(ctx->priv->colloc_grid[i][j]);
+ }
+
+ free(ctx->priv->colloc_grid);
free(ctx->priv->eqs);
@@ -489,13 +500,6 @@ void tdi_pssolve_context_free(PSSolveContext **pctx)
free(ctx->priv);
- if (ctx->colloc_grid) {
- for (int i = 0; i < ctx->nb_equations; i++)
- for (int j = 0; j < ARRAY_ELEMS(ctx->colloc_grid[i]); j++)
- free(ctx->colloc_grid[i][j]);
- }
-
- free(ctx->colloc_grid);
free(ctx->basis);
free(ctx->solve_order);
diff --git a/pssolve.h b/pssolve.h
index b350a1a..15ee313 100644
--- a/pssolve.h
+++ b/pssolve.h
@@ -116,7 +116,7 @@ typedef struct PSSolveContext {
*
* Set by the solver after tdi_pssolve_context_init().
*/
- double *(*colloc_grid)[2];
+ const double * const (*colloc_grid)[2];
/**
* The thread pool used for multithreaded execution. May be set by the