/[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 4705 by jfenwick, Fri Feb 21 02:36:15 2014 UTC revision 4712 by sshaw, Wed Feb 26 04:08:41 2014 UTC
# Line 19  Line 19 
19  #include <esysUtils/esysFileWriter.h>  #include <esysUtils/esysFileWriter.h>
20  #include <ripley/DefaultAssembler2D.h>  #include <ripley/DefaultAssembler2D.h>
21  #include <ripley/WaveAssembler2D.h>  #include <ripley/WaveAssembler2D.h>
22    #include <ripley/LameAssembler2D.h>
23    #include <ripley/domainhelpers.h>
24  #include <boost/scoped_array.hpp>  #include <boost/scoped_array.hpp>
25  #include "esysUtils/EsysRandom.h"  #include "esysUtils/EsysRandom.h"
26  #include "blocktools.h"  #include "blocktools.h"
# Line 55  Rectangle::Rectangle(int n0, int n1, dou Line 57  Rectangle::Rectangle(int n0, int n1, dou
57      }      }
58    
59      bool warn=false;      bool warn=false;
60      // if number of subdivisions is non-positive, try to subdivide by the same      std::vector<int> factors;
61      // ratio as the number of elements      int ranks = m_mpiInfo->size;
62      if (d0<=0 && d1<=0) {      int epr[2] = {n0,n1};
63          warn=true;      int d[2] = {d0,d1};
64          d0=max(1, (int)(sqrt(m_mpiInfo->size*(n0+1)/(float)(n1+1))));      if (d0<=0 || d1<=0) {
65          d1=m_mpiInfo->size/d0;          for (int i = 0; i < 2; i++) {
66          if (d0*d1 != m_mpiInfo->size) {              if (d[i] < 1) {
67              // ratios not the same so subdivide side with more elements only                  d[i] = 1;
68              if (n0>n1) {                  continue;
                 d0=0;  
                 d1=1;  
             } else {  
                 d0=1;  
                 d1=0;  
69              }              }
70                epr[i] = -1; // can no longer be max
71                //remove
72                if (ranks % d[i] != 0) {
73                    throw RipleyException("Invalid number of spatial subdivisions");
74                }
75                ranks /= d[i];
76            }
77            factorise(factors, ranks);
78            if (factors.size() != 0) {
79                warn = true;
80          }          }
81      }      }
82      if (d0<=0) {      
83          // d1 is preset, determine d0 - throw further down if result is no good      while (factors.size() > 0) {
84          d0=m_mpiInfo->size/d1;          int i = epr[0] > epr[1] ? 0 : 1;
85      } else if (d1<=0) {          int f = factors.back();
86          // d0 is preset, determine d1 - throw further down if result is no good          factors.pop_back();
87          d1=m_mpiInfo->size/d0;          d[i] *= f;
88            epr[i] /= f;
89      }      }
90        d0 = d[0]; d1 = d[1];
91        
92      // ensure number of subdivisions is valid and nodes can be distributed      // ensure number of subdivisions is valid and nodes can be distributed
93      // among number of ranks      // among number of ranks
94      if (d0*d1 != m_mpiInfo->size)      if (d0*d1 != m_mpiInfo->size)
# Line 2096  escript::Data Rectangle::randomFillWorke Line 2105  escript::Data Rectangle::randomFillWorke
2105          message& m=incoms[i];          message& m=incoms[i];
2106          comserr|=MPI_Irecv(block.getInBuffer(m.destbuffid), block.getBuffSize(m.destbuffid) , MPI_DOUBLE, m.sourceID, m.tag, m_mpiInfo->comm, reqs+(rused++));          comserr|=MPI_Irecv(block.getInBuffer(m.destbuffid), block.getBuffSize(m.destbuffid) , MPI_DOUBLE, m.sourceID, m.tag, m_mpiInfo->comm, reqs+(rused++));
2107          block.setUsed(m.destbuffid);          block.setUsed(m.destbuffid);
       
2108      }      }
2109    
2110      for (size_t i=0;i<outcoms.size();++i)      for (size_t i=0;i<outcoms.size();++i)
# Line 2107  escript::Data Rectangle::randomFillWorke Line 2115  escript::Data Rectangle::randomFillWorke
2115            
2116      if (!comserr)      if (!comserr)
2117      {          {    
2118          comserr=MPI_Waitall(rused, reqs, stats);              comserr=MPI_Waitall(rused, reqs, stats);
2119      }      }
2120    
2121      if (comserr)      if (comserr)
# Line 2216  void Rectangle::setAssembler(std::string Line 2224  void Rectangle::setAssembler(std::string
2224      if (type.compare("WaveAssembler") == 0) {      if (type.compare("WaveAssembler") == 0) {
2225          delete assembler;          delete assembler;
2226          assembler = new WaveAssembler2D(this, m_dx, m_NX, m_NE, m_NN, constants);          assembler = new WaveAssembler2D(this, m_dx, m_NX, m_NE, m_NN, constants);
2227        } else if (type.compare("LameAssembler") == 0) {
2228            delete assembler;
2229            assembler = new LameAssembler2D(this, m_dx, m_NX, m_NE, m_NN);
2230      } else { //else ifs would go before this for other types      } else { //else ifs would go before this for other types
2231          throw RipleyException("Ripley::Rectangle does not support the"          throw RipleyException("Ripley::Rectangle does not support the"
2232                                  " requested assembler");                                  " requested assembler");

Legend:
Removed from v.4705  
changed lines
  Added in v.4712

  ViewVC Help
Powered by ViewVC 1.1.26