diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index 3197d24e6661a5f886643473f678a0b6d2176f67..d0aeaab31f739e22cfa9d2b71f6264d4d2cc2caf 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 bc36222aaf97c4f524ab367c7a2343ffe67a602e..cb1be694e830c5ab817cf6a13fc529a8a983766b 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"