From 356bd9aac4b6ebce9408020b30a23be306193bd2 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de> Date: Thu, 15 Oct 2009 08:18:09 +0200 Subject: [PATCH] timeout for curve fitting --- pub/src/curve.cpp | 9 ++++++++- pub/src/frida2.cpp | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index 3197d24e..d0aeaab3 100644 --- a/pub/src/curve.cpp +++ b/pub/src/curve.cpp @@ -397,6 +397,7 @@ typedef struct { COlc *fc; uint k; uint j; + double timeout; } FitDatTyp; @@ -414,6 +415,8 @@ void globalEvaluate( double* par, int m_dat, double* fvec, try { FitDatTyp *mydata; mydata = (FitDatTyp*) data; + if( mydata->timeout && time(NULL) > mydata->timeout ) + throw string( "reached fit time out" ); COlc *fc = mydata->fc; const COld *fd = mydata->fd; CCurve *c = &(fc->VC[ mydata->j ]); @@ -474,6 +477,7 @@ namespace NFitTune { int nCall=200; int nPrint=0; int mFitMetric=1; + double maxtime = 3; }; @@ -507,7 +511,9 @@ void NCurveFile::SetFitTuningPars( string which ) if( ret<1 || ret> N_FIT_METRICS ) throw string( "invalid option" ); NFitTune::mFitMetric = ret; - } + } else if ( which=="t" ) + NFitTune::maxtime = dask( "Max duration of fits (in s)", + NFitTune::maxtime ); } @@ -576,6 +582,7 @@ void NCurveFile::Fit( bool _allow_slow_conv ) printf( " [%d*%zu]", npfree, D->size() ); if ( NFitTune::nPrint ) printf("\n"); + data.timeout = time(NULL) + NFitTune::maxtime; lm_minimize( D->size(), npfree, &(Par[0]), globalEvaluate, globalPrintout, &data, &control ); if( control.info==10 ) diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp index bc36222a..cb1be694 100644 --- a/pub/src/frida2.cpp +++ b/pub/src/frida2.cpp @@ -130,6 +130,7 @@ int main() " csc set number of calls\n" " csp set print frequency\n" " csm set fit metric\n" + " cst set maximum duration of fits\n" "Tuning parameters for integration:\n" " cn? show parameters\n" " cnm set integration mode\n" -- GitLab