@@ -1680,15 +1680,15 @@ algorithm
16801680 HpcOmTaskGraph . TASKGRAPHMETA (inComps= inComps,varCompMapping= varCompMapping,eqCompMapping= eqCompMapping,rootNodes= rootNodes,nodeNames= nodeNames,nodeDescs= nodeDescs,exeCosts= exeCosts,commCosts= commCosts,nodeMark= nodeMark) = iTaskGraphMeta;
16811681
16821682 // dumping stuff-------------------------
1683- print("the simEqSysts1: \n " +& stringDelimitList( List . map(odes, SimCodeUtil . dumpSimEqSystemLst), " \n " ) +& " \n " );
1684- SimCodeUtil . dumpVarLst(algVars, "algVars1" );
1683+ print("simCode1 \n " );
1684+ SimCodeUtil . dumpSimCode(iSimCode );
16851685 print("sccSimEqMap1 \n " );
16861686 HpcOmSimCodeMain . dumpSccSimEqMapping(iSccSimEqMapping);
16871687 print("inComps1 \n " );
16881688 HpcOmSimCodeMain . dumpSccSimEqMapping(inComps);
16891689 // --------------------------------------
16901690
1691- // create new variables and equations for the duplicated tasks
1691+ // prepare everything in order to create new variables and equations for the duplicated tasks
16921692 sizeTasks = List . fold(List . map(clusters,listLength),intAdd,0 );
16931693 taskAss = arrayCreate(sizeTasks,-1 );
16941694 procAss = arrayCreate(listLength(clusters),{});
@@ -1697,34 +1697,25 @@ algorithm
16971697 taskDuplAss = arrayCreate(sizeTasks,-1 ); // the original task for every task (for not duplicated tasks, its itself)
16981698 threadTask = arrayCreate(numProc,{});
16991699 schedule = HpcOmSimCode . THREADSCHEDULE (threadTask,{});
1700- duplSccSimEqMap = {};
1701- duplComps = {};
1700+ duplSccSimEqMap = {}; // a list that is later appended to the sccSimEqMapping
1701+ duplComps = {}; // a list that is later appended to the inComps
17021702 threadIdx = 1 ;
1703- compIdx = List . fold( List . flatten(arrayList(inComps)),intMax, 0 ) + 1 ;
1703+ compIdx = arrayLength(iSccSimEqMapping) + 1 ; // the next available component index
17041704 taskIdx = arrayLength(iTaskGraph)+ 1 ;
1705- simVarIdx = List . fold(List . map(algVars,SimCodeUtil . varIndex),intMax,0 )+ 1 ;
1706- simEqSysIdx = SimCodeUtil . getMaxSimEqSystemIndex(iSimCode)+ 1 ;
1707- lsIdx = List . fold( List . map( List . flatten(odes), SimCodeUtil . getLSindex),intMax, 0 ) + 1 ;
1708- nlsIdx = List . fold(List . map(List . flatten(odes),SimCodeUtil . getNLSindex ),intMax,0 )+ 1 ;
1709- mIdx = List . fold(List . map(List . flatten(odes),SimCodeUtil . getMixedindex ),intMax,0 )+ 1 ;
1710-
1711- print( "TG before" );
1712- HpcOmTaskGraph . printTaskGraph(iTaskGraph);
1705+ simVarIdx = List . fold(List . map(algVars,SimCodeUtil . varIndex),intMax,0 )+ 1 ;// the next available simVar index
1706+ simEqSysIdx = SimCodeUtil . getMaxSimEqSystemIndex(iSimCode)+ 1 ;// the next available simEqSys index
1707+ print( "highest simEqSysIdx: " +& intString(simEqSysIdx) +& " \n " ) ;
1708+ lsIdx = List . fold(List . map(List . flatten(odes),SimCodeUtil . getLSindex ),intMax,0 )+ 1 ;// the next available linear system index
1709+ nlsIdx = List . fold(List . map(List . flatten(odes),SimCodeUtil . getNLSindex ),intMax,0 )+ 1 ;// the next available nonlinear system index
1710+ mIdx = List . fold( List . map( List . flatten(odes), SimCodeUtil . getMixedindex),intMax, 0 ) + 1 ; // the next available mixed system index
1711+
1712+ // traverse the clusters and duplicate tasks if needed
17131713 (taskAss,procAss,taskGraph,taskDuplAss,_,simCode,schedule,duplSccSimEqMap,duplComps) = createTDSduplicateTasks(clusters,taskAss,procAss,(threadIdx,taskIdx,compIdx,simVarIdx,simEqSysIdx,lsIdx,nlsIdx,mIdx),iTaskGraph,taskGraph,taskDuplAss,iTaskGraphMeta,iSimCode,schedule,iSccSimEqMapping,duplSccSimEqMap,duplComps);
1714- print("TG after" );
1715- HpcOmTaskGraph . printTaskGraph(taskGraph);
17161714
17171715 // update stuff
17181716 numDupl = List . fold(List . map(duplComps,listLength),intAdd,0 );
17191717 procAss = Util . arrayMap(procAss,listReverse);
1720- print("duplSccSimEqMap \n " );
1721- HpcOmSimCodeMain . dumpSccSimEqMapping(listArray(duplSccSimEqMap));
1722- print("iSccSimEqMapping \n " );
1723- HpcOmSimCodeMain . dumpSccSimEqMapping(iSccSimEqMapping);
17241718 sccSimEqMap = Util . arrayAppend(iSccSimEqMapping,listArray(listReverse(duplSccSimEqMap)));
1725- print("sccSimEqMap \n " );
1726- HpcOmSimCodeMain . dumpSccSimEqMapping(sccSimEqMap);
1727-
17281719 comps = Util . arrayAppend(inComps,listArray(listReverse(duplComps)));
17291720 varCompMapping = Util . arrayAppend(varCompMapping,arrayCreate(numDupl,(0 ,0 ,0 )));
17301721 eqCompMapping = Util . arrayAppend(eqCompMapping,arrayCreate(numDupl,(0 ,0 ,0 )));
@@ -1735,10 +1726,8 @@ algorithm
17351726 meta = HpcOmTaskGraph . TASKGRAPHMETA (comps,varCompMapping,eqCompMapping,rootNodes,nodeNames,nodeDescs,exeCosts,commCosts,nodeMark);
17361727
17371728 // dumping stuff-------------------------
1738- SimCode . SIMCODE (modelInfo = SimCode . MODELINFO (vars= simVars), odeEquations= odes) = simCode;
1739- print("the simEqSysts2: \n " +& stringDelimitList(List . map(odes,SimCodeUtil . dumpSimEqSystemLst)," \n " )+& " \n " );
1740- SimCode . SIMVARS (algVars= algVars) = simVars;
1741- SimCodeUtil . dumpVarLst(algVars,"algVars2" );
1729+ print("simCode 2 \n " );
1730+ SimCodeUtil . dumpSimCode(simCode);
17421731 print("sccSimEqMap2 \n " );
17431732 HpcOmSimCodeMain . dumpSccSimEqMapping(sccSimEqMap);
17441733 print("inComps2 \n " );
@@ -1902,9 +1891,6 @@ algorithm
19021891 odes = List . map1r(odes,replaceSimEqSystemLstWithSameIndex,simEqSysts);
19031892 simCode = SimCodeUtil . replaceODEandALLequations(allEqs,odes,simCodeIn);
19041893
1905- print("the simEqSysts " +& SimCodeUtil . dumpSimEqSystemLst(simEqSysts)+& " \n " );
1906- print("the simEqSysts after cluster: " +& intString(threadIdx)+& "_" +& intString(node)+& " \n " +& stringDelimitList(List . map(odes,SimCodeUtil . dumpSimEqSystemLst)," \n " )+& " \n " );
1907-
19081894 task = HpcOmSimCode . CALCTASK (1 ,node,0 . 0 ,-1 . 0 ,threadIdx,simEqs);
19091895 thread = task::threadIn;
19101896 taskDuplAss = arrayUpdate(taskDuplAssIn,node,node);
@@ -1941,8 +1927,8 @@ protected function createTDSduplicateTasks2"sets the information about the new t
19411927 output list< list< Integer >> duplCompsOut;
19421928protected
19431929 String crefAppend;
1944- Integer threadIdx,compIdx,simVarIdx,simVarIdx2,simEqSysIdx,simEqSysIdx2,numVars,numEqs,taskIdx,lsIdx,nlsIdx,mIdx;
1945- list< Integer > comps,simEqSysIdcs,simVarSysIdcs,simEqSysIdcs2,simVarSysIdcs2,thread,origSuccTasks,clSuccTasks;
1930+ Integer threadIdx,compIdx,simVarIdx,simVarIdx2,simEqSysIdx,simEqSysIdx2,simEqSysIdx3, numVars,numEqs,numInitEqs ,taskIdx,lsIdx,nlsIdx,mIdx;
1931+ list< Integer > comps,simEqSysIdcs,simVarSysIdcs,simEqSysIdcs2,simEqSysIdcsInit, simVarSysIdcs2,thread,origSuccTasks,clSuccTasks;
19461932 list< list< Integer >> simEqIdxLst,simVarIdxLst;
19471933 array< list< Integer >> inComps;
19481934 BackendVarTransform . VariableReplacements repl;
@@ -1951,11 +1937,13 @@ protected
19511937 SimCode . ModelInfo modelinfo;
19521938 SimCode . SimVars simVars;
19531939 SimCode . SimCode simCode;
1940+ list< BackendDAE . Equation > eqs;
1941+ list< BackendDAE . Var > vars;
19541942 list< DAE . ComponentRef > crefs,crefsDupl;
19551943 list< list< DAE . ComponentRef >> crefLst;
19561944 list< DAE . Exp > crefsDuplExp;
19571945 list< SimCode . SimVar > simVarLst,simVarDupl,algVars;
1958- list< SimCode . SimEqSystem > simEqSysts,simEqSystsDupl;
1946+ list< SimCode . SimEqSystem > simEqSysts,simEqSystsDupl,initEqs ;
19591947 list< list< SimCode . SimEqSystem >> odes;
19601948algorithm
19611949 HpcOmTaskGraph . TASKGRAPHMETA (inComps= inComps) := iTaskGraphMeta;
@@ -2000,21 +1988,30 @@ algorithm
20001988 // BackendVarTransform.dumpReplacements(repl);
20011989 numEqs := listLength(simEqSysts);
20021990 simEqSysIdcs2 := List . intRange2(simEqSysIdx,simEqSysIdx+ numEqs- 1 );
2003-
1991+ print( "simEqSysIdcs2 :" +& intListString(simEqSysIdcs2) +& " \n " );
20041992 (simEqSystsDupl,_) := List . map1_2(simEqSysts,replaceExpsInSimEqSystem,repl);// replace the exps and crefs
20051993 (simEqSystsDupl,(lsIdx,nlsIdx,mIdx)) := List . mapFold(simEqSystsDupl,replaceSystemIndex,(lsIdx,nlsIdx,mIdx));// udpate the indeces of th systems
20061994 simEqSystsDupl := List . threadMap(simEqSystsDupl,simEqSysIdcs2,SimCodeUtil . replaceSimEqSysIndex);
20071995 print("the simEqSystsDupl " +& SimCodeUtil . dumpSimEqSystemLst(simEqSystsDupl)+& " \n " );
2008- simCode := List . fold1(simEqSystsDupl,SimCodeUtil . addSimEqSysToODEquations,1 ,simCode);
20091996 simEqSysIdx2 := simEqSysIdx + numEqs;
2010- print("simEqSysIdcs2 :" +& intListString(simEqSysIdcs2)+& " \n " );
2011-
2012- SimCode . SIMCODE (odeEquations= odes) := simCode;
2013- print("the simEqSysts after cluster: " +& intString(threadIdx)+& "_" +& intString(node)+& " \n " +& stringDelimitList(List . map(odes,SimCodeUtil . dumpSimEqSystemLst)," \n " )+& " \n " );
1997+ // update sccSimEqmapping for the duplicated
1998+ duplSccSimEqMapOut := listAppend(List . map(simEqSysIdcs2,List . create),duplSccSimEqMapIn);
1999+ simCode := List . fold1(simEqSystsDupl,SimCodeUtil . addSimEqSysToODEquations,1 ,simCode);
2000+ // set task in thread
2001+ threadOut := HpcOmSimCode . CALCTASK (1 ,taskIdx,0 . 0 ,-1 . 0 ,threadIdx,simEqSysIdcs2)::threadIn;
2002+ // add init eqs to simCode
2003+ numInitEqs := listLength(crefs);
2004+ simEqSysIdcsInit := List . intRange2(simEqSysIdx2,simEqSysIdx2+ numInitEqs- 1 );
2005+ initEqs := List . thread3Map(crefsDupl,crefs,simEqSysIdcsInit,makeSEScrefAssignment);
2006+ print("the initEqs " +& SimCodeUtil . dumpSimEqSystemLst(initEqs)+& " \n " );
2007+ simCode := List . fold(initEqs,SimCodeUtil . addSimEqSysToInitialEquations,simCode);
2008+ simEqSysIdx3 := simEqSysIdx2 + numInitEqs;
2009+
2010+ SimCode . SIMCODE (odeEquations= odes) := simCode;
2011+ print("the simEqSysts after cluster: " +& intString(threadIdx)+& "_" +& intString(node)+& " \n " +& stringDelimitList(List . map(odes,SimCodeUtil . dumpSimEqSystemLst)," \n " )+& " \n " );
20142012
20152013 // update duplSccSimEqMap, duplComps, taskAss, procAss for the new duplicates
2016- duplSccSimEqMapOut := listAppend(List . map(simEqSysIdcs2,List . create),duplSccSimEqMapIn);
2017- taskAssOut := arrayUpdate(taskAssIn,taskIdx,threadIdx);
2014+ taskAssOut := arrayUpdate(taskAssIn,taskIdx,threadIdx);
20182015 thread := arrayGet(procAssIn,threadIdx);
20192016 thread := taskIdx::thread;
20202017 procAssOut := arrayUpdate(procAssIn,threadIdx,thread);
@@ -2023,9 +2020,6 @@ algorithm
20232020 compIdx := compIdx+ listLength(comps);
20242021 duplCompsOut := comps::duplCompsIn;
20252022
2026- // set task in thread
2027- threadOut := HpcOmSimCode . CALCTASK (1 ,taskIdx,0 . 0 ,-1 . 0 ,threadIdx,simEqSysIdcs2)::threadIn;
2028-
20292023 // update taskGraph and taskDuplAss
20302024 taskDuplAssOut := arrayUpdate(taskDuplAssIn,taskIdx,node);
20312025 origSuccTasks := arrayGet(taskGraphIn,node);
@@ -2034,11 +2028,23 @@ algorithm
20342028 taskGraph := arrayUpdate(taskGraphIn,node,origSuccTasks);
20352029 taskGraphOut := arrayUpdate(taskGraph,taskIdx,clSuccTasks);
20362030
2037- idcsOut := (threadIdx,taskIdx+ 1 ,compIdx,simVarIdx2,simEqSysIdx2 ,lsIdx,nlsIdx,mIdx);
2031+ idcsOut := (threadIdx,taskIdx+ 1 ,compIdx,simVarIdx2,simEqSysIdx3 ,lsIdx,nlsIdx,mIdx);
20382032 simCodeOut := simCode;
20392033 replOut := repl;
20402034end createTDSduplicateTasks2;
20412035
2036+ protected function makeSEScrefAssignment
2037+ input DAE . ComponentRef lhs;
2038+ input DAE . ComponentRef rhs;
2039+ input Integer idx;
2040+ output SimCode . SimEqSystem sesOut;
2041+ protected
2042+ DAE . Type ty;
2043+ algorithm
2044+ ty := ComponentReference . crefType(rhs);
2045+ sesOut := SimCode . SES_SIMPLE_ASSIGN (idx,lhs,DAE . CREF (rhs,ty),DAE . emptyElementSource);
2046+ end makeSEScrefAssignment;
2047+
20422048protected function replaceSimEqSystemLstWithSameIndex
20432049 input list< SimCode . SimEqSystem > eqSystsIn;
20442050 input list< SimCode . SimEqSystem > eqSysLstIn;
@@ -2206,17 +2212,17 @@ algorithm
22062212 then (simEqSys,changed);
22072213 case (SimCode . SES_WHEN (index= idx,conditions= crefs,initialCall= ic,left= cref,right= exp,elseWhen= NONE (),source= source),_)
22082214 equation
2209- (crefs,bLst) = List . map1_2(crefs,replaceCref,replIn);
2210- (cref,changed) = replaceCref(cref,replIn);
2215+ (crefs,bLst) = List . map1_2(crefs,BackendVarTransform . replaceCref,replIn);
2216+ (cref,changed) = BackendVarTransform . replaceCref(cref,replIn);
22112217 changed = List . fold(bLst,boolOr,changed);
22122218 (exp,changed1) = BackendVarTransform . replaceExp(exp,replIn,NONE ());
22132219 changed = boolOr(changed,changed1);
22142220 simEqSys = SimCode . SES_WHEN (idx,crefs,ic,cref,exp,NONE (),source);
22152221 then (simEqSys,changed);
22162222 case (SimCode . SES_WHEN (index= idx,conditions= crefs,initialCall= ic,left= cref,right= exp,elseWhen= SOME (simEqSys),source= source),_)
22172223 equation
2218- (crefs,bLst) = List . map1_2(crefs,replaceCref,replIn);
2219- (cref,changed) = replaceCref(cref,replIn);
2224+ (crefs,bLst) = List . map1_2(crefs,BackendVarTransform . replaceCref,replIn);
2225+ (cref,changed) = BackendVarTransform . replaceCref(cref,replIn);
22202226 changed = List . fold(bLst,boolOr,changed);
22212227 (exp,changed1) = BackendVarTransform . replaceExp(exp,replIn,NONE ());
22222228 changed = boolOr(changed,changed1);
@@ -2231,24 +2237,6 @@ algorithm
22312237 end matchcontinue;
22322238end replaceExpsInSimEqSystem;
22332239
2234- protected function replaceCref"replaces a cref.
2235- author: Waurich TUD 2014-06"
2236- input DAE . ComponentRef crefIn;
2237- input BackendVarTransform . VariableReplacements replIn;
2238- output DAE . ComponentRef crefOut;
2239- output Boolean changedOut;
2240- algorithm
2241- (crefOut,changedOut) := matchcontinue(crefIn,replIn)
2242- case (_,_)
2243- equation
2244- true = BackendVarTransform . hasReplacement(replIn,crefIn);
2245- DAE . CREF (componentRef= crefOut) = BackendVarTransform . getReplacement(replIn,crefIn);
2246- then (crefOut,true );
2247- else
2248- then (crefIn,false );
2249- end matchcontinue;
2250- end replaceCref;
2251-
22522240protected function replaceCrefInSimVar"performs replacements on a simVar structure.
22532241author: Waurich TUD 2014-06"
22542242 input SimCode . SimVar simVarIn;
0 commit comments