/[escript]/trunk/ripley/src/Rectangle.cpp
ViewVC logotype

Diff of /trunk/ripley/src/Rectangle.cpp

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

revision 4572 by jfenwick, Sun Dec 8 00:54:37 2013 UTC revision 4575 by jfenwick, Mon Dec 9 22:59:31 2013 UTC
# Line 3968  namespace Line 3968  namespace
3968    
3969  escript::Data Rectangle::randomFill(long seed, const boost::python::tuple& filter) const  escript::Data Rectangle::randomFill(long seed, const boost::python::tuple& filter) const
3970  {  {
3971      if (m_mpiInfo->size!=1)  //     if (m_mpiInfo->size!=1)
3972      {  //     {
3973          throw RipleyException("This type of random does not support MPI yet.");  //         throw RipleyException("This type of random does not support MPI yet.");
3974      }  //     }
3975      if (m_numDim!=2)      if (m_numDim!=2)
3976      {      {
3977          throw RipleyException("Only 2D supported at this time.");          throw RipleyException("Only 2D supported at this time.");
# Line 4023  escript::Data Rectangle::randomFill(long Line 4023  escript::Data Rectangle::randomFill(long
4023            
4024      dim_t X=m_mpiInfo->rank%m_NX[0];      dim_t X=m_mpiInfo->rank%m_NX[0];
4025      dim_t Y=m_mpiInfo->rank/m_NX[0];      dim_t Y=m_mpiInfo->rank/m_NX[0];
4026        dim_t row=m_NX[0];
4027    
4028      MPI_Request reqs[10];      MPI_Request reqs[10];
4029      MPI_Status stats[10];      MPI_Status stats[10];
4030      short rused=0;      short rused=0;
4031      double* SWin=new double[radius*radius];      double* SWin=new double[radius*radius];  memset(SWin, 0, radius*radius*sizeof(double));
4032      double* SEin=new double[radius*radius];      double* SEin=new double[radius*radius];  memset(SEin, 0, radius*radius*sizeof(double));
4033      double* NWin=new double[radius*radius];      double* NWin=new double[radius*radius];  memset(NWin, 0, radius*radius*sizeof(double));
4034      double* Sin=new double[radius*m_NX[0]];      double* Sin=new double[radius*numpoints[0]];  memset(Sin, 0, radius*numpoints[0]*sizeof(double));
4035      double* Win=new double[radius*m_NX[0]];      double* Win=new double[radius*numpoints[1]];  memset(Win, 0, radius*numpoints[1]*sizeof(double));
4036    
4037      double* NEout=new double[radius*radius];      double* NEout=new double[radius*radius];  memset(NEout, 0, radius*radius*sizeof(double));
4038      double* NWout=new double[radius*radius];      double* NWout=new double[radius*radius];  memset(NWout, 0, radius*radius*sizeof(double));
4039      double* SEout=new double[radius*radius];      double* SEout=new double[radius*radius];  memset(SEout, 0, radius*radius*sizeof(double));
4040      double* Nout=new double[radius*m_NX[0]];      double* Nout=new double[radius*numpoints[0]];  memset(Nout, 0, radius*numpoints[0]*sizeof(double));
4041      double* Eout=new double[radius*m_NX[0]];      double* Eout=new double[radius*numpoints[1]];  memset(Eout, 0, radius*numpoints[1]*sizeof(double));
4042        
4043    //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << SWin << " " << SEin << " " << NWin << " "<< Sin << " "<< Win << " "<< NEout << " "<< NWout << " "
4044    //<< SEout << " "
4045    //<< Nout << " "
4046    //<< Eout << " "
4047    //<< endl;          
4048            
4049    
4050      int comserr=0;      int comserr=0;
4051      if (Y!=0)   // not on bottom row,      if (Y!=0)   // not on bottom row,
4052      {      {
4053      if (X!=0)   // not on the left hand edge      if (X!=0)   // not on the left hand edge
4054      {      {
4055          // recv bottomleft from SW          // recv bottomleft from SW
4056          comserr|=MPI_Irecv(SWin, radius*radius, MPI_DOUBLE, (X-1)+(Y-1)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv SW (7) from " << (X-1)+(Y-1)*row << endl;
4057          comserr|=MPI_Irecv(Win, numpoints[1]*radius, MPI_DOUBLE, X-1+Y*m_NX[0], 10, m_mpiInfo->comm, reqs+(rused++));              comserr|=MPI_Irecv(SWin, radius*radius, MPI_DOUBLE, (X-1)+(Y-1)*row, 7, m_mpiInfo->comm, reqs+(rused++));
4058    //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv W (10) from " <<  X-1+Y*row << endl;        
4059            comserr|=MPI_Irecv(Win, numpoints[1]*radius, MPI_DOUBLE, X-1+Y*row, 10, m_mpiInfo->comm, reqs+(rused++));
4060        
4061      }      }
4062      else      else
4063      {      {
4064          comserr|=MPI_Irecv(SWin, radius*radius, MPI_DOUBLE, (Y-1)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv SW (7) from " << (Y-1)*row  << endl;              
4065            comserr|=MPI_Irecv(SWin, radius*radius, MPI_DOUBLE, (Y-1)*row, 7, m_mpiInfo->comm, reqs+(rused++));
4066      }      }
4067      comserr|=MPI_Irecv(Sin, numpoints[0]*radius, MPI_DOUBLE, X+(Y-1)*m_NX[0], 8, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv S (8) from " << X+(Y-1)*row  << endl;        
4068      comserr|=MPI_Irecv(SEin, radius*radius, MPI_DOUBLE, X+(Y-1)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));      comserr|=MPI_Irecv(Sin, numpoints[0]*radius, MPI_DOUBLE, X+(Y-1)*row, 8, m_mpiInfo->comm, reqs+(rused++));
4069    //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv SE (7) from " << X+(Y-1)*row << endl;    
4070        comserr|=MPI_Irecv(SEin, radius*radius, MPI_DOUBLE, X+(Y-1)*row, 7, m_mpiInfo->comm, reqs+(rused++));
4071    
4072                
4073      }      }
4074      else        // on the bottom row      else        // on the bottom row
4075      {      {
4076      if (X!=0)      if (X!=0)
4077      {      {
4078          comserr|=MPI_Irecv(Win, numpoints[1]*radius, MPI_DOUBLE, X-1+Y*m_NX[0], 10, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv W (10) from " << X-1+Y*row << endl;    
4079          comserr|=MPI_Irecv(NWin, radius*radius, MPI_DOUBLE, X-1+Y*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));          comserr|=MPI_Irecv(Win, numpoints[1]*radius, MPI_DOUBLE, X-1+Y*row, 10, m_mpiInfo->comm, reqs+(rused++));
4080    //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv NW (7) from " << X-1+Y*row << endl;      
4081            comserr|=MPI_Irecv(NWin, radius*radius, MPI_DOUBLE, X-1+Y*row, 7, m_mpiInfo->comm, reqs+(rused++));
4082      }      }
4083      if (X!=(m_NX[0]-1))      if (X!=(row-1))
4084      {      {
4085          comserr|=MPI_Isend(SEout, radius*radius, MPI_DOUBLE, X+1+(Y)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));      //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send SE (7) to " <<  X+1+(Y)*row << endl;          
4086            comserr|=MPI_Isend(SEout, radius*radius, MPI_DOUBLE, X+1+(Y)*row, 7, m_mpiInfo->comm, reqs+(rused++));  
4087        
4088      }      }
4089      }      }
4090        
4091      if (Y!=(m_NX[1]-1)) // not on the top row      if (Y!=(m_NX[1]-1)) // not on the top row
4092      {      {
4093      comserr|=MPI_Isend(Nout, radius*numpoints[0], MPI_DOUBLE, X+(Y+1)*m_NX[0], 8, m_mpiInfo->comm, reqs+(rused++));  //cerr << "Y=" << Y << "  (numpoints[1]-1)=" << (numpoints[1]-1) << endl;
4094      comserr|=MPI_Isend(NEout, radius*radius, MPI_DOUBLE, X+(Y+1)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send N (8) to " << X+(Y+1)*row  << endl;
4095      if (X!=(m_NX[0]-1)) // not on right hand edge      comserr|=MPI_Isend(Nout, radius*numpoints[0], MPI_DOUBLE, X+(Y+1)*row, 8, m_mpiInfo->comm, reqs+(rused++));
4096    //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send NE (7) to " <<  X+(Y+1)*row << endl;
4097        comserr|=MPI_Isend(NEout, radius*radius, MPI_DOUBLE, X+(Y+1)*row, 7, m_mpiInfo->comm, reqs+(rused++));
4098        if (X!=(row-1)) // not on right hand edge
4099      {      {
4100          comserr|=MPI_Isend(NEout, radius*radius, MPI_DOUBLE, X+1+(Y+1)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send NE (7) to " <<  X+1+(Y+1)*row << endl;            
4101            comserr|=MPI_Isend(NEout, radius*radius, MPI_DOUBLE, X+1+(Y+1)*row, 7, m_mpiInfo->comm, reqs+(rused++));
4102      }      }
4103      if (X==0)   // left hand edge      if (X==0)   // left hand edge
4104      {      {
4105          comserr|=MPI_Isend(NWout, radius*radius, MPI_DOUBLE, (Y+1)*m_NX[0],7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send NW (7) to " << (Y+1)*row << endl;      
4106            comserr|=MPI_Isend(NWout, radius*radius, MPI_DOUBLE, (Y+1)*row,7, m_mpiInfo->comm, reqs+(rused++));    
4107      }        }  
4108      }      }
4109      if (X!=(m_NX[0]-1)) // not on right hand edge      if (X!=(row-1)) // not on right hand edge
4110      {      {
4111      comserr|=MPI_Isend(NEout, radius*radius, MPI_DOUBLE, X+1+(Y)*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send NE (7) to " << X+1+(Y)*row << endl;      
4112      comserr|=MPI_Isend(Eout, numpoints[1]*radius, MPI_DOUBLE, X+1+(Y)*m_NX[0], 10, m_mpiInfo->comm, reqs+(rused++));      comserr|=MPI_Isend(NEout, radius*radius, MPI_DOUBLE, X+1+(Y)*row, 7, m_mpiInfo->comm, reqs+(rused++));
4113      comserr|=MPI_Irecv(NWin, radius*radius, MPI_DOUBLE, (X-1)+Y*m_NX[0], 7, m_mpiInfo->comm, reqs+(rused++));  //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Send E (10) to " << X+1+(Y)*row << endl;  
4114        comserr|=MPI_Isend(Eout, numpoints[1]*radius, MPI_DOUBLE, X+1+(Y)*row, 10, m_mpiInfo->comm, reqs+(rused++));
4115      }      }
4116        if (X!=0)
4117        {
4118    //cerr << m_mpiInfo->rank << "[" << __LINE__ << "]: " << "Recv NW (7) from " << (X-1)+Y*row << endl;    
4119          
4120        comserr|=MPI_Irecv(NWin, radius*radius, MPI_DOUBLE, (X-1)+Y*row, 7, m_mpiInfo->comm, reqs+(rused++));
4121          
4122          
4123        }
4124        
4125      if (!comserr)      if (!comserr)
4126      {      {
4127    //cerr << rused << ": " <<   m_mpiInfo->rank << "[" << __LINE__ << "]\n";        
4128          comserr=MPI_Waitall(rused, reqs, stats);          comserr=MPI_Waitall(rused, reqs, stats);
4129      }      }
4130        
4131      if (comserr)      if (comserr)
4132      {      {
4133      // Yes this is throwing an exception as a result of an MPI error.      // Yes this is throwing an exception as a result of an MPI error.

Legend:
Removed from v.4572  
changed lines
  Added in v.4575

  ViewVC Help
Powered by ViewVC 1.1.26