diff --git a/luksan/luksan.h b/luksan/luksan.h index 66b9281b5bb4c5ea06d1589e61b6d14970026632..5161bf5ff8225a96e2574bc23395009dd3e62850 100644 --- a/luksan/luksan.h +++ b/luksan/luksan.h @@ -32,6 +32,11 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data, int mf, int mos1, int mos2); +typedef struct { + double fl, fu, pl, rl, pu, ru; + int mes1, mes2, mes3, mode; +} ps1l01_state; + /***************************** internal routines *************************/ /* mssubs.c: */ @@ -88,7 +93,7 @@ void luksan_ps1l01__(double *r__, double *rp, tolp, double *par1, double *par2, int *kd, int *ld, int *nit, int *kit, int *nred, int *mred, int * maxst, int *iest, int *inits, int *iters, int *kters, - int *mes, int *isys); + int *mes, int *isys, ps1l01_state *state); void luksan_pulsp3__(int *n, int *m, int *mf, double *xm, double *gr, double *xo, double *go, double *r__, double *po, double *sig, int *iterh, diff --git a/luksan/plip.c b/luksan/plip.c index 8f42b3a4e972c10edaf1fe9170fbaa9e6aa62c68..8bce79ee1d9c134022c96056e984dc562f7b813a 100644 --- a/luksan/plip.c +++ b/luksan/plip.c @@ -153,6 +153,7 @@ static void plip_(int *nf, int *nb, double *x, int * int iters, irest, inits, kters, maxst; double snorm; int mtesx, ntesx; + ps1l01_state state; /* INITIATION */ @@ -375,7 +376,8 @@ L11130: L11170: luksan_ps1l01__(&r__, &rp, f, &fo, &fp, &p, &po, &pp, minf_est, &maxf, &rmin, &rmax, &tols, &tolp, &par1, &par2, &kd, &ld, &stat_1->nit, &kit, & - nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, &isys); + nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, + &isys, &state); if (isys == 0) { goto L11174; } diff --git a/luksan/plis.c b/luksan/plis.c index 84d4c0a06f4114cacdcaa7c0c5530c29ccf7affb..11d371f209560912a864404b08e6276e47462c47 100644 --- a/luksan/plis.c +++ b/luksan/plis.c @@ -144,6 +144,7 @@ static void plis_(int *nf, int *nb, double *x, int * int iters, irest, inits, kters, maxst; double snorm; int mtesx, ntesx; + ps1l01_state state; /* INITIATION */ @@ -382,7 +383,8 @@ L12620: L11170: luksan_ps1l01__(&r__, &rp, f, &fo, &fp, &p, &po, &pp, minf_est, &maxf, &rmin, &rmax, &tols, &tolp, &par1, &par2, &kd, &ld, &stat_1->nit, &kit, & - nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, &isys); + nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, + &isys, &state); if (isys == 0) { goto L11174; } diff --git a/luksan/pnet.c b/luksan/pnet.c index bf6192eda12aa10bbc4a83c89457f1c9c2629149..d57461c1d6224de35cd34b3ab8f257bab33bc5a2 100644 --- a/luksan/pnet.c +++ b/luksan/pnet.c @@ -172,6 +172,7 @@ static void pnet_(int *nf, int *nb, double *x, int * int iters, irest, inits, kters, maxst; double snorm; int mtesx, ntesx; + ps1l01_state state; /* INITIATION */ @@ -517,7 +518,8 @@ L12560: L11060: luksan_ps1l01__(&r__, &rp, f, &fo, &fp, &p, &po, &pp, minf_est, &maxf, &rmin, &rmax, &tols, &tolp, &par1, &par2, &kd, &ld, &stat_1->nit, &kit, & - nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, &isys); + nred, &mred, &maxst, iest, &inits, &iters, &kters, &mes, + &isys, &state); if (isys == 0) { goto L11064; } diff --git a/luksan/pssubs.c b/luksan/pssubs.c index 2d3f94869f2d6c411784d76a5ae2ec441b1aaac3..5393d74ffac0f04fa2815ea16a377dc9b34fa074 100644 --- a/luksan/pssubs.c +++ b/luksan/pssubs.c @@ -202,6 +202,16 @@ L1: return; } /* luksan_pnint1__ */ +/* save and restore state, replacing old non-reeentrant implementation + that used static local variables */ +#define SS(var) state->var = var +#define SAVE_STATE SS(fl); SS(fu); SS(pl); SS(rl); SS(pu); SS(ru); \ + SS(mes1); SS(mes2); SS(mes3); SS(mode) +#define RS(var) var = state->var +#define RESTORE_STATE RS(fl); RS(fu); RS(pl); RS(rl); RS(pu); RS(ru); \ + RS(mes1); RS(mes2); RS(mes3); RS(mode) + + /* cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc */ /* SUBROUTINE PS1L01 ALL SYSTEMS 97/12/01 * PURPOSE : @@ -276,20 +286,22 @@ void luksan_ps1l01__(double *r__, double *rp, tolp, double *par1, double *par2, int *kd, int *ld, int *nit, int *kit, int *nred, int *mred, int * maxst, int *iest, int *inits, int *iters, int *kters, - int *mes, int *isys) + int *mes, int *isys, ps1l01_state *state) { /* System generated locals */ double d__1, d__2; /* Local variables */ unsigned l1, l2, l3, m1, l5, m2, l7, m3; - static double fl, fu, pl, rl, pu, ru; - static int mes1, mes2, mes3, mode; + double fl, fu, pl, rl, pu, ru; + int mes1, mes2, mes3, mode; int merr; static int mtyp; int init1; double rtemp; + RESTORE_STATE; + if (*isys == 1) { goto L3; } @@ -363,6 +375,7 @@ L2: *kd = 1; *ld = -1; *isys = 1; + SAVE_STATE; return; L3: if (mode == 0) { @@ -463,6 +476,7 @@ L3: goto L2; L4: *isys = 0; + SAVE_STATE; return; } /* luksan_ps1l01__ */