From a7e56f77275830af694453e978c9f568a0b2b2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sj=C3=B6lund?= Date: Thu, 20 Sep 2012 14:54:45 +0000 Subject: [PATCH] - Added scripting call system_parallel - Made BuildModelRecursive.mos capable of generating a report while simulating models in parallel git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12994 f25d12d1-65f4-0310-ae8a-bbce733d8d8e --- Compiler/FrontEnd/ModelicaBuiltin.mo | 7 ++++ Compiler/Script/CevalScript.mo | 7 ++++ Compiler/Util/System.mo | 6 ++++ Compiler/runtime/Makefile.common | 6 ++-- .../runtime/{System_omc.cpp => System_omc.c} | 4 --- Compiler/runtime/System_rml.c | 7 ++++ Compiler/runtime/systemimpl.c | 36 +++++++++++++++++++ Examples/BuildModelRecursive.mos | 9 +++-- configure.in | 6 ++-- 9 files changed, 78 insertions(+), 10 deletions(-) rename Compiler/runtime/{System_omc.cpp => System_omc.c} (99%) diff --git a/Compiler/FrontEnd/ModelicaBuiltin.mo b/Compiler/FrontEnd/ModelicaBuiltin.mo index 1efad63f739..e4a6248f6ca 100644 --- a/Compiler/FrontEnd/ModelicaBuiltin.mo +++ b/Compiler/FrontEnd/ModelicaBuiltin.mo @@ -989,6 +989,13 @@ external "builtin" annotation(__OpenModelica_Impure=true); annotation(preferredView="text"); end system; +function system_parallel "Similar to system(3). Executes the given commands in the system shell, in parallel if omc was compiled using OpenMP." + input String callStr[:] "String to call: bash -c $callStr"; + output Integer retval[:] "Return value of the system call; usually 0 on success"; +external "builtin" annotation(__OpenModelica_Impure=true); +annotation(preferredView="text"); +end system_parallel; + function saveAll "save the entire loaded AST to file." input String fileName; output Boolean success; diff --git a/Compiler/Script/CevalScript.mo b/Compiler/Script/CevalScript.mo index d1d690f9b44..c32ce97640c 100644 --- a/Compiler/Script/CevalScript.mo +++ b/Compiler/Script/CevalScript.mo @@ -1568,6 +1568,13 @@ algorithm then (cache,Values.INTEGER(resI),st); + case (cache,env,"system_parallel",{Values.ARRAY(valueLst=vals)},st,msg) + equation + strs = List.map(vals, ValuesUtil.extractValueString); + v = ValuesUtil.makeIntArray(System.systemCallParallel(strs)); + then + (cache,v,st); + case (cache,env,"timerClear",{Values.INTEGER(i)},st,msg) equation System.realtimeClear(i); diff --git a/Compiler/Util/System.mo b/Compiler/Util/System.mo index 715ee7109e3..42827bcc61a 100644 --- a/Compiler/Util/System.mo +++ b/Compiler/Util/System.mo @@ -308,6 +308,12 @@ public function systemCall external "C" outInteger=SystemImpl__systemCall(inString) annotation(Library = "omcruntime"); end systemCall; +public function systemCallParallel + input list inStrings; + output list outIntegers; + external "C" outIntegers=SystemImpl__systemCallParallel(inStrings) annotation(Library = "omcruntime"); +end systemCallParallel; + public function spawnCall input String path "The absolute path to the executable"; input String str "The list of arguments with executable"; diff --git a/Compiler/runtime/Makefile.common b/Compiler/runtime/Makefile.common index c6f83df0c37..bc8f2027f3f 100644 --- a/Compiler/runtime/Makefile.common +++ b/Compiler/runtime/Makefile.common @@ -62,8 +62,10 @@ Print_rml.o : printimpl.c Print_omc.o : printimpl.c Error_rml.o : errorext.cpp ErrorMessage.hpp Error_omc.o : errorext.cpp ErrorMessage.hpp ../OpenModelicaBootstrappingHeader.h -System_rml.o : systemimpl.c config.h errorext.h $(configUnix) -System_omc.o : systemimpl.c config.h errorext.h $(configUnix) $(RML_COMPAT) +System_rml.o : System_rml.c systemimpl.c config.h errorext.h $(configUnix) + $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) -fopenmp $< +System_omc.o : System_omc.c systemimpl.c config.h errorext.h $(configUnix) $(RML_COMPAT) + $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) -fopenmp $< Lapack_rml.o : lapackimpl.c config.h $(configUnix) Lapack_omc.o : lapackimpl.c config.h $(configUnix) $(RML_COMPAT) IOStreamExt_rml.o : IOStreamExt.c diff --git a/Compiler/runtime/System_omc.cpp b/Compiler/runtime/System_omc.c similarity index 99% rename from Compiler/runtime/System_omc.cpp rename to Compiler/runtime/System_omc.c index 00930a59776..0538d5284ab 100644 --- a/Compiler/runtime/System_omc.cpp +++ b/Compiler/runtime/System_omc.c @@ -28,8 +28,6 @@ * */ -extern "C" { - #if defined(_MSC_VER) #include #endif @@ -666,5 +664,3 @@ extern const char* System_snprintff(const char *fmt, int len, double d) buf[1023] = 0; return buf; } - -} diff --git a/Compiler/runtime/System_rml.c b/Compiler/runtime/System_rml.c index f5d2a41bf1b..998713e5c32 100644 --- a/Compiler/runtime/System_rml.c +++ b/Compiler/runtime/System_rml.c @@ -792,6 +792,13 @@ RML_BEGIN_LABEL(System__systemCall) } RML_END_LABEL +RML_BEGIN_LABEL(System__systemCallParallel) +{ + rmlA0 = SystemImpl__systemCallParallel(rmlA0); + RML_TAILCALLK(rmlSC); +} +RML_END_LABEL + RML_BEGIN_LABEL(System__spawnCall) { const char* path = RML_STRINGDATA(rmlA0); diff --git a/Compiler/runtime/systemimpl.c b/Compiler/runtime/systemimpl.c index 822ed16f4d4..45a73988901 100644 --- a/Compiler/runtime/systemimpl.c +++ b/Compiler/runtime/systemimpl.c @@ -565,6 +565,42 @@ int SystemImpl__systemCall(const char* str) return ret_val; } +void* SystemImpl__systemCallParallel(void *lst) +{ + void *tmp = lst; + int sz = 0, i; + char **calls; + int *results; + while (RML_NILHDR != RML_GETHDR(tmp)) { + sz++; + tmp = RML_CDR(tmp); + } + if (sz == 0) return mk_nil(); + calls = (char**) malloc(sz*sizeof(char*)); + assert(calls); + results = (int*) malloc(sz*sizeof(int)); + assert(results); + tmp = lst; + sz = 0; + while (RML_NILHDR != RML_GETHDR(tmp)) { + calls[sz++] = RML_STRINGDATA(RML_CAR(tmp)); + tmp = RML_CDR(tmp); + } +#pragma omp parallel for private(i) schedule(dynamic) + for (i=0; i=0; i--) { + tmp = mk_cons(mk_icon(results[i]),tmp); + } + return tmp; +} + int SystemImpl__spawnCall(const char* path, const char* str) { int ret_val = -1; diff --git a/Examples/BuildModelRecursive.mos b/Examples/BuildModelRecursive.mos index 713998ee75b..ed837a5afdd 100644 --- a/Examples/BuildModelRecursive.mos +++ b/Examples/BuildModelRecursive.mos @@ -1,6 +1,6 @@ // Note: Run with +g=MetaModelica -setCommandLineOptions("+g=Modelica"); +setCommandLineOptions({"+g=Modelica","+d=nogen"}); OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED); log:="BuildModelRecursive.html"; MSLVersion:="3.1"; @@ -36,6 +36,7 @@ deleteClass(Modelica.Utilities); system("rm -f Modelica"); system("ln -fs '"+getInstallationDirectoryPath()+"/lib/omlibrary/Modelica "+MSLVersion+"/' Modelica"); omc:=getInstallationDirectoryPath()+"/bin/omc"; + a:={typeNameString(x) for x guard isExperiment(x) in getClassNames(recursive=true,sort=true)}; getErrorString(); @@ -43,11 +44,15 @@ getErrorString(); print("Number of classes to build: " + String(size(a,1))); system("rm -f Modelica.* " + log); + +/*** This is the stuff executed for each model ***/ + min(writeFile(s + ".mos"," writeFile(\""+log+"\",\""+s+"\n\",append=true); statFile := \""+s+".stat\"; writeFile(statFile,\""+s+"\");getErrorString(); loadModel(Modelica,{\"3.1\"});"+loadModelicaTest+" +setCommandLineOptions(\"+d=nogen\"); res:=buildModel("+s+"); errFile:=\""+s+".err\"; simFile:=\""+s+".sim\"; @@ -98,7 +103,7 @@ str:=\"\" + (if err <> \"\" then \""+s+"\" els writeFile(statFile,str);getErrorString(); ") for s in a); getErrorString(); -min(0==system("ulimit -t "+ulimitOmc+" ; " + omc + " " + s + ".mos") for s in a); +results := system_parallel({"ulimit -t "+ulimitOmc+" ; " + omc + " " + s + ".mos" for s in a}); getErrorString(); echo(false); diff --git a/configure.in b/configure.in index f7ac34ceb83..550ea7c7237 100644 --- a/configure.in +++ b/configure.in @@ -578,9 +578,9 @@ else fi if test "Darwin" != `uname`; then - RT_LDFLAGS="$RT_LDFLAGS -lrt" + RT_LDFLAGS="$RT_LDFLAGS -lrt -fopenmp" else - RT_LDFLAGS="$RT_LDFLAGS -liconv" + RT_LDFLAGS="$RT_LDFLAGS -liconv -fopenmp" fi dnl should we compile modpar @@ -629,6 +629,8 @@ else fi AC_MSG_RESULT([$MODELICA_SPEC_PLATFORM]) +CFLAGS="$CFLAGS" + date=`date "+%Y-%m-%d %H:%M:%S"` GENERATED_AUTOCONF_FILES="Makefile \