Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit b383de7

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Cache the FMI configure results
This was previously done for Windows and now for Linux/OSX as well. The "dynamic" and "static" platforms now skip running the configure script since we know what the results (should) be.
1 parent cd1bf87 commit b383de7

File tree

4 files changed

+122
-73
lines changed

4 files changed

+122
-73
lines changed

Compiler/Script/CevalScriptBackend.mo

Lines changed: 88 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,83 @@ algorithm
31643164
end match;
31653165
end translateModelCPP;*/
31663166

3167+
protected function configureFMU
3168+
input String platform;
3169+
input String fmutmp;
3170+
input String logfile;
3171+
input Boolean isWindows;
3172+
protected
3173+
String CC, CFLAGS, LDFLAGS, makefileStr,
3174+
dir=fmutmp+"/sources/", cmd="",
3175+
quote="'",
3176+
dquote = if isWindows then "\"" else "'";
3177+
algorithm
3178+
CC := System.getCCompiler();
3179+
CFLAGS := System.stringReplace(System.getCFlags(),"${MODELICAUSERCFLAGS}","");
3180+
LDFLAGS := ("-L"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+System.getTriple()+"/omc"+dquote+" "+
3181+
"-Wl,-rpath,"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+System.getTriple()+"/omc"+dquote+" "+
3182+
System.getLDFlags()+" ");
3183+
if System.regularFileExists(dir + logfile) then
3184+
System.removeFile(dir + logfile);
3185+
end if;
3186+
_ := match platform
3187+
case "dynamic"
3188+
algorithm
3189+
makefileStr := System.readFile(dir + "Makefile.in");
3190+
// replace @XX@ variables in the Makefile
3191+
makefileStr := System.stringReplace(makefileStr, "@CC@", CC);
3192+
makefileStr := System.stringReplace(makefileStr, "@CFLAGS@", CFLAGS);
3193+
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+System.getRTLibsSim());
3194+
makefileStr := System.stringReplace(makefileStr, "@LIBS@", "");
3195+
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", System.getDllExt());
3196+
makefileStr := System.stringReplace(makefileStr, "@NEED_RUNTIME@", "");
3197+
makefileStr := System.stringReplace(makefileStr, "@NEED_DGESV@", "");
3198+
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
3199+
makefileStr := System.stringReplace(makefileStr, "@CPPFLAGS@", "");
3200+
makefileStr := System.stringReplace(makefileStr, "@LIBTYPE_DYNAMIC@", "1");
3201+
makefileStr := System.stringReplace(makefileStr, "\r\n", "\n");
3202+
System.writeFile(dir + "Makefile", makefileStr);
3203+
System.writeFile(dir + "config.log", "Using cached values for dynamic platform");
3204+
cmd := "cached values";
3205+
then ();
3206+
case "static"
3207+
algorithm
3208+
makefileStr := System.readFile(dir + "Makefile.in");
3209+
// replace @XX@ variables in the Makefile
3210+
makefileStr := System.stringReplace(makefileStr, "@CC@", CC);
3211+
makefileStr := System.stringReplace(makefileStr, "@CFLAGS@", CFLAGS);
3212+
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+System.getRTLibsFMU());
3213+
makefileStr := System.stringReplace(makefileStr, "@LIBS@", "");
3214+
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", System.getDllExt());
3215+
makefileStr := System.stringReplace(makefileStr, "@NEED_RUNTIME@", "1");
3216+
makefileStr := System.stringReplace(makefileStr, "@NEED_DGESV@", "");
3217+
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
3218+
makefileStr := System.stringReplace(makefileStr, "@CPPFLAGS@", "-DOMC_MINIMAL_RUNTIME=1 -DCMINPACK_NO_DLL=1");
3219+
makefileStr := System.stringReplace(makefileStr, "@LIBTYPE_DYNAMIC@", "1");
3220+
makefileStr := System.stringReplace(makefileStr, "\r\n", "\n");
3221+
System.writeFile(dir + "Makefile", makefileStr);
3222+
System.writeFile(dir + "config.log", "Using cached values for static platform");
3223+
cmd := "cached values";
3224+
then ();
3225+
else
3226+
algorithm
3227+
cmd := "cd \"" + fmutmp + "/sources\" && ./configure --host="+quote+platform+quote+" CFLAGS="+quote+"-Os -flto"+quote+" LDFLAGS=-flto";
3228+
if 0 <> System.systemCall(cmd, outFile=logfile) then
3229+
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {System.readFile(logfile)});
3230+
System.removeFile(dir + logfile);
3231+
fail();
3232+
end if;
3233+
then ();
3234+
end match;
3235+
if not isWindows then
3236+
if 0 <> System.systemCall("cd " + dir + " && make clean > /dev/null 2>&1") then
3237+
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {"Failed to make clean"});
3238+
fail();
3239+
end if;
3240+
end if;
3241+
ExecStat.execStat("buildModelFMU: configured platform " + platform + " using " + cmd);
3242+
end configureFMU;
3243+
31673244
protected function buildModelFMU " author: Frenkel TUD
31683245
translates a model into cpp code and writes also a makefile"
31693246
input FCore.Cache inCache;
@@ -3180,8 +3257,8 @@ protected function buildModelFMU " author: Frenkel TUD
31803257
output GlobalScript.SymbolTable st;
31813258
protected
31823259
Boolean staticSourceCodeFMU;
3183-
String filenameprefix, quote, dquote, fmutmp, thisplatform, cmd, logfile,
3184-
makefileStr, CC, CFLAGS, LDFLAGS, LIBS, dir;
3260+
String filenameprefix, fmutmp, thisplatform, cmd, logfile,
3261+
makefileStr, LIBS, dir;
31853262
GlobalScript.SimulationOptions defaulSimOpt;
31863263
SimCode.SimulationSettings simSettings;
31873264
list<String> libs;
@@ -3221,9 +3298,6 @@ algorithm
32213298
System.realtimeTick(ClockIndexes.RT_CLOCK_BUILD_MODEL);
32223299

