Skip to content

Commit

Permalink
Simulation paralleization support with parmodauto (#6825)
Browse files Browse the repository at this point in the history
@mahge
Fix serialization
a894bea

  - Traversal now handles der, pre, previous ...
    properly, i.e., treats them as crefs instead of calls.

@mahge
Update ParModAuto sources.
4c135b3

  - There are so many changes here.
  - Capability for monitoring and rescheduling added.
  - Use JSON instead of XML
  - updated compilation settings. e.g. use GC_THREADS from the
    compilation command instead of defining it in the files.

  - many other fixes and changes.

@mahge
Move parmodauto flag from debug to config flags.
724a4ab

  - It is now used as --parmodauto instead of -d=parmodauto

@mahge
Remove unused parmodelica code.
f78687c

  - We do not try to parallelize all the systems anymore.
    We only parallelize ODE system for now. So cleanup the rest.

@mahge
Update the code gen for the updated interface.
f5b3713

  - We now use a global model variable in the C code.
  - Pass this global variable to the C interface functions.
    Basically acts as the 'this' argument for the C++ counterparts
    of the functions.

@mahge
Changed dumping of linear torn systems
8ecba32

  - The internal equations are now dumped as fields of the main equation.
    They used to be dumped before the actual equation which made parsing them contrived.

  - Diabled old parsing and wrote a new one since the dump format has changed.
    In order to avoid surprises, we stick to parsing only what we know we can handle for now.

  - Disabled source dumping for now. It is not really needed anyway.
  - Normalized debug and log dumping a bit.

@mahge
Move ParModAuto library handling to SimCode
61a1c64

  - Move the managment of ParModAuto libs out of the templates
    The templates was not the right place to do this.
    We should do things in SimCode when possible.

@mahge
Clean up to avoid warnings
49add1b
@mahge
Restructure parsing of task system json dump.
d497cec

  - Parsing is more structured and are a bit cleaner now.

  - Try to make sure we fail on anything that we have not
    vetted manudally and are sure we are handling properly.

    Since some of the format for linear/non-linear as well as
    dynamic/non-dynamic tearing combinations can be similar
    it is easy to parse something by miskae as something else.

@mahge
Changed dumping of non-linear systems
30d7d3e
  
  - Updated dumping of non-linear [torn] systems with NO alternative
      tearing.

  - The internal equations are now dumped as fields of the main equation.
      They used to be dumped before the actual equation which made parsing them contrived.

  - This is similar to 54ce151

@mahge
Add a separate file for tasksystem serialization.
9134a76

  - Unfortunately we need to dump the task syste a bit different from
    from the dbug dump for a number of reasons:
     - We need to simplify things so that it is convenient to parse it later.
     - We also have a different function for extracting crefs from expressions.
       this treats der(x), pre(x) .. 'correctly' as differnt crefs from x.
     - There is a lot of information that is not need for paraellization
       that is dumped by the original serialization. So this helps us in
       striping that information without affecting the debugging.

  - Removed the old XML task system dumping which is not not used anymore.

@mahge
Allow parsing of single output algorithms.
e890be6

  - Multiple output algorithms will be checked
    again and allowed later.

@mahge
Refactor and format all source files.
0724dc4

@mahge
Always build debug version om parmodauto for now.
b068c06

  - I hope I won't forget to change this later.

@mahge
Cleanup and normalize the makefiles.
83a972d

@mahge
Explicitly link to boost system
d5e172e

@mahge
Fix TBB include path.
1f57456

  - TBB is now assumed to be in `OMCompiler/3rdParty/tbb` instead of
    `OMCompiler/3rdParty/tbb_cmake`


@mahge
Add parmodauto configure/build to omc compilation.
4d124ad

  - parmodauto con now be enabled with --enable-parmodauto during
    configuration of OpenModelica.

  - This will check for the existence of modified TBB sources in
    3rdParty/tbb_omc and if will fail if the directory does not exist.

  - If it exists, omc_tbb will be configured using cmake during
    OpenModelica's autoconf configuration.

  - configuration will set two new variables ENABLE_PARMODAUTO and
    OMC_TBB_ROOT. These values are used to enable parmodauto compilation
    and find TBB source directory respectively.

@mahge
Fix cmake compilation.
d9b9a66

  - Add new file and remove old file from MM sources list.

@mahge
Specify number of threads during pm model creation
20b24c4

  - This used to be set during compilation. That was find for testing but
    for general usage it should be settable during simulation time.

  - It is still recommended to just let the system pick the number of
    threads unless you have specific reasons to do otherwise, e.g. comparing
    performance for research reasons.

@mahge
Add parmodauto to OMCompiler's CMake compilation.
06f5b5f
@mahge
If parmodauto link using g++.
1192d7d

  - We need to either compile with g++ or explicitly link to libstdc++.
    I think it is better to let g++ do its full c++ thing instead of
    linking just libstdc++ only.

@mahge
Propagate maximum number of threads.
7035b01

  - This is preparation to be able to set the desired number of threads
    at simulation start.

    Now the max number of threads to be used at any time can be set with
    the interface function PM_Model_create() when the parmodauto model
    representation is created by the OpenModelica simulation executable
    code.

    The maximum number of threads is passed to TBB by OMModel constructor
    using tbb::task_scheduler_init.

@mahge
Do not install om_pm_model.hpp.
69383d9

  - It is not needed. Just the interface file om_pm_interface.hpp is enough.
    If needed we will add it later.
  • Loading branch information
mahge committed Oct 31, 2020
1 parent 5817e91 commit 2ecc837
Show file tree
Hide file tree
Showing 48 changed files with 4,364 additions and 4,069 deletions.
1 change: 0 additions & 1 deletion OMCompiler/.gitignore
Expand Up @@ -139,7 +139,6 @@ Compiler/Template/MMToJulia.mo
Compiler/Template/NFInstDumpTpl.mo
Compiler/Template/SCodeDumpTpl.mo
Compiler/Template/SimCodeDump.mo
Compiler/Template/TaskSystemDump.mo
Compiler/Template/TplCodegen.mo
Compiler/Template/Unparsing.mo
Compiler/Template/VisualXMLTpl.mo
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/.cmake/meta_modelica_source_list.cmake
Expand Up @@ -378,6 +378,7 @@ set(OMC_MM_BACKEND_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/HpcOmSimCodeMain.mo
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/SerializeInitXML.mo
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/SerializeModelInfo.mo
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/SerializeTaskSystemInfo.mo
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/SimCode.mo
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/SimCodeMain.mo
${CMAKE_CURRENT_SOURCE_DIR}/SimCode/SimCodeUtil.mo
Expand Down Expand Up @@ -419,7 +420,6 @@ set(OMC_MM_BACKEND_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/Template/GraphMLDumpTpl.mo
${CMAKE_CURRENT_SOURCE_DIR}/Template/NFInstDumpTpl.mo
${CMAKE_CURRENT_SOURCE_DIR}/Template/SimCodeDump.mo
${CMAKE_CURRENT_SOURCE_DIR}/Template/TaskSystemDump.mo
${CMAKE_CURRENT_SOURCE_DIR}/Template/VisualXMLTpl.mo

${CMAKE_CURRENT_SOURCE_DIR}/Util/AvlTree.mo
Expand Down
144 changes: 76 additions & 68 deletions OMCompiler/Compiler/FrontEnd/Expression.mo
Expand Up @@ -6129,6 +6129,15 @@ algorithm
outDims := if outChanged then listReverse(outDims) else inDims;
end traverseExpTypeDims2;

public function extractUniqueCrefsFromExp
"Extracts all unique ComponentRef from an Expression."
input DAE.Exp inExp;
output list<DAE.ComponentRef> ocrefs;
algorithm
// ocrefs := List.unique(List.flatten(List.map1(extractCrefsFromExp(inExp), ComponentReference.expandCref, true)));
ocrefs := List.unique(extractCrefsFromExp(inExp));
end extractUniqueCrefsFromExp;

public function extractCrefsFromExp "
Author: BZ 2008-06, Extracts all ComponentRef from an Expression."
input DAE.Exp inExp;
Expand All @@ -6137,14 +6146,37 @@ algorithm
(_,ocrefs) := traverseExpBottomUp(inExp, traversingComponentRefFinder, {});
end extractCrefsFromExp;

public function extractUniqueCrefsFromExp
"Extracts all unique ComponentRef from an Expression."
public function traversingComponentRefFinder "
Author: BZ 2008-06
Exp traverser that Union the current ComponentRef with list if it is already there.
Returns a list containing, unique, all componentRef in an Expression."
input DAE.Exp inExp;
input list<DAE.ComponentRef> inCrefs;
output DAE.Exp outExp;
output list<DAE.ComponentRef> crefs;
algorithm
(outExp,crefs) := match (inExp,inCrefs)
local
ComponentRef cr;
case (DAE.CREF(componentRef=cr), crefs)
equation
crefs = List.unionEltOnTrue(cr,crefs,ComponentReference.crefEqual);
then (inExp,crefs);
else (inExp,inCrefs);
end match;
end traversingComponentRefFinder;

public function extractUniqueCrefsFromExpDerPreStart
"author mahge: Same as extractUniqueCrefsFromExp except:
This function will not treat der(), pre() and start() as calls
but as unique ids. i.e. x is different from der(x) and given der(x) x will not
be extreacted as a unique id. Instead you get $DER.x. Same oes for pre and start.."
input DAE.Exp inExp;
output list<DAE.ComponentRef> ocrefs;
algorithm
// ocrefs := List.unique(List.flatten(List.map1(extractCrefsFromExp(inExp), ComponentReference.expandCref, true)));
ocrefs := List.unique(extractCrefsFromExp(inExp));
end extractUniqueCrefsFromExp;
ocrefs := List.unique(extractCrefsFromExpDerPreStart(inExp));
end extractUniqueCrefsFromExpDerPreStart;

public function extractCrefsFromExpDerPreStart
" author mahge: Same as extractCrefsFromExp except:
Expand All @@ -6154,21 +6186,49 @@ public function extractCrefsFromExpDerPreStart
input DAE.Exp inExp;
output list<DAE.ComponentRef> ocrefs;
algorithm
(_,ocrefs) := traverseExpDerPreStart(inExp, traversingComponentRefFinder, {});
(_,ocrefs) := traverseExpTopDown(inExp, traversingComponentRefFinderDerPreStart, {});
end extractCrefsFromExpDerPreStart;

public function extractUniqueCrefsFromExpDerPreStart
"author mahge: Same as extractUniqueCrefsFromExp except:
This function will not treat der(), pre() and start() as calls
but as unique ids. i.e. x is different from der(x) and given der(x) x will not
be extreacted as a unique id. Instead you get $DER.x. Same oes for pre and start.."
public function traversingComponentRefFinderDerPreStart "
"
input DAE.Exp inExp;
output list<DAE.ComponentRef> ocrefs;
input list<DAE.ComponentRef> inCrefs;
output DAE.Exp e;
output Boolean cont;
output list<DAE.ComponentRef> crefs;
algorithm
// ocrefs := List.unique(List.flatten(List.map1(extractCrefsFromExp(inExp), ComponentReference.expandCref, true)));
ocrefs := List.unique(extractCrefsFromExpDerPreStart(inExp));
end extractUniqueCrefsFromExpDerPreStart;
(e,cont,crefs) := match (inExp,inCrefs)
local
ComponentRef cr;
case (DAE.CREF(componentRef=cr), crefs)
algorithm
crefs := List.unionEltOnTrue(cr,inCrefs,ComponentReference.crefEqual);
then (inExp, false, crefs);

case (DAE.CALL(path = Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr)}),_) algorithm
cr := ComponentReference.crefPrefixDer(cr);
crefs := List.unionEltOnTrue(cr,inCrefs,ComponentReference.crefEqual);
then (inExp, false, crefs);

case (DAE.CALL(path = Absyn.IDENT(name="pre"), expLst={DAE.CREF(componentRef=cr)}),_) algorithm
cr := ComponentReference.crefPrefixPre(cr);
crefs := List.unionEltOnTrue(cr,inCrefs,ComponentReference.crefEqual);
then (inExp, false, crefs);

case (DAE.CALL(path = Absyn.IDENT(name="previous"), expLst={DAE.CREF(componentRef=cr)}),_) algorithm
cr := ComponentReference.crefPrefixPrevious(cr);
crefs := List.unionEltOnTrue(cr,inCrefs,ComponentReference.crefEqual);
then (inExp, false, crefs);

case (DAE.CALL(path = Absyn.IDENT(name="start"), expLst={DAE.CREF(componentRef=cr)}),_) algorithm
Error.addInternalError(getInstanceName() + " - Found a start call expression " + ExpressionDump.printExpStr(inExp), sourceInfo());
cr := ComponentReference.crefPrefixStart(cr);
crefs := List.unionEltOnTrue(cr,inCrefs,ComponentReference.crefEqual);
then (inExp, false, crefs);

else (inExp,true,inCrefs);
end match;
end traversingComponentRefFinderDerPreStart;

public function extractUniqueCrefsFromStatmentS
"authot mahge: Extracts all unique ComponentRef from Statments."
Expand Down Expand Up @@ -6373,26 +6433,6 @@ algorithm
end match;
end traversingComponentRefPresent;

public function traversingComponentRefFinder "
Author: BZ 2008-06
Exp traverser that Union the current ComponentRef with list if it is already there.
Returns a list containing, unique, all componentRef in an Expression."
input DAE.Exp inExp;
input list<DAE.ComponentRef> inCrefs;
output DAE.Exp outExp;
output list<DAE.ComponentRef> crefs;
algorithm
(outExp,crefs) := match (inExp,inCrefs)
local
ComponentRef cr;
case (DAE.CREF(componentRef=cr), crefs)
equation
crefs = List.unionEltOnTrue(cr,crefs,ComponentReference.crefEqual);
then (inExp,crefs);
else (inExp,inCrefs);
end match;
end traversingComponentRefFinder;

public function traversingComponentRefFinderNoPreDer "
Author: BZ 2008-06
Exp traverser that Union the current ComponentRef with list if it is already there.
Expand All @@ -6417,40 +6457,6 @@ algorithm
end match;
end traversingComponentRefFinderNoPreDer;

public function traversingDerAndComponentRefFinder "
Author: Frenkel TUD 2012-06
Exp traverser that Union the current ComponentRef with list if it is already there.
Returns a list containing, unique, all componentRef in an Expression and a second list
containing all componentRef from a der function."
input tuple<DAE.Exp, tuple<list<DAE.ComponentRef>,list<DAE.ComponentRef>>> inExp;
output tuple<DAE.Exp, tuple<list<DAE.ComponentRef>,list<DAE.ComponentRef>>> outExp;
algorithm
outExp := matchcontinue(inExp)
local
list<DAE.ComponentRef> crefs,dcrefs;
ComponentRef cr;
Type ty;
DAE.Exp e;

case((e as DAE.CREF(cr,_), (crefs,dcrefs)))
equation
crefs = List.unionEltOnTrue(cr,crefs,ComponentReference.crefEqual);
// e = makeCrefExp(cr,ty);
then
((e, (crefs,dcrefs) ));

case((e as DAE.CALL(path = Absyn.IDENT(name = "der"),expLst={DAE.CREF(cr,_)}), (crefs,dcrefs)))
equation
dcrefs = List.unionEltOnTrue(cr,dcrefs,ComponentReference.crefEqual);
// e = makeCrefExp(cr,ty);
then
((e, (crefs,dcrefs) ));

else inExp;

end matchcontinue;
end traversingDerAndComponentRefFinder;

public function expHasCref "author: Frenkel TUD 2011-04
returns true if the expression contains the cref"
input DAE.Exp inExp;
Expand Down Expand Up @@ -11730,6 +11736,7 @@ algorithm
end matchcontinue;
end isCrefListWithEqualIdents;

/*
protected function traverseExpDerPreStart
" TODO: REPLACE THIS ABOMINATION WITH A BETTER traverseExpBottomUp
Expand Down Expand Up @@ -12106,6 +12113,7 @@ algorithm
then (expl,ext_arg);
end match;
end traverseExpDerPreStartList;
*/

public function renameExpCrefIdent
input DAE.Exp inExp;
Expand Down

0 comments on commit 2ecc837

Please sign in to comment.