From 8db0a802ca195e7639fcb30f3e5d6f10679ed0b0 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 9 Aug 2009 11:42:41 +0200 Subject: [PATCH] isl_basic_set_sample: only perform basis reduction once On larger problem, much time was spent on repeated basis reductions with little or no reduction on the number of points visited. The initial basis reduction seems to be sufficient in most cases. --- include/isl_ctx.h.in | 4 ++++ isl_ctx.c | 3 +++ isl_sample.c | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/isl_ctx.h.in b/include/isl_ctx.h.in index ef16c06..9168ff3 100644 --- a/include/isl_ctx.h.in +++ b/include/isl_ctx.h.in @@ -69,6 +69,10 @@ struct isl_ctx { #define ISL_PIP_PIP 1 unsigned pip; + #define ISL_GBR_NEVER 0 + #define ISL_GBR_ONCE 1 + #define ISL_GBR_ALWAYS 2 + unsigned gbr; unsigned gbr_only_first; }; diff --git a/isl_ctx.c b/isl_ctx.c index 2922a46..bee266b 100644 --- a/isl_ctx.c +++ b/isl_ctx.c @@ -37,6 +37,9 @@ struct isl_ctx *isl_ctx_alloc() ctx->ilp_solver = ISL_ILP_GBR; ctx->pip = ISL_PIP_TAB; + ctx->gbr = ISL_GBR_ONCE; + ctx->gbr_only_first = 0; + return ctx; error: free(ctx); diff --git a/isl_sample.c b/isl_sample.c index 51eea13..669ce0c 100644 --- a/isl_sample.c +++ b/isl_sample.c @@ -328,7 +328,7 @@ static struct isl_basic_set *basic_set_reduced(struct isl_basic_set *bset, return NULL; gbr_only_first = bset->ctx->gbr_only_first; - bset->ctx->gbr_only_first = 1; + bset->ctx->gbr_only_first = bset->ctx->gbr == ISL_GBR_ONCE; *T = isl_basic_set_reduced_basis(bset); bset->ctx->gbr_only_first = gbr_only_first; @@ -418,6 +418,8 @@ error: static struct isl_vec *sample_bounded(struct isl_basic_set *bset) { unsigned dim; + unsigned gbr; + struct isl_ctx *ctx; struct isl_vec *sample; struct isl_vec *obj = NULL; struct isl_mat *T = NULL; @@ -438,6 +440,9 @@ static struct isl_vec *sample_bounded(struct isl_basic_set *bset) if (bset->n_eq > 0) return sample_eq(bset, sample_bounded); + ctx = bset->ctx; + gbr = ctx->gbr; + isl_int_init(min); isl_int_init(max); obj = isl_vec_alloc(bset->ctx, 1 + dim); @@ -460,7 +465,10 @@ static struct isl_vec *sample_bounded(struct isl_basic_set *bset) goto out; } - if (isl_int_ne(min, max)) { + if (ctx->gbr != ISL_GBR_NEVER && isl_int_ne(min, max)) { + if (ctx->gbr == ISL_GBR_ONCE) + ctx->gbr = ISL_GBR_NEVER; + bset = basic_set_reduced(bset, &T); if (!bset) goto error; @@ -491,8 +499,10 @@ out: isl_vec_free(obj); isl_int_clear(min); isl_int_clear(max); + ctx->gbr = gbr; return sample; error: + ctx->gbr = gbr; isl_mat_free(T); isl_basic_set_free(bset); isl_vec_free(obj); -- 2.7.4