/[escript]/branches/split/escriptcore/src/SubWorld.cpp
ViewVC logotype

Diff of /branches/split/escriptcore/src/SubWorld.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4807 by jfenwick, Wed Mar 26 05:48:28 2014 UTC revision 4808 by jfenwick, Thu Mar 27 05:34:14 2014 UTC
# Line 60  void SubWorld::clearJobs() Line 60  void SubWorld::clearJobs()
60      jobvec.clear();      jobvec.clear();
61  }  }
62    
63    // takes an vector of bools of size 2*number of variables
64    // Each entry in the first group is true if this subworld has at least one job which exports that variable.
65    // Each entry in the second group is true if there is at least one Job in this world which wishes
66    // to import that variable.
67    // The order of the variables is determined by the order of keys in the reducemap
68    // Q: Why does it take chars then?
69    // A: Because I want raw storage that I can pass via MPI and bool is special cased.
70    bool SubWorld::localTransport(std::vector<char>& vb, std::string& errmsg)
71    {
72        for (size_t i=0;i<jobvec.size();++i)
73        {  
74        bp::dict expmap=bp::extract<bp::dict>(jobvec[i].attr("exportedvalues"))();  
75        bp::list items=expmap.items();
76        size_t l=bp::len(items);
77        for (int j=0;j<l;++j)
78        {
79            bp::object o1=items[j][0];
80            bp::object o2=items[j][1];
81            bp::extract<std::string> ex1(o1);
82            if (!ex1.check())
83            {
84            errmsg="Job attempted export using a name which was not a string.";
85            return false;
86            }
87            std::string name=ex1();
88            std::map<std::string, Reducer_ptr>::iterator it=reducemap.find(name);
89            if (it==reducemap.end())
90            {
91            errmsg="Attempt to export variable \""+name+"\". SplitWorld was not told about this variable.";
92            return false;
93            }
94            // so now we know it is a known name, we check that it is not None and that it is compatible
95            if (o2.is_none())
96            {
97            errmsg="Attempt to export variable \""+name+"\" with value of None, this is not permitted.";
98            return false;
99            }
100            if (!(it->second)->valueCompatible(o2))
101            {
102            errmsg="Attempt to export variable \""+name+"\" with an incompatible value.";
103            return false;
104            }
105            if (!(it->second)->reduceLocalValue(o2, errmsg))
106            {
107            return false;   // the error string will be set by the reduceLocalValue
108            }
109        }
110        }
111    
112        // If we get here, all of the (local) exports worked
113        // Now, lets make a record for distrubtion    
114        size_t l=reducemap.size();
115        vb.resize(l*2);
116        size_t i=0;
117        for (str2reduce::iterator it=reducemap.begin();it!=reducemap.end();++it, ++i)
118        {
119        if (it->second->hasValue())
120        {
121            vb[i]=1;
122        }
123        else
124        {
125            vb[i]=0;
126        }
127        if (importmap[it->first])
128        {
129            vb[i+l]=1;
130        }
131        else
132        {
133            vb[i+l]=0;    
134        }
135        }    
136        return true;      
137    }
138    /*
139  // Deal with the i-th job's exports  // Deal with the i-th job's exports
140  bool SubWorld::processExports(size_t i, std::string& errmsg)  bool SubWorld::processExportsLocal(size_t i, std::string& errmsg)
141  {  {
142      bp::dict expmap=bp::extract<bp::dict>(jobvec[i].attr("exportedvalues"))();        bp::dict expmap=bp::extract<bp::dict>(jobvec[i].attr("exportedvalues"))();  
143      bp::list items=expmap.items();      bp::list items=expmap.items();
# Line 100  bool SubWorld::processExports(size_t i, Line 176  bool SubWorld::processExports(size_t i,
176      }      }
177      }      }
178      return true;      return true;
179  }  }*/
180    /*
181    
182    void SubWorld::populateVarMoveInfo(vector<char>& vb)
183    {
184        size_t l=reducemap.size();
185        vb.resize(l*2);
186        for (str2reduce::iterator it=reducemap.begin(), int i=0;it!=reducemap.end();++it, ++i)
187        {
188        if (it->second->hasValue())
189        {
190            vb[i]=1;
191        }
192        else
193        {
194            vb[i]=0;
195        }
196        if (importmap[it->first])
197        {
198            vb[i+l]=1;
199        }
200        else
201        {
202            vb[i+l]=0;    
203        }
204        }
205    }*/
206    
207  // clears out all the old import and export values from _Jobs_  // clears out all the old import and export values from _Jobs_
208  // does not clear values out of reducers  // does not clear values out of reducers
# Line 133  char SubWorld::runJobs(std::string& erro Line 235  char SubWorld::runJobs(std::string& erro
235          {          {
236          return 2;            return 2;  
237          }          }
         // now we check the exports from that Job,  
         // Do names and type match?  
         if (!processExports(i, errormsg))  
         {      
         return 4;  
         }  
238          // check to see if we need to keep running          // check to see if we need to keep running
239          if (!ex())          if (!ex())
240          {          {
# Line 170  char SubWorld::runJobs(std::string& erro Line 266  char SubWorld::runJobs(std::string& erro
266      return ret;      return ret;
267  }  }
268    
269  void SubWorld::addVariable(std::string& name, Reducer_ptr& rp)  // if manual import is false, add this new variable to all the Jobs in this world
270    void SubWorld::addVariable(std::string& name, Reducer_ptr& rp, bool manualimport)
271  {  {
272      if (reducemap.find(name)!=reducemap.end())      if (reducemap.find(name)!=reducemap.end())
273      {      {
# Line 179  void SubWorld::addVariable(std::string& Line 276  void SubWorld::addVariable(std::string&
276      throw SplitWorldException(oss.str());          throw SplitWorldException(oss.str());    
277      }      }
278      reducemap[name]=rp;      reducemap[name]=rp;
279        if (!manualimport)
280        {
281        for (size_t i=0;i<jobvec.size();++i)
282        {
283            jobvec[i].attr("requestImport")(name);
284        }
285        }
286  }  }
287    
288  void SubWorld::removeVariable(std::string& s)  void SubWorld::removeVariable(std::string& s)

Legend:
Removed from v.4807  
changed lines
  Added in v.4808

  ViewVC Help
Powered by ViewVC 1.1.26