32233300
isWindows := System.os() == "Windows_NT";
3224-
// compile
3225-
quote := if isWindows then "" else "'";
3226-
dquote := if isWindows then "\"" else "'";
32273301

32283302
if Config.simCodeTarget() == "Cpp" then
32293303
System.removeDirectory("binaries");
@@ -3234,79 +3308,30 @@ algorithm
32343308
CevalScript.compileModel(filenameprefix + "_FMU", libs,
32353309
makeVars={"TARGET_TRIPLET=" + platform});
32363310
end if;
3311+
ExecStat.execStat("buildModelFMU: Generate C++ for platform " + platform);
32373312
end for;
32383313
return;
32393314
end if;
32403315

32413316
CevalScript.compileModel(filenameprefix+"_FMU" , libs);
3242-
fmutmp := filenameprefix + ".fmutmp";
3243-
logfile := filenameprefix + ".log";
32443317

3245-
CC := quote+System.getCCompiler()+quote;
3246-
CFLAGS := quote+System.stringReplace(System.getCFlags(),"${MODELICAUSERCFLAGS}","")+quote;
3247-
LDFLAGS := quote+("-L"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+System.getTriple()+"/omc"+dquote+" "+
3248-
"-Wl,-rpath,"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+System.getTriple()+"/omc"+dquote+" "+
3249-
System.getLDFlags()+" ");
3318+
ExecStat.execStat("buildModelFMU: Generate the FMI files");
32503319

