diff --git a/Compiler/FrontEnd/Ceval.mo b/Compiler/FrontEnd/Ceval.mo index 003aa256ba3..12b2be8608c 100644 --- a/Compiler/FrontEnd/Ceval.mo +++ b/Compiler/FrontEnd/Ceval.mo @@ -4395,6 +4395,7 @@ algorithm Option st; Msg msg; Env.Cache cache; + String str; case (cache,env,{xe,ye},impl,st,msg) equation (cache,Values.ARRAY(xv,{3}),_) = ceval(cache,env, xe, impl, st,NONE(), msg); @@ -4404,7 +4405,8 @@ algorithm (cache,res,st); case (_,_,_,_,_,MSG()) equation - Print.printErrorBuf("#- Error, could not evaulate cross. Ceval.cevalBuiltinCross failed.\n"); + str = "cross" +& ExpressionDump.printExpStr(DAE.TUPLE(inExpExpLst)); + Error.addMessage(Error.FAILED_TO_EVALUATE_EXPRESSION, {str}); then fail(); end matchcontinue; diff --git a/Compiler/FrontEnd/ValuesUtil.mo b/Compiler/FrontEnd/ValuesUtil.mo index 6bf8d6ae95c..e1ac7789822 100644 --- a/Compiler/FrontEnd/ValuesUtil.mo +++ b/Compiler/FrontEnd/ValuesUtil.mo @@ -1693,7 +1693,7 @@ algorithm makeArray({Values.INTEGER(iz1),Values.INTEGER(iz2),Values.INTEGER(iz3)}); case (_,_) equation - Debug.fprintln("failtrace", "- ValuesUtil.crossProduct failed"); + Error.addMessage(Error.INTERNAL_ERROR, {"ValuesUtil.crossProduct failed"}); then fail(); end matchcontinue; diff --git a/Compiler/Util/Error.mo b/Compiler/Util/Error.mo index b8e21e3f805..7789af44ef6 100644 --- a/Compiler/Util/Error.mo +++ b/Compiler/Util/Error.mo @@ -271,6 +271,7 @@ public constant ErrorID CONSISTENT_UNITS=518; public constant ErrorID INCOMPLETE_UNITS=519; public constant ErrorID INCOMPATIBLE_TYPES_FUNC=520; public constant ErrorID ASSIGN_RHS_ELABORATION=521; +public constant ErrorID FAILED_TO_EVALUATE_EXPRESSION = 522; public constant ErrorID INDEX_REDUCTION_NOTIFICATION=1000; public constant ErrorID SELECTED_STATE_DUE_TO_START_NOTIFICATION = 1001; @@ -687,6 +688,7 @@ protected constant list> errorTabl (META_DEAD_CODE,TRANSLATION(),NOTIFICATION(),"Dead code elimination: %s."), (META_UNUSED_DECL,TRANSLATION(),NOTIFICATION(),"Unused local variable: %s."), (META_UNUSED_AS_BINDING,TRANSLATION(),NOTIFICATION(),"Removing unused as-binding: %s."), + (FAILED_TO_EVALUATE_EXPRESSION,TRANSLATION(),ERROR(),"Could not evaluate expression: %s"), (COMPILER_WARNING,TRANSLATION(),WARNING(),"%s") }; diff --git a/Compiler/runtime/Makefile.common b/Compiler/runtime/Makefile.common index 1e87fda9996..b9d4ddf6726 100644 --- a/Compiler/runtime/Makefile.common +++ b/Compiler/runtime/Makefile.common @@ -19,7 +19,7 @@ endif RML_COMPAT=$(top_builddir)/c_runtime/rml_compatibility.h SRC = RTOpts_rml.c Print_rml.c System_rml.c Settings_rml.c \ - SimulationResults_rml.c IOStreamExt_rml.c rtclock.c Database.c Socket_rml.c + SimulationResults_rml.c IOStreamExt_rml.c Database.c Socket_rml.c CPPSRC = unitparser.cpp UnitParserExt_rml.cpp ptolemyio_rml.cpp \ BackendDAEEXT_rml.cpp ErrorMessage.cpp Error_rml.cpp OptManager_rml.cpp \ @@ -28,7 +28,7 @@ CPPSRC = unitparser.cpp UnitParserExt_rml.cpp ptolemyio_rml.cpp \ OBJ = $(SRC:.c=.o) $(CPPSRC:.cpp=.o) $(CPPSRC:.cc=.o) OMC_OBJ = Error_omc.o Print_omc.o RTOpts_omc.o System_omc.o Settings_omc.o \ - IOStreamExt_omc.o ErrorMessage.o systemimplmisc.o rtclock.o \ + IOStreamExt_omc.o ErrorMessage.o systemimplmisc.o \ UnitParserExt_omc.o unitparser.o BackendDAEEXT_omc.o Socket_omc.o \ Dynload_omc.o OptManager_omc.o SimulationResults_omc.o ptolemyio_omc.o $(OMCCORBASRC) diff --git a/c_runtime/Makefile.common b/c_runtime/Makefile.common index 77819853f4b..56549bc8edd 100644 --- a/c_runtime/Makefile.common +++ b/c_runtime/Makefile.common @@ -15,7 +15,7 @@ ddasrt.o dlinpk.o enorm.o hybrd1.o nelmead.o qform.o r1updt.o \ biglag.o ddassl.o dogleg.o fdjac1.o hybrj.o newuoa.o qrfac.o trsapp.o \ daux.o dlamch.o dpmpar.o hybrd.o lsame.o newuob.o r1mpyq.o update.o division.o\ java_interface.o meta_modelica.o meta_modelica_builtin.o meta_modelica_real.o \ -meta_modelica_string_lit.o ModelicaUtilities.o $(EXTRA_OBJS) +meta_modelica_string_lit.o rtclock.o ModelicaUtilities.o $(EXTRA_OBJS) SIMOBJS = $(FOBJS) simulation_runtime.o simulation_init.o simulation_input.o simulation_events.o linearize.o \ solver_dasrt.o solver_main.o simulation_result_plt.o simulation_result_csv.o simulation_result_bin.o simulation_result_mat.o simulation_delay.o tables.o options.o dgesv_aux.o $(EXTRA_SIMOBJS) @@ -50,6 +50,7 @@ read_write.h \ real_array.h \ ringbuffer.h \ rml_compatibility.h \ +rtclock.h \ sendData/sendData.h \ simulation_delay.h \ simulation_events.h \ diff --git a/c_runtime/meta_modelica_builtin_boxptr.h b/c_runtime/meta_modelica_builtin_boxptr.h index 6efe26675e4..b590c97664c 100644 --- a/c_runtime/meta_modelica_builtin_boxptr.h +++ b/c_runtime/meta_modelica_builtin_boxptr.h @@ -25,12 +25,12 @@ boxptr_binOp(boxptr_intMul,mmc_mk_icon,mmc_unbox_integer,*) boxptr_binOp(boxptr_intDiv,mmc_mk_icon,mmc_unbox_integer,/) boxptr_unOp(boxptr_intAbs,mmc_mk_icon,mmc_unbox_integer,labs) boxptr_unOp(boxptr_intNeg,mmc_mk_icon,mmc_unbox_integer,-) -boxptr_binOp(boxptr_intLt,mmc_mk_icon,mmc_unbox_integer,<) -boxptr_binOp(boxptr_intLe,mmc_mk_icon,mmc_unbox_integer,<=) -boxptr_binOp(boxptr_intEq,mmc_mk_icon,mmc_unbox_integer,==) -boxptr_binOp(boxptr_intNe,mmc_mk_icon,mmc_unbox_integer,!=) -boxptr_binOp(boxptr_intGe,mmc_mk_icon,mmc_unbox_integer,>) -boxptr_binOp(boxptr_intGt,mmc_mk_icon,mmc_unbox_integer,>=) +boxptr_binOp(boxptr_intLt,mmc_mk_bcon,mmc_unbox_integer,<) +boxptr_binOp(boxptr_intLe,mmc_mk_bcon,mmc_unbox_integer,<=) +boxptr_binOp(boxptr_intEq,mmc_mk_bcon,mmc_unbox_integer,==) +boxptr_binOp(boxptr_intNe,mmc_mk_bcon,mmc_unbox_integer,!=) +boxptr_binOp(boxptr_intGe,mmc_mk_bcon,mmc_unbox_integer,>=) +boxptr_binOp(boxptr_intGt,mmc_mk_bcon,mmc_unbox_integer,>) boxptr_unOp(boxptr_intReal,mmc_mk_rcon,mmc_unbox_integer,(modelica_real)) boxptr_binOp(boxptr_realAdd,mmc_mk_rcon,mmc_unbox_real,+) boxptr_binOp(boxptr_realSub,mmc_mk_rcon,mmc_unbox_real,-) @@ -38,12 +38,12 @@ boxptr_binOp(boxptr_realMul,mmc_mk_rcon,mmc_unbox_real,*) boxptr_binOp(boxptr_realDiv,mmc_mk_rcon,mmc_unbox_real,/) boxptr_unOp(boxptr_realAbs,mmc_mk_rcon,mmc_unbox_real,fabs) boxptr_unOp(boxptr_realNeg,mmc_mk_rcon,mmc_unbox_real,-) -boxptr_binOp(boxptr_realLt,mmc_mk_rcon,mmc_unbox_real,<) -boxptr_binOp(boxptr_realLe,mmc_mk_rcon,mmc_unbox_real,<=) -boxptr_binOp(boxptr_realEq,mmc_mk_rcon,mmc_unbox_real,==) -boxptr_binOp(boxptr_realNe,mmc_mk_rcon,mmc_unbox_real,!=) -boxptr_binOp(boxptr_realGe,mmc_mk_rcon,mmc_unbox_real,>) -boxptr_binOp(boxptr_realGt,mmc_mk_rcon,mmc_unbox_real,>=) +boxptr_binOp(boxptr_realLt,mmc_mk_bcon,mmc_unbox_real,<) +boxptr_binOp(boxptr_realLe,mmc_mk_bcon,mmc_unbox_real,<=) +boxptr_binOp(boxptr_realEq,mmc_mk_bcon,mmc_unbox_real,==) +boxptr_binOp(boxptr_realNe,mmc_mk_bcon,mmc_unbox_real,!=) +boxptr_binOp(boxptr_realGe,mmc_mk_bcon,mmc_unbox_real,>=) +boxptr_binOp(boxptr_realGt,mmc_mk_bcon,mmc_unbox_real,>) boxptr_unOp(boxptr_realInt,mmc_mk_icon,mmc_unbox_real,(modelica_integer)) #undef boxptr_unOp diff --git a/Compiler/runtime/rtclock.c b/c_runtime/rtclock.c similarity index 65% rename from Compiler/runtime/rtclock.c rename to c_runtime/rtclock.c index e7315b3ca34..f27d9a49f78 100644 --- a/Compiler/runtime/rtclock.c +++ b/c_runtime/rtclock.c @@ -35,6 +35,7 @@ #include LARGE_INTEGER performance_frequency; +LARGE_INTEGER acc_tp[NUM_RT_CLOCKS]; LARGE_INTEGER tick_tp[NUM_RT_CLOCKS]; void rt_tick(int ix) { @@ -55,11 +56,30 @@ double rt_tock(int ix) { return d1 / d2; } +void rt_clear(int ix) +{ + acc_tp[ix] = 0; +} + +void rt_accumulate(int ix) { + LARGE_INTEGER tock_tp; + QueryPerformanceCounter(&tock_tp); + acc_tp[ix] += tock_tp - tick_tp[ix]; +} + +double rt_total(int ix) { + double d1,d2; + d1 = (double)(acc_tp[ix].QuadPart); + d2 = (double) performance_frequency.QuadPart; + return d1 / d2; +} + #elif defined(__APPLE_CC__) #include #include +uint64_t acc_tp[NUM_RT_CLOCKS]; uint64_t tick_tp[NUM_RT_CLOCKS]; void rt_tick(int ix) { @@ -76,10 +96,29 @@ double rt_tock(int ix) { return elapsednano * 1e-9; } +void rt_clear(int ix) +{ + acc_tp[ix] = 0; +} + +void rt_accumulate(int ix) { + uint64_t tock_tp = mach_absolute_time(); + acc_tp[ix] += tock_tp - tick_tp[ix]; +} + +double rt_total(int ix) { + static mach_timebase_info_data_t info = {0,0}; + if (info.denom == 0) + mach_timebase_info(&info); + uint64_t elapsednano = acc_tp[ix] * (info.numer / info.denom); + return elapsednano * 1e-9; +} + #else #include +struct timespec acc_tp[NUM_RT_CLOCKS]; struct timespec tick_tp[NUM_RT_CLOCKS]; void rt_tick(int ix) { @@ -92,4 +131,25 @@ double rt_tock(int ix) { return (tock_tp.tv_sec - tick_tp[ix].tv_sec) + (tock_tp.tv_nsec - tick_tp[ix].tv_nsec)*1e-9; } +void rt_clear(int ix) +{ + acc_tp[ix].tv_sec = 0; + acc_tp[ix].tv_nsec = 0; +} + +void rt_accumulate(int ix) { + struct timespec tock_tp = {0,0}; + clock_gettime(CLOCK_MONOTONIC, &tock_tp); + acc_tp[ix].tv_sec += tock_tp.tv_sec -tick_tp[ix].tv_sec; + acc_tp[ix].tv_nsec += tock_tp.tv_nsec-tick_tp[ix].tv_nsec; + if (acc_tp[ix].tv_nsec > 1e9) { + acc_tp[ix].tv_sec++; + acc_tp[ix].tv_nsec -= 1e9; + } +} + +double rt_total(int ix) { + return acc_tp[ix].tv_sec + (acc_tp[ix].tv_nsec*1e-9); +} + #endif diff --git a/Compiler/runtime/rtclock.h b/c_runtime/rtclock.h similarity index 70% rename from Compiler/runtime/rtclock.h rename to c_runtime/rtclock.h index d195afa1700..e58455c3ca8 100644 --- a/Compiler/runtime/rtclock.h +++ b/c_runtime/rtclock.h @@ -31,11 +31,32 @@ #ifndef __RTCLOCK__H #define __RTCLOCK__H +#ifdef __cplusplus +extern "C" { +#endif + #define NUM_RT_CLOCKS 17 #define NUM_USER_RT_CLOCKS 16 #define RT_CLOCK_SPECIAL_STOPWATCH 16 /* The 17th clock */ +#define SIM_TIMER_TOTAL 0 +#define SIM_TIMER_INIT 1 +#define SIM_TIMER_STEP 2 +#define SIM_TIMER_OUTPUT 3 +#define SIM_TIMER_EVENT 4 + void rt_tick(int ix); +/* tick() ... tock() -> returns the number of seconds since the tick */ double rt_tock(int ix); +/*clear() ... tick() ... accumulate() ... tick() ... accumulate() + * returns the total number of seconds accumulated between the tick() and accumulate() calls */ +void rt_clear(int ix); +void rt_accumulate(int ix); +double rt_total(int ix); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/c_runtime/simulation_result_csv.cpp b/c_runtime/simulation_result_csv.cpp index 1babc5f9518..03f6a16a623 100644 --- a/c_runtime/simulation_result_csv.cpp +++ b/c_runtime/simulation_result_csv.cpp @@ -46,12 +46,13 @@ #include "simulation_runtime.h" #include #include - +#include "rtclock.h" void simulation_result_csv::emit() { const char* format = "%.16g,"; storeExtrapolationData(); + rt_tick(SIM_TIMER_OUTPUT); fprintf(fout, format, globalData->timeValue); for (int i = 0; i < globalData->nStates; i++) fprintf(fout, format, globalData->states[i]); @@ -64,6 +65,7 @@ void simulation_result_csv::emit() for (int i = 0; i < globalData->boolVariables.nAlgebraic; i++) fprintf(fout, format, globalData->boolVariables.algebraics[i]); fprintf(fout, "\n"); + rt_accumulate(SIM_TIMER_OUTPUT); } simulation_result_csv::simulation_result_csv(const char* filename, long numpoints) : simulation_result(filename,numpoints) @@ -92,5 +94,7 @@ simulation_result_csv::simulation_result_csv(const char* filename, long numpoint simulation_result_csv::~simulation_result_csv() { + rt_tick(SIM_TIMER_OUTPUT); fclose(fout); + rt_accumulate(SIM_TIMER_OUTPUT); } diff --git a/c_runtime/simulation_result_plt.cpp b/c_runtime/simulation_result_plt.cpp index 208b786bea5..27a5bb2b5ce 100644 --- a/c_runtime/simulation_result_plt.cpp +++ b/c_runtime/simulation_result_plt.cpp @@ -47,6 +47,7 @@ #include #include #include "../Compiler/runtime/config.h" +#include "rtclock.h" #ifdef CONFIG_WITH_SENDDATA #include "sendData/sendData.h" @@ -55,11 +56,10 @@ void simulation_result_plt::emit() { storeExtrapolationData(); + rt_tick(SIM_TIMER_OUTPUT); if (actualPoints < maxPoints) { if(!isInteractiveSimulation())add_result(simulationResultData,&actualPoints); //used for non-interactive simulation - return; - } - else { + } else { maxPoints = 1.4*maxPoints + (maxPoints-actualPoints) + 2000; // cerr << "realloc simulationResultData to a size of " << maxPoints * dataSize * sizeof(double) << endl; simulationResultData = (double*)realloc(simulationResultData, maxPoints * dataSize * sizeof(double)); @@ -69,6 +69,7 @@ void simulation_result_plt::emit() } add_result(simulationResultData,&actualPoints); } + rt_accumulate(SIM_TIMER_OUTPUT); } /* @@ -221,6 +222,7 @@ simulation_result_plt::~simulation_result_plt() if(Static::enabled()) closeSendData(); #endif + rt_tick(SIM_TIMER_OUTPUT); FILE* f = fopen(filename, "w"); if (!f) @@ -230,9 +232,6 @@ simulation_result_plt::~simulation_result_plt() throw SimulationResultFileOpenException(); } - clock_t t0, t1; - t0 = clock(); - // Rather ugly numbers than unneccessary rounding. //f.precision(std::numeric_limits::digits10 + 1); fprintf(f, "#Ptolemy Plot file, generated by OpenModelica\n"); @@ -295,6 +294,5 @@ simulation_result_plt::~simulation_result_plt() throw SimulationResultFileCloseException(); } - t1 = clock(); - // printf ("\telapsed wall clock time for printing simulation results: %g\n", ((double) (t1 - t0))/CLOCKS_PER_SEC); + rt_accumulate(SIM_TIMER_OUTPUT); } diff --git a/c_runtime/simulation_runtime.cpp b/c_runtime/simulation_runtime.cpp index 9353bf8e400..bbc0d4c1a85 100644 --- a/c_runtime/simulation_runtime.cpp +++ b/c_runtime/simulation_runtime.cpp @@ -52,6 +52,7 @@ #include "simulation_result_plt.h" #include "simulation_result_csv.h" #include "simulation_result_mat.h" +#include "rtclock.h" using namespace std; @@ -262,8 +263,12 @@ int startNonInteractiveSimulation(int argc, char**argv){ initSample(start,stop); initDelay(start); - if (measure_time_flag) - measure_start_time = clock(); + if (measure_time_flag) { + rt_tick(SIM_TIMER_TOTAL); + rt_clear(SIM_TIMER_OUTPUT); + rt_clear(SIM_TIMER_EVENT); + rt_clear(SIM_TIMER_INIT); + } if(create_linearmodel){ if (lintime == NULL ) { @@ -285,8 +290,12 @@ int startNonInteractiveSimulation(int argc, char**argv){ deinitDelay(); - if (measure_time_flag) - cout << "Time to calculate simulation: "<< (clock()-measure_start_time)/CLOCKS_PER_SEC <<" sec." << endl; + if (measure_time_flag) { + cout << "Time to calculate initial values: "<< rt_total(SIM_TIMER_INIT) <<" sec." << endl; + cout << "Total time to do event handling: "<< rt_total(SIM_TIMER_EVENT) <<" sec." << endl; + cout << "Total time to produce the output file: "<< rt_total(SIM_TIMER_OUTPUT) <<" sec." << endl; + cout << "Total time to calculate simulation: "<< rt_tock(SIM_TIMER_TOTAL) <<" sec." << endl; + } deInitializeDataStruc(globalData,ALL); return retVal; diff --git a/c_runtime/solver_dasrt.cpp b/c_runtime/solver_dasrt.cpp index 5be82620b2f..67521e7b371 100644 --- a/c_runtime/solver_dasrt.cpp +++ b/c_runtime/solver_dasrt.cpp @@ -39,6 +39,7 @@ #include #include #include +#include "rtclock.h" using namespace std; @@ -122,6 +123,7 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step, globalData->helpVars[i] = 0; const string *init_method = getFlagValue("im",argc,argv); + int measure_time_flag = (int)flagSet("mt",argc,argv); inUpdate = 0; @@ -162,6 +164,8 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step, if (sim_verbose) { cout << "Calculated bound parameters" << endl; } // Calculate initial values from (fixed) start attributes and intial equation // sections + if (measure_time_flag) + rt_tick(SIM_TIMER_INIT); globalData->init=1; initial_function(); // calculates e.g. start values depending on e.g parameters. saveall(); // adrpo: -> save the initial values to have them in pre(var); @@ -210,6 +214,10 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step, sim_result->emit(); calcEnabledZeroCrossings(); globalData->init = 0; + // Initialization complete + if (measure_time_flag) + rt_accumulate(SIM_TIMER_INIT); + if (sim_verbose) { cout << "calling DDASRT from "<< globalData->timeValue << " to "<< tout << endl; } // Take an initial tiny step and then check for events at startTime @@ -320,8 +328,8 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step, // alg vars too. acceptedStep = 1; functionDAE_output(); - checkTermination(); - function_storeDelayed(); + checkTermination(); + function_storeDelayed(); acceptedStep = 0; } while (outputSteps >= 0 && idid == 1 && globalData->timeValue < tout); @@ -361,8 +369,8 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step, // alg vars too. acceptedStep=1; functionDAE_output(); // discrete variables are seperated so that the can be emited before and after the event. - checkTermination(); - function_storeDelayed(); + checkTermination(); + function_storeDelayed(); acceptedStep=0; } while (outputSteps >= 0 && idid == 1 && globalData->timeValue < tout); } // end while diff --git a/c_runtime/solver_main.cpp b/c_runtime/solver_main.cpp index 54a21b8fbc7..65ae5803d54 100644 --- a/c_runtime/solver_main.cpp +++ b/c_runtime/solver_main.cpp @@ -41,6 +41,7 @@ #include #include #include +#include "rtclock.h" using namespace std; @@ -168,9 +169,10 @@ int solver_main(int argc, char** argv, double &start, double &stop, double &ste int sampleEvent_actived = 0; - double uround = dlamch_("P",1); + double uround = dlamch_((char*)"P",1); const string *init_method = getFlagValue("im",argc,argv); + int measure_time_flag = (int)flagSet("mt",argc,argv); int retValIntegrator; @@ -203,6 +205,8 @@ int solver_main(int argc, char** argv, double &start, double &stop, double &ste // Calculate initial values from initial_function() // saveall() value as pre values + if (measure_time_flag) + rt_tick(SIM_TIMER_INIT); globalData->init=1; initial_function(); saveall(); @@ -210,7 +214,7 @@ int solver_main(int argc, char** argv, double &start, double &stop, double &ste storeExtrapolationData(); // Calculate initial values from (fixed) start attributes if (initialize(init_method)) { - throw TerminateSimulationException(globalData->timeValue, + throw TerminateSimulationException(globalData->timeValue, string("Error in initialization. Storing results and exiting.\n")); } saveall(); @@ -219,8 +223,8 @@ int solver_main(int argc, char** argv, double &start, double &stop, double &ste // Calculate stable discrete state // and initial ZeroCrossings if (globalData->curSampleTimeIx < globalData->nSampleTimes){ - sampleEvent_actived = checkForSampleEvent(); - activateSampleEvents(); + sampleEvent_actived = checkForSampleEvent(); + activateSampleEvents(); } //Activate sample and evaluate again int needToIterate=0; @@ -275,6 +279,9 @@ int solver_main(int argc, char** argv, double &start, double &stop, double &ste saveall(); if (sim_verbose){ sim_result->emit(); } + // Initialization complete + if (measure_time_flag) + rt_accumulate(SIM_TIMER_INIT); globalData->init=0; // Put initial values to delayed expression buffers @@ -284,96 +291,108 @@ int solver_main(int argc, char** argv, double &start, double &stop, double &ste cout << "Performed initial value calculation." << endl; cout << "Start numerical solver from "<< globalData->timeValue << " to "<< stop << endl; } + std::fstream fmt; + if (measure_time_flag) { + fmt.open("omc_mt.log", std::fstream::out); + } try { - while( globalData->timeValue < stop){ - - /* - * Calculate new step size after an event - */ - if (dideventstep == 1){ - offset = globalData->timeValue-laststep; - dideventstep = 0; - if (offset+16*uround > step) - offset = 0; - }else{ - offset = 0; - } - globalData->current_stepsize = step-offset; - if (globalData->timeValue+globalData->current_stepsize>stop){ - globalData->current_stepsize = stop - globalData->timeValue; - } - - if (globalData->curSampleTimeIx < globalData->nSampleTimes){ - sampleEvent_actived = checkForSampleEvent(); - } - if (sim_verbose){ - cout << "Call Solver from " << globalData->timeValue << " to " << globalData->timeValue+globalData->current_stepsize << endl; - } - /* do one integration step - * - * one step means: - * determine all states by Integration-Method - * update continuous part with - * functionODE_new() and functionAlgebraics(); - */ - - retValIntegrator = solver_main_step(flag,start,stop,reset); - - functionAlgebraics(); - - function_storeDelayed(); - - if (reset) - reset = false; - - //Check for Events - if (CheckForNewEvent(&sampleEvent_actived)){ - stateEvents++; - reset = true; - dideventstep = 1; - }else if (sampleEvent_actived){ - EventHandle(1); - sampleEvents++; - reset = true; - dideventstep = 1; - sampleEvent_actived = 0; - }else{ - laststep = globalData->timeValue; - } - - // Emit this time step - functionAliasEquations(); - sim_result->emit(); - saveall(); + while( globalData->timeValue < stop ) { + if (measure_time_flag) { + rt_tick(SIM_TIMER_STEP); + } + /* + * Calculate new step size after an event + */ + if (dideventstep == 1) { + offset = globalData->timeValue-laststep; + dideventstep = 0; + if (offset+16*uround > step) + offset = 0; + } else { + offset = 0; + } + globalData->current_stepsize = step-offset; + if (globalData->timeValue+globalData->current_stepsize>stop) { + globalData->current_stepsize = stop - globalData->timeValue; + } - //Check for termination of terminate() or assert() - checkTermination(); + if (globalData->curSampleTimeIx < globalData->nSampleTimes) { + sampleEvent_actived = checkForSampleEvent(); + } + if (sim_verbose){ + cout << "Call Solver from " << globalData->timeValue << " to " << globalData->timeValue+globalData->current_stepsize << endl; + } + /* do one integration step + * + * one step means: + * determine all states by Integration-Method + * update continuous part with + * functionODE_new() and functionAlgebraics(); + */ + + retValIntegrator = solver_main_step(flag,start,stop,reset); + + functionAlgebraics(); + + function_storeDelayed(); + + if (reset) + reset = false; + + //Check for Events + if (measure_time_flag) + rt_tick(SIM_TIMER_EVENT); + if (CheckForNewEvent(&sampleEvent_actived)) { + stateEvents++; + reset = true; + dideventstep = 1; + } else if (sampleEvent_actived) { + EventHandle(1); + sampleEvents++; + reset = true; + dideventstep = 1; + sampleEvent_actived = 0; + } else { + laststep = globalData->timeValue; + } + if (measure_time_flag) + rt_accumulate(SIM_TIMER_EVENT); - if (retValIntegrator){ - throw TerminateSimulationException(globalData->timeValue, - string("Error in Simulation. Solver exit with error.\n")); - } - if (sim_verbose){ - cout << "** Step to " << globalData->timeValue << " Done!" << endl; - } + // Emit this time step + functionAliasEquations(); + saveall(); + if (measure_time_flag) { + fmt << "Time to calculate step to: " << globalData->timeValue << " " << rt_tock(SIM_TIMER_STEP) << " sec." << std::endl; + } + sim_result->emit(); + //Check for termination of terminate() or assert() + checkTermination(); + if (retValIntegrator) { + throw TerminateSimulationException(globalData->timeValue, + string("Error in Simulation. Solver exit with error.\n")); } - } catch (TerminateSimulationException &e) { - cout << e.getMessage() << endl; - if (modelTermination) { // terminated from assert, etc. - cout << "Simulation terminated at time " << globalData->timeValue << endl; - return -1; - } + if (sim_verbose) { + cout << "** Step to " << globalData->timeValue << " Done!" << endl; + } + + } + } catch (TerminateSimulationException &e) { + cout << e.getMessage() << endl; + if (modelTermination) { // terminated from assert, etc. + cout << "Simulation terminated at time " << globalData->timeValue << endl; + return -1; + } } - if (sim_verbose){ - cout << "\t*** Statistics ***" << endl; - cout << "Events: " << stateEvents + sampleEvents<< endl; - cout << "State Events: " << stateEvents << endl; - cout << "Sample Events: " << sampleEvents << endl; + if (sim_verbose) { + cout << "\t*** Statistics ***" << endl; + cout << "Events: " << stateEvents + sampleEvents<< endl; + cout << "State Events: " << stateEvents << endl; + cout << "Sample Events: " << sampleEvents << endl; } deinitializeEventData(); diff --git a/configure b/configure index e78e0872281..2d4ee4ef211 100755 --- a/configure +++ b/configure @@ -4750,7 +4750,7 @@ fi if test "Darwin" != `uname`; then - LDFLAGS+=" -lrt" + LIBSENDDATA_LDFLAGS+=" -lrt" fi diff --git a/configure.in b/configure.in index 1ee88a5f775..f029012011f 100644 --- a/configure.in +++ b/configure.in @@ -354,7 +354,7 @@ AC_ARG_WITH(sendData-Qt, [ --with-sendData-Qt Compile with support for plot ]) if test "Darwin" != `uname`; then - LDFLAGS+=" -lrt" + LIBSENDDATA_LDFLAGS+=" -lrt" fi dnl Check for libCoin