/[escript]/trunk/escriptcore/src/MPIDataReducer.cpp
ViewVC logotype

Diff of /trunk/escriptcore/src/MPIDataReducer.cpp

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

revision 5682 by jfenwick, Tue Jun 23 01:55:20 2015 UTC revision 5683 by jfenwick, Wed Jun 24 02:00:12 2015 UTC
# Line 142  bool MPIDataReducer::reduceLocalValue(bo Line 142  bool MPIDataReducer::reduceLocalValue(bo
142      return false;      return false;
143      }      }
144      d.expand();     // because I don't want to mess about with types of Data      d.expand();     // because I don't want to mess about with types of Data
145      if (!valueadded)    // first value so answer becomes this one      if (!valueadded || !had_an_export_this_round)   // first value so answer becomes this one
146      {      {
147      value=d;      value=d;
148      dom=d.getDomain();      dom=d.getDomain();
# Line 151  bool MPIDataReducer::reduceLocalValue(bo Line 151  bool MPIDataReducer::reduceLocalValue(bo
151      }      }
152      else      else
153      {      {
       
154      if (reduceop==MPI_OP_NULL)      if (reduceop==MPI_OP_NULL)
155      {      {
156          if (had_an_export_this_round)          if (had_an_export_this_round)
# Line 232  bool MPIDataReducer::checkRemoteCompatib Line 231  bool MPIDataReducer::checkRemoteCompatib
231  // are compatible  // are compatible
232  bool MPIDataReducer::reduceRemoteValues(esysUtils::JMPI& mpi_info, bool active)  bool MPIDataReducer::reduceRemoteValues(esysUtils::JMPI& mpi_info, bool active)
233  {  {
   using namespace std;  
234      if (!active)      if (!active)
235      {      {
236      return false;   // shutting down this option until I implement it      return false;   // shutting down this option until I implement it
# Line 402  boost::python::object MPIDataReducer::ge Line 400  boost::python::object MPIDataReducer::ge
400    
401    
402      // send from proc 0 in the communicator to all others      // send from proc 0 in the communicator to all others
403  bool MPIDataReducer::groupSend(MPI_Comm& com)      // second argument is true if this rank is sending
404    bool MPIDataReducer::groupSend(MPI_Comm& comm, bool imsending)
405  {  {
406      throw SplitWorldException("groupSend Not implemented yet.");        if (dom.get()==0)
407          {
408          return 0; // trying to avoid throwing here
409                // this will still cause a lockup if it happens
410          }
411    #ifdef ESYS_MPI
412          if (imsending)
413          {
414          // first step is to let the other world know what sort of thing it needs to make
415          if (value.isLazy())
416          {
417              value.resolve();
418          }
419          std::vector<unsigned> params;
420          getCompatibilityInfo(params);
421          if (MPI_Bcast(&params[0], params.size(), MPI_UNSIGNED, 0,comm)!=MPI_SUCCESS)
422          {
423              return false;
424          }
425            // now we have informed the other end of what happened
426            // are we done or is there actually data to send
427          if (params[0]<10)
428          {
429              return false;
430          }
431            // at this point, we know there is data to send
432          const DataAbstract::ValueType::value_type* vect=value.getDataRO();
433            // now the receiver knows how much data it should be receive
434            // need to make sure that we aren't trying to send data with no local samples
435          if (vect!=0)
436          {
437              if (MPI_Bcast(const_cast<DataAbstract::ValueType::value_type*>(vect), value.getLength(), MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)
438              {
439              return false;
440              }
441          }
442          }
443          else  // we are receiving
444          {
445            // first we need to find out what we are expecting
446          unsigned params[7];
447          if (MPI_Bcast(params, 7, MPI_UNSIGNED, 0, comm)!=MPI_SUCCESS)
448          {
449              return false;
450          }
451          if (params[0]<10) // the sender somehow tried to send something invalid
452          {
453              return false;
454          }
455            // now we put the shape object together
456          escript::DataTypes::ShapeType s;
457          for (int i=0;i<4;++i)
458          {
459              if (params[3+i]>0)
460              {
461              s.push_back(params[3+i]);
462              }
463              else
464              {
465              break;
466              }
467          }
468            // Now we need the FunctionSpace
469          FunctionSpace fs=FunctionSpace(dom, static_cast<int>(params[1]));
470          value=Data(0, s, fs, params[0]==12);
471          if (params[0]==11)    // The Data is tagged so we need to work out what tags we need
472          {
473              // TODO:  Need to ship the tags and names over but for now just make sure there
474              // are the same number of tags
475              value.tag();
476              
477              DataVector dv(DataTypes::noValues(s), 0, 1);
478              for (unsigned i=0;i<params[2];++i)
479              {
480              value.setTaggedValueFromCPP(static_cast<int>(i)+1, s, dv, 0);
481              }
482              return false; // because I don't trust this yet
483          }
484          DataAbstract::ValueType::value_type* vect=&(value.getExpandedVectorReference()[0]);
485          if (MPI_Bcast(const_cast<DataAbstract::ValueType::value_type*>(vect), value.getLength(), MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)
486          {
487              return false;
488          }
489          valueadded=true;
490          }
491    #endif        
492        return true;
493  }  }
494    
495  bool MPIDataReducer::groupReduce(MPI_Comm& com, char mystate)  bool MPIDataReducer::groupReduce(MPI_Comm& com, char mystate)
# Line 423  void MPIDataReducer::copyValueFrom(boost Line 508  void MPIDataReducer::copyValueFrom(boost
508      {      {
509      throw SplitWorldException("Attempt to copy DataEmpty.");      throw SplitWorldException("Attempt to copy DataEmpty.");
510      }      }
511      value=sr->value;      if (sr==this)
512        {
513        throw SplitWorldException("Source and destination can not be the same variable.");
514        }
515        value.copy(sr->value);    
516      valueadded=true;      valueadded=true;
517  }  }
518    

Legend:
Removed from v.5682  
changed lines
  Added in v.5683

  ViewVC Help
Powered by ViewVC 1.1.26