/[escript]/branches/trilinos_from_5897/escriptcore/src/MPIDataReducer.cpp
ViewVC logotype

Diff of /branches/trilinos_from_5897/escriptcore/src/MPIDataReducer.cpp

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

revision 5962 by caltinay, Fri Feb 5 03:37:49 2016 UTC revision 5963 by caltinay, Mon Feb 22 06:59:27 2016 UTC
# Line 233  bool MPIDataReducer::checkRemoteCompatib Line 233  bool MPIDataReducer::checkRemoteCompatib
233  bool MPIDataReducer::reduceRemoteValues(MPI_Comm& comm)  bool MPIDataReducer::reduceRemoteValues(MPI_Comm& comm)
234  {  {
235  #ifdef ESYS_MPI  #ifdef ESYS_MPI
236      DataTypes::ValueType& vr=value.getExpandedVectorReference();      DataTypes::RealVectorType& vr=value.getExpandedVectorReference();
237      Data result(0, value.getDataPointShape(), value.getFunctionSpace(), true);      Data result(0, value.getDataPointShape(), value.getFunctionSpace(), true);
238      DataTypes::ValueType& rr=result.getExpandedVectorReference();      DataTypes::RealVectorType& rr=result.getExpandedVectorReference();
239      if (reduceop==MPI_OP_NULL)      if (reduceop==MPI_OP_NULL)
240      {      {
241      reset();    // we can't be sure what the value should be      reset();    // we can't be sure what the value should be
# Line 259  bool MPIDataReducer::reduceRemoteValues( Line 259  bool MPIDataReducer::reduceRemoteValues(
259  //  [1]    Functionspace type code  //  [1]    Functionspace type code
260  //  [2]    Only used for tagged --- gives the number of tags (which exist in the data object)  //  [2]    Only used for tagged --- gives the number of tags (which exist in the data object)
261  //  [3..6] Components of the shape    //  [3..6] Components of the shape  
262    //  [7]    Complexity: {0: real, 1:complex}
263  void MPIDataReducer::getCompatibilityInfo(std::vector<unsigned>& params)  void MPIDataReducer::getCompatibilityInfo(std::vector<unsigned>& params)
264  {  {
265      params.resize(7);      params.resize(8);
266      for (int i=0;i<7;++i)      for (int i=0;i<8;++i)
267      {      {
268      params[0]=0;      params[i]=0;
269      }      }
270      if (!valueadded)      if (!valueadded)
271      {      {
# Line 294  void MPIDataReducer::getCompatibilityInf Line 295  void MPIDataReducer::getCompatibilityInf
295      for (int i=0;i<s.size();++i)      for (int i=0;i<s.size();++i)
296      {      {
297      params[3+i]=s[i];      params[3+i]=s[i];
298      }          }
299        params[7]=value.isComplex();
300  }  }
301    
302    
# Line 336  bool MPIDataReducer::recvFrom(Esys_MPI_r Line 338  bool MPIDataReducer::recvFrom(Esys_MPI_r
338      // are the same number of tags      // are the same number of tags
339      value.tag();      value.tag();
340            
341      DataVector dv(DataTypes::noValues(s), 0, 1);      DataTypes::RealVectorType dv(DataTypes::noValues(s), 0, 1);
342      for (unsigned i=0;i<params[2];++i)      for (unsigned i=0;i<params[2];++i)
343      {      {
344          value.setTaggedValueFromCPP(static_cast<int>(i)+1, s, dv, 0);          value.setTaggedValueFromCPP(static_cast<int>(i)+1, s, dv, 0);
# Line 373  bool MPIDataReducer::sendTo(Esys_MPI_ran Line 375  bool MPIDataReducer::sendTo(Esys_MPI_ran
375        {        {
376        return false;        return false;
377        }        }
378      // at this point, we know there is data to send        
379        const DataAbstract::ValueType::value_type* vect=value.getDataRO();        if (value.isComplex())
     // now the receiver knows how much data it should be receive  
     // need to make sure that we aren't trying to send data with no local samples  
       if (vect!=0)  
380        {        {
381        // MPI v3 has this first param as a const void* (as it should be)        DataTypes::cplx_t dummy=0;
382        // Version on my machine expects void*          // at this point, we know there is data to send
383        if (MPI_Send(const_cast<DataAbstract::ValueType::value_type*>(vect), value.getLength(), MPI_DOUBLE, target, PARAMTAG, mpiinfo->comm)!=MPI_SUCCESS)        const DataTypes::cplx_t* vect=value.getDataRO(dummy);
384            // now the receiver knows how much data it should be receive
385            // need to make sure that we aren't trying to send data with no local samples
386          if (vect!=0)
387        {        {
388            return false;            // MPI v3 has this first param as a const void* (as it should be)
389              // Version on my machine expects void*
390              // we don't require MPIv3 yet ... so we can't use MPI_CXX_DOUBLE_COMPLEX
391              // We'll try just sending twice as many doubles
392              //if (MPI_Send(const_cast<DataTypes::cplx_t*>(vect), value.getLength(), MPI_CXX_DOUBLE_COMPLEX, target, PARAMTAG, mpiinfo->comm)!=MPI_SUCCESS)
393              if (MPI_Send(const_cast<DataTypes::cplx_t*>(vect), 2*value.getLength(), MPI_DOUBLE, target, PARAMTAG, mpiinfo->comm)!=MPI_SUCCESS)
394              {
395              return false;
396              }
397          }
398          }
399          else
400          {
401          DataTypes::real_t dummy=0;
402            // at this point, we know there is data to send
403          const DataTypes::real_t* vect=value.getDataRO(dummy);
404            // now the receiver knows how much data it should be receive
405            // need to make sure that we aren't trying to send data with no local samples
406          if (vect!=0)
407          {
408              // MPI v3 has this first param as a const void* (as it should be)
409              // Version on my machine expects void*
410              if (MPI_Send(const_cast<DataTypes::real_t*>(vect), value.getLength(), MPI_DOUBLE, target, PARAMTAG, mpiinfo->comm)!=MPI_SUCCESS)
411              {
412              return false;
413              }
414        }        }
415        }        }
416  #endif        #endif      
# Line 426  bool MPIDataReducer::groupSend(MPI_Comm& Line 453  bool MPIDataReducer::groupSend(MPI_Comm&
453        {        {
454            return false;            return false;
455        }        }
456          // at this point, we know there is data to send        
457        const DataAbstract::ValueType::value_type* vect=value.getDataRO();        if (value.isComplex())
         // now the receiver knows how much data it should be receive  
         // need to make sure that we aren't trying to send data with no local samples  
       if (vect!=0)  
458        {        {
459            if (MPI_Bcast(const_cast<DataAbstract::ValueType::value_type*>(vect), value.getLength(), MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)            DataTypes::cplx_t dummy=0;
460            // at this point, we know there is data to send
461              const DataTypes::cplx_t* vect=value.getDataRO(dummy);
462            // now the receiver knows how much data it should be receive
463            // need to make sure that we aren't trying to send data with no local samples
464              if (vect!=0)
465            {            {
466            return false;            // we don't require MPIv3 yet ... so we can't use MPI_CXX_DOUBLE_COMPLEX
467              // We'll try just sending twice as many doubles      
468              //if (MPI_Bcast(const_cast<DataTypes::cplx_t*>(vect), value.getLength(), MPI_CXX_DOUBLE_COMPLEX, 0, comm)!=MPI_SUCCESS)
469              if (MPI_Bcast(const_cast<DataTypes::cplx_t*>(vect), value.getLength()*2, MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)
470              {
471                  return false;
472              }
473              }
474          }
475          else
476          {
477              DataTypes::real_t dummy=0;
478            // at this point, we know there is data to send
479              const DataTypes::real_t* vect=value.getDataRO(dummy);
480            // now the receiver knows how much data it should be receive
481            // need to make sure that we aren't trying to send data with no local samples
482              if (vect!=0)
483              {
484              if (MPI_Bcast(const_cast<DataTypes::real_t*>(vect), value.getLength(), MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)
485              {
486                  return false;
487              }
488            }            }
489        }        }
490        }        }
491        else  // we are receiving        else  // we are receiving
492        {        {
493              bool createcplx=false;
494          // first we need to find out what we are expecting          // first we need to find out what we are expecting
495        unsigned params[7];        unsigned params[8];
496        if (MPI_Bcast(params, 7, MPI_UNSIGNED, 0, comm)!=MPI_SUCCESS)        if (MPI_Bcast(params, 8, MPI_UNSIGNED, 0, comm)!=MPI_SUCCESS)
497        {        {
498            return false;            return false;
499        }        }
# Line 466  bool MPIDataReducer::groupSend(MPI_Comm& Line 516  bool MPIDataReducer::groupSend(MPI_Comm&
516        }        }
517          // Now we need the FunctionSpace          // Now we need the FunctionSpace
518        FunctionSpace fs=FunctionSpace(dom, static_cast<int>(params[1]));        FunctionSpace fs=FunctionSpace(dom, static_cast<int>(params[1]));
519        value=Data(0, s, fs, params[0]==12);        
520        if (params[0]==11)    // The Data is tagged so we need to work out what tags we need        if (createcplx)   // we need to make a complex data
521        {        {
522            // TODO:  Need to ship the tags and names over but for now just make sure there            value=Data(0, s, fs, params[0]==12);
523            // are the same number of tags            value.complicate();
524            value.tag();            if (params[0]==11)    // The Data is tagged so we need to work out what tags we need
             
           DataVector dv(DataTypes::noValues(s), 0, 1);  
           for (unsigned i=0;i<params[2];++i)  
525            {            {
526            value.setTaggedValueFromCPP(static_cast<int>(i)+1, s, dv, 0);            // TODO:  Need to ship the tags and names over but for now just make sure there
527              // are the same number of tags
528              value.tag();
529              
530              DataTypes::CplxVectorType dv(DataTypes::noValues(s), 0, 1);
531              for (unsigned i=0;i<params[2];++i)
532              {
533                  value.setTaggedValueFromCPP(static_cast<int>(i)+1, s, dv, 0);
534              }
535              return false; // because I don't trust this yet
536            }            }
537            return false; // because I don't trust this yet            DataTypes::cplx_t* vect=&(value.getExpandedVectorReference(DataTypes::cplx_t(0))[0]);
538              //if (MPI_Bcast(const_cast<DataTypes::cplx_t*>(vect), value.getLength(), MPI_CXX_DOUBLE_COMPLEX, 0, comm)!=MPI_SUCCESS)
539              if (MPI_Bcast(const_cast<DataTypes::cplx_t*>(vect), value.getLength()*2, MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)
540              {
541              return false;
542              }    
543        }        }
544        DataAbstract::ValueType::value_type* vect=&(value.getExpandedVectorReference()[0]);        else
       if (MPI_Bcast(const_cast<DataAbstract::ValueType::value_type*>(vect), value.getLength(), MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)  
545        {        {
546            return false;            
547              value=Data(0, s, fs, params[0]==12);
548              if (params[0]==11)    // The Data is tagged so we need to work out what tags we need
549              {
550              // TODO:  Need to ship the tags and names over but for now just make sure there
551              // are the same number of tags
552              value.tag();
553              
554              DataTypes::RealVectorType dv(DataTypes::noValues(s), 0, 1);
555              for (unsigned i=0;i<params[2];++i)
556              {
557                  value.setTaggedValueFromCPP(static_cast<int>(i)+1, s, dv, 0);
558              }
559              return false; // because I don't trust this yet
560              }
561              DataTypes::real_t* vect=&(value.getExpandedVectorReference(0)[0]);
562              if (MPI_Bcast(const_cast<DataTypes::real_t*>(vect), value.getLength(), MPI_DOUBLE, 0, comm)!=MPI_SUCCESS)
563              {
564              return false;
565              }
566        }        }
567        valueadded=true;        valueadded=true;
568        }        }

Legend:
Removed from v.5962  
changed lines
  Added in v.5963

  ViewVC Help
Powered by ViewVC 1.1.26