3251-
if isWindows then
3252-
dir := fmutmp + "/sources/";
3253-
makefileStr := System.readFile(dir + "Makefile.in");
3254-
// replace @XX@ variables in the Makefile
3255-
makefileStr := System.stringReplace(makefileStr, "@CC@", CC);
3256-
makefileStr := System.stringReplace(makefileStr, "@CFLAGS@", CFLAGS);
3257-
makefileStr := System.stringReplace(makefileStr, "@LDFLAGS@", LDFLAGS+System.getRTLibsSim()+quote);
3258-
makefileStr := System.stringReplace(makefileStr, "@LIBS@", "");
3259-
makefileStr := System.stringReplace(makefileStr, "@DLLEXT@", ".dll");
3260-
makefileStr := System.stringReplace(makefileStr, "@NEED_RUNTIME@", "");
3261-
makefileStr := System.stringReplace(makefileStr, "@NEED_DGESV@", "");
3262-
makefileStr := System.stringReplace(makefileStr, "@FMIPLATFORM@", System.modelicaPlatform());
3263-
makefileStr := System.stringReplace(makefileStr, "@CPPFLAGS@", "");
3264-
makefileStr := System.stringReplace(makefileStr, "\r\n", "\n");
3265-
System.writeFile(dir + "Makefile", makefileStr);
3266-
if System.regularFileExists(dir + logfile) then
3267-
System.removeFile(dir + logfile);
3268-
end if;
3269-
try
3270-
CevalScript.compileModel(filenameprefix, libs, workingDir=dir, makeVars={});
3271-
else
3272-
outValue := Values.STRING("");
3273-
return;
3274-
end try;
3275-
System.removeDirectory(fmutmp);
3276-
return;
3277-
end if;
3278-
3279-
thisplatform := " CC="+CC+
3280-
" CFLAGS="+CFLAGS+
3281-
" LDFLAGS="+LDFLAGS;
3320+
fmutmp := filenameprefix + ".fmutmp";
3321+
logfile := filenameprefix + ".log";
3322+
dir := fmutmp+"/sources/";
32823323

32833324
for platform in platforms loop
3284-
cmd := "cd \"" + fmutmp + "/sources\" && ./configure "+
3285-
(if platform == "dynamic" then
3286-
" --with-dynamic-om-runtime"+thisplatform+System.getRTLibsSim()+quote
3287-
elseif platform == "static" then
3288-
thisplatform+quote
3289-
else
3290-
(
3291-
" --host="+quote+platform+quote+
3292-
" CFLAGS="+quote+"-Os -flto"+quote+" LDFLAGS=-flto"
3293-
)
3294-
) + " && make clean";
3295-
if System.regularFileExists(logfile) then
3296-
System.removeFile(logfile);
3297-
end if;
3298-
if 0 <> System.systemCall(cmd, outFile=logfile) then
3299-
outValue := Values.STRING("");
3300-
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {System.readFile(logfile)});
3301-
return;
3302-
end if;
3325+
configureFMU(platform, fmutmp, logfile, isWindows);
33033326
try
3304-
CevalScript.compileModel(filenameprefix, libs, workingDir=fmutmp+"/sources", makeVars={});
3327+
CevalScript.compileModel(filenameprefix, libs, workingDir=dir, makeVars={});
33053328
else
33063329
outValue := Values.STRING("");
33073330
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {System.readFile(logfile)});
3331+
ExecStat.execStat("buildModelFMU failed for platform " + platform);
33083332
return;
33093333
end try;
3334+
ExecStat.execStat("buildModelFMU: Generate platform " + platform);
33103335
end for;
33113336

33123337
System.removeDirectory(fmutmp);

Compiler/SimCode/SimCodeMain.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ algorithm
293293
if not Config.getRunningTestsuite() then
294294
resstr = System.pwd() + System.pathDelimiter() + resstr;
295295
end if;
296+
ExecStat.execStat("translateModelFMU complete");
296297
then
297298
(cache, Values.STRING(resstr), st, dlow_1, libs, file_dir, resultValues);
298299
else

