node->DynParaLoop::accept(this);
writeSimpleDataLinks(node);
writeSimpleStreamLinks(node);
- _out << indent(depth) << "</foreach>" << endl;
+ _out << indent(depth) << "</foreachdyn>" << endl;
endCase(node);
DEBTRACE("END visitForEachLoopDyn " << _root->getChildName(node));
}
for (list<Node*>::iterator ic = setOfChildren.begin(); ic != setOfChildren.end(); ++ic)
// add "splitter" node of ForEachLoop nodes to the set of children
- if ( dynamic_cast<ForEachLoop*>( *ic ) )
+ if ( dynamic_cast<ForEachLoopGen*>( *ic ) )
{
Node *nodeToInsert=(*ic)->getChildByName(ForEachLoop::NAME_OF_SPLITTERNODE);
if(find(setOfChildrenPlusSplitters.begin(),setOfChildrenPlusSplitters.end(),nodeToInsert)==setOfChildrenPlusSplitters.end())
DEBTRACE( "BINGO!" );
string fromName;
- if ( dynamic_cast<SplitterNode*>(from) && dynamic_cast<ForEachLoop*>(from->getFather()) )
+ if ( dynamic_cast<SplitterNode*>(from) && dynamic_cast<ForEachLoopGen*>(from->getFather()) )
fromName = from->getFather()->getName();
else
fromName = node->getChildName(from);
string childName;
- if ( dynamic_cast<SplitterNode*>(to) && dynamic_cast<ForEachLoop*>(to->getFather()) )
+ if ( dynamic_cast<SplitterNode*>(to) && dynamic_cast<ForEachLoopGen*>(to->getFather()) )
childName = node->getChildName(to->getFather());
else
childName = node->getChildName(to);
virtual void node (ENGINE::InlineNode* const& n);
virtual void forloop (ENGINE::ForLoop* const& b);
virtual void foreach (ENGINE::ForEachLoop* const& b);
+ virtual void foreachdyn (ENGINE::ForEachLoopDyn* const& b);
virtual void optimizer (ENGINE::OptimizerLoop* const& b);
virtual void while_ (ENGINE::WhileLoop* const& b);
virtual void switch_ (ENGINE::Switch* const& b);
currentProc->nodeMap[fullname]=b->getChildByShortName("splitter");
}
template <class T>
+void looptypeParser<T>::foreachdyn (ENGINE::ForEachLoopDyn* const& b)
+{
+ DEBTRACE("loop_foreachdyn" << b->getName())
+ _cnode->edSetNode(b);
+ std::string fullname=currentProc->names.back()+ b->getName();
+ currentProc->nodeMap[fullname]=b;
+ fullname += ".splitter";
+ currentProc->nodeMap[fullname]=b->getChildByShortName("splitter");
+}
+template <class T>
void looptypeParser<T>::optimizer (ENGINE::OptimizerLoop* const& b)
{
DEBTRACE( "loop_optimizer: " << b->getName() );
template <class T> foreachlooptypeParser<T> foreachlooptypeParser<T>::foreachloopParser;
+//FIXME
+template <class T=ENGINE::ForEachLoopDyn*>
+struct foreachloopdyntypeParser:dynparalooptypeParser<T>
+{
+ static foreachloopdyntypeParser<T> foreachloopdynParser;
+
+ virtual void buildAttr(const XML_Char** attr)
+ {
+ if (!attr)
+ return;
+ this->required("name",attr);
+ this->required("type",attr);
+ for (int i = 0; attr[i]; i += 2)
+ {
+ if(std::string(attr[i]) == "name")name(attr[i+1]);
+ if(std::string(attr[i]) == "state")this->state(attr[i+1]);
+ if(std::string(attr[i]) == "nbranch")nbranch(atoi(attr[i+1]));
+ if(std::string(attr[i]) == "loopWeight")weight(atof(attr[i+1]));
+ if(std::string(attr[i]) == "type")datatype(attr[i+1]);
+ }
+ postAttr();
+ }
+ virtual void pre ()
+ {
+ _nbranch=0;
+ _weight=-1.;
+ this->looptypeParser<T>::pre();
+ }
+ virtual void name (const std::string& name)
+ {
+ DEBTRACE("foreach_name: " << name)
+ _name=name;
+ _fullname=currentProc->names.back()+name;
+ }
+ virtual void nbranch (const int& n)
+ {
+ DEBTRACE("foreach_nbranch: " << n )
+ _nbranch=n;
+ }
+ virtual void weight (const double& x)
+ {
+ DEBTRACE("foreach_weight: " << x )
+ _weight=x;
+ }
+ virtual void datatype (const std::string& type)
+ {
+ DEBTRACE("foreach_datatype: "<< type)
+ _datatype=type;
+ }
+ virtual void postAttr()
+ {
+ if(currentProc->typeMap.count(_datatype)==0)
+ {
+ //Check if the typecode is defined in the runtime
+ YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(_datatype);
+ if(t==0)
+ {
+ std::stringstream msg;
+ msg << "Type "<< _datatype <<" does not exist"<<" ("<<__FILE__<<":"<<__LINE__<< ")";
+ throw Exception(msg.str());
+ }
+ else
+ {
+ currentProc->typeMap[_datatype]=t;
+ t->incrRef();
+ }
+ }
+ this->_cnode=theRuntime->createForEachLoopDyn(_name,currentProc->typeMap[_datatype]);
+ //set number of branches
+ if(_nbranch > 0)this->_cnode->edGetNbOfBranchesPort()->edInit(_nbranch);
+ if(_weight > 0)this->_cnode->setWeight(_weight);
+ this->_cnodes.push_back(this->_cnode);
+ currentProc->names.push_back(_fullname + '.');
+ }
+ virtual T post()
+ {
+ DEBTRACE("foreach_post" << this->_cnode->getName())
+ T b=this->_cnode;
+ this->_cnodes.pop_back();
+ currentProc->names.pop_back();
+ this->_cnode=this->_cnodes.empty() ? 0 : this->_cnodes.back();
+ return b;
+ }
+ int _nbranch;
+ double _weight;
+ std::string _fullname;
+ std::string _name;
+ std::string _datatype;
+};
+
+template <class T> foreachloopdyntypeParser<T> foreachloopdyntypeParser<T>::foreachloopdynParser;
}
namespace YACS
this->maxcount("node",1,element);
this->maxcount("forloop",1,element);
this->maxcount("foreach",1,element);
+ this->maxcount("foreachdyn",1,element);
this->maxcount("optimizer",1,element);
this->maxcount("while",1,element);
this->maxcount("switch",1,element);
else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
else if(element == "foreach")pp=&foreachlooptypeParser<>::foreachloopParser;
+ else if(element == "foreachdyn")pp=&foreachloopdyntypeParser<>::foreachloopdynParser;
else if(element == "optimizer")pp=&optimizerlooptypeParser<>::optimizerloopParser;
else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
else if(element == "switch")pp=&switchtypeParser::switchParser;
else if(element == "forloop")forloop(((forlooptypeParser<>*)child)->post());
else if(element == "foreach")foreach(((foreachlooptypeParser<>*)child)->post());
+ else if(element == "foreachdyn")foreachdyn(((foreachloopdyntypeParser<>*)child)->post());
else if(element == "optimizer")optimizer(((optimizerlooptypeParser<>*)child)->post());
else if(element == "while")while_(((whilelooptypeParser<>*)child)->post());
else if(element == "switch")switch_(((switchtypeParser*)child)->post());
import pilot
import SALOMERuntime
import loader
+import datetime
+fname="testFEDyn.xml"
+fname2="REtestFEDyn.xml"
SALOMERuntime.RuntimeSALOME.setRuntime()
+l=loader.YACSLoader()
r=SALOMERuntime.getSALOMERuntime()
p=r.createProc("prTest1")
td=p.createType("double","double")
o0=n0.edAddOutputPort("o0",tsi)
n0.setScript("o0=[ elt for elt in range(8) ]")
p.edAddChild(n0)
-n1=r.createForEachLoopDyn("n1",ti)
+n1=r.createForEachLoop("n1",ti)#Dyn
+n1.getInputPort("nbBranches").edInitPy(2)
n10=r.createScriptNode("","n10")
n10.setExecutionMode("remote")
n10.setContainer(cont)
n1.edAddChild(n10)
n10.setScript("""
import time
-time.sleep(2)
+time.sleep(1)
o2=2*i1
""")
-n10.setWeight(4.)
i1=n10.edAddInputPort("i1",ti)
o2=n10.edAddOutputPort("o2",ti)
p.edAddChild(n1)
n2=r.createScriptNode("","n2")
n2.setScript("o4=i3")
i3=n2.edAddInputPort("i3",tsi)
+i4=n2.edAddInputPort("i4",tsi)
o4=n2.edAddOutputPort("o4",tsi)
-n2.setScript("o4=i3")
+n2.setScript("o4=[a+b for a,b in zip(i3,i4)]")
p.edAddChild(n2)
p.edAddCFLink(n1,n2)
p.edAddLink(o2,i3)
-#p.saveSchema(fname)
-#p=l.load(fname)
-ex=pilot.ExecutorSwig()
+# Second parallel foreach
+n11=r.createForEachLoop("n11",ti)#Dyn
+n11.getInputPort("nbBranches").edInitPy(2)
+n110=r.createScriptNode("","n110")
+n110.setExecutionMode("remote")
+n110.setContainer(cont)
+n11.edAddChild(n110)
+n110.setScript("""
+import time
+time.sleep(10)
+o2=3*i1
+""")
+i1_1=n110.edAddInputPort("i1",ti)
+o2_1=n110.edAddOutputPort("o2",ti)
+p.edAddChild(n11)
+p.edAddLink(o0,n11.edGetSeqOfSamplesPort())
+p.edAddLink(n11.edGetSamplePort(),i1_1)
+p.edAddCFLink(n0,n11)
+p.edAddCFLink(n11,n2)
+p.edAddLink(o2_1,i4)
+#
+p.saveSchema(fname)
+p=l.load(fname)
+p.saveSchema(fname2)
+p.init()
+"""ex=pilot.ExecutorSwig()
assert(p.getState()==pilot.READY)
+stt = datetime.datetime.now()
ex.RunW(p,0)
+print(str(datetime.datetime.now()-stt))
assert(p.getState()==pilot.DONE)
-assert(o4.getPyObj()==[0, 2, 4, 6, 8, 10, 12, 14])
+assert(o4.getPyObj()==[0, 5, 10, 15, 20, 25, 30, 35])"""
+# Ideal ForEachDyn time = 22 s
+# ForEach time = 40 s"""
\ No newline at end of file