Compiler/Template/CodegenFMU.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,17 +1073,17 @@ match platform
10731073
else
10741074
<<
10751075
<%fileNamePrefix%>_FMU:
1076-
<%\t%>$(MAKE) $(MAINOBJ) <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES) > make.log
1076+
<%\t%>$(MAKE) CC="$(CC)" $(MAINOBJ) <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES) 2>&1 | tee make.log
10771077
<%\t%>mkdir -p ../binaries/$(FMIPLATFORM)
10781078
ifeq (@LIBTYPE_DYNAMIC@,1)
1079-
<%\t%>$(LD) -o <%modelNamePrefix%>$(DLLEXT) $(MAINOBJ) $(OFILES) $(RUNTIMEFILES) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(LDFLAGS)
1079+
<%\t%>$(LD) -o <%modelNamePrefix%>$(DLLEXT) $(MAINOBJ) $(OFILES) $(RUNTIMEFILES) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(LDFLAGS) 2>&1 | tee -a make.log
10801080
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>_FMU.libs config.log make.log ../binaries/$(FMIPLATFORM)/
10811081
endif
10821082
<%\t%>head -n20 Makefile > ../binaries/$(FMIPLATFORM)/config.summary
10831083
ifeq (@LIBTYPE_STATIC@,1)
10841084
<%\t%>rm -f <%modelNamePrefix%>.a
10851085
<%\t%>$(AR) -rsu <%modelNamePrefix%>.a $(MAINOBJ) $(OFILES) $(RUNTIMEFILES)
1086-
<%\t%>cp <%fileNamePrefix%>.a <%fileNamePrefix%>_FMU.libs config.log ../binaries/$(FMIPLATFORM)/
1086+
<%\t%>cp <%fileNamePrefix%>.a <%fileNamePrefix%>_FMU.libs config.log make.log ../binaries/$(FMIPLATFORM)/
10871087
endif
10881088
<%\t%>$(MAKE) distclean
10891089
<%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fileNamePrefix%>.fmu *

SimulationRuntime/fmi/export/fmi1/fmu1_model_interface.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ fmiComponent fmiInstantiateModel(fmiString instanceName, fmiString GUID, fmiCall
144144
comp = (ModelInstance *)functions.allocateMemory(1, sizeof(ModelInstance));
145145
if (comp) {
146146
DATA* fmudata = NULL;
147-
MODEL_DATA* modelData = NULL;
148-
SIMULATION_INFO* simInfo = NULL;
149-
threadData_t *threadData = NULL;
147+
MODEL_DATA* modelData = NULL;
148+
SIMULATION_INFO* simInfo = NULL;
149+
threadData_t *threadData = NULL;
150150

151151
comp->functions = functions;
152152
comp->loggingOn = loggingOn;
@@ -199,14 +199,21 @@ fmiComponent fmiInstantiateModel(fmiString instanceName, fmiString GUID, fmiCall
199199
/* read input vars */
200200
/* input_function(comp->fmuData);*/
201201
/* allocate memory for non-linear system solvers */
202+
#if !defined(OMC_NUM_NONLINEAR_SYSTEMS) || OMC_NUM_NONLINEAR_SYSTEMS>0
202203
initializeNonlinearSystems(comp->fmuData, comp->threadData);
204+
#endif
203205
/* allocate memory for non-linear system solvers */
206+
#if !defined(OMC_NUM_LINEAR_SYSTEMS) || OMC_NUM_LINEAR_SYSTEMS>0
204207
initializeLinearSystems(comp->fmuData, comp->threadData);
208+
#endif
205209
/* allocate memory for mixed system solvers */
210+
#if !defined(OMC_NUM_MIXED_SYSTEMS) || OMC_NUM_MIXED_SYSTEMS>0
206211
initializeMixedSystems(comp->fmuData, comp->threadData);
212+
#endif
207213
/* allocate memory for state selection */
214+
#if !defined(OMC_NO_STATESELECTION)
208215
initializeStateSetJacobians(comp->fmuData, comp->threadData);
209-
216+
#endif
210217
return comp;
211218
}
212219

@@ -643,7 +650,9 @@ fmiStatus fmiInitialize(fmiComponent c, fmiBoolean toleranceControlled, fmiReal
643650
/*TODO: Simulation stop time is need to calculate in before hand all sample events
644651
We shouldn't generate them all in beforehand */
645652
initSample(comp->fmuData, comp->threadData, comp->fmuData->localData[0]->timeValue, 100 /*should be stopTime*/);
653+
#if !defined(OMC_NDELAY_EXPRESSIONS) || OMC_NDELAY_EXPRESSIONS>0
646654
initDelay(comp->fmuData, comp->fmuData->localData[0]->timeValue);
655+
#endif
647656

648657
/* due to an event overwrite old values */
649658
overwriteOldSimulationData(comp->fmuData);
@@ -689,13 +698,15 @@ fmiStatus fmiEventUpdate(fmiComponent c, fmiBoolean intermediateResults, fmiEven
689698
/* try */
690699
MMC_TRY_INTERNAL(simulationJumpBuffer)
691700

701+
#if !defined(OMC_NO_STATESELECTION)
692702
if (stateSelection(comp->fmuData, threadData, 1, 1))
693703
{
694704
if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
695705
"fmiEventUpdate: Need to iterate state values changed!");
696706
/* if new set is calculated reinit the solver */
697707
eventInfo->stateValuesChanged = fmiTrue;
698708
}
709+
#endif
699710

700711
storePreValues(comp->fmuData);
701712

@@ -800,13 +811,15 @@ fmiStatus fmiCompletedIntegratorStep(fmiComponent c, fmiBoolean* callEventUpdate
800811
storePreValues(comp->fmuData);
801812
*callEventUpdate = fmiFalse;
802813
/******** check state selection ********/
814+
#if !defined(OMC_NO_STATESELECTION)
803815
if (stateSelection(comp->fmuData, comp->threadData, 1, 0))
804816
{
805817
if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
806818
"fmiEventUpdate: Need to iterate state values changed!");
807819
/* if new set is calculated reinit the solver */
808820
*callEventUpdate = fmiTrue;
809821
}
822+
#endif
810823
/* TODO: fix the extrapolation in non-linear system
811824
* then we can stop to save all variables in
812825
* in the whole ringbuffer
@@ -829,17 +842,27 @@ fmiStatus fmiTerminate(fmiComponent c)
829842
"fmiTerminate");
830843

831844
comp->state = modelTerminated;
845+
/* call external objects destructors */
846+
comp->fmuData->callback->callExternalObjectDestructors(comp->fmuData, comp->threadData);
847+
848+
#if !defined(OMC_NUM_NONLINEAR_SYSTEMS) || OMC_NUM_NONLINEAR_SYSTEMS>0
832849
/* free nonlinear system data */
833850
freeNonlinearSystems(comp->fmuData, comp->threadData);
851+
#endif
852+
#if !defined(OMC_NUM_MIXED_SYSTEMS) || OMC_NUM_MIXED_SYSTEMS>0
834853
/* free mixed system data */
835854
freeMixedSystems(comp->fmuData, comp->threadData);
855+
#endif
856+
#if !defined(OMC_NUM_LINEAR_SYSTEMS) || OMC_NUM_LINEAR_SYSTEMS>0
836857
/* free linear system data */
837858
freeLinearSystems(comp->fmuData, comp->threadData);
838-
839-
/* call external objects destructors */
840-
comp->fmuData->callback->callExternalObjectDestructors(comp->fmuData, comp->threadData);
859+
#endif
860+
#if !defined(OMC_NO_STATESELECTION)
841861
/* free stateset data */
842862
freeStateSetData(comp->fmuData);
863+
#endif
864+
865+
/* free stateset data */
843866
deInitializeDataStruc(comp->fmuData);
844867
/* free simuation data */
845868
comp->functions.freeMemory(comp->fmuData->modelData);

0 commit comments

Comments
 (0)