freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Move big methods ool inside Partition/


From: Richard Guenther
Subject: [PATCH] Move big methods ool inside Partition/
Date: Mon, 4 Aug 2003 20:50:21 +0200 (CEST)

The following patch moves big methods out of line for classes
inside Partition/.  There is no gain in inlining these methods
and compile time improves with these not declared inline.  It
also makes the class structures easier to read.

Tested by compiling and Layout and Paritition tests on ppc-linux.

Ok?

Richard.


2003Aug04  Richard Guenther <address@hidden>

        * src/Partition/BisectionMapper.h: move big methods out of line.
        src/Partition/ContextMapper.h: likewise.
        src/Partition/ContiguousMapper.h: likewise.
        src/Partition/DistributedMapper.h: likewise.
        src/Partition/GridPartition.h: likewise.
        src/Partition/SpatialPartition.h: likewise.
        src/Partition/TilePartition.h: likewise.
        src/Partition/UniformGridPartition.h: likewise.

Index: src/Partition/BisectionMapper.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/BisectionMapper.h,v
retrieving revision 1.6
diff -u -u -r1.6 BisectionMapper.h
--- src/Partition/BisectionMapper.h     23 Jan 2003 21:29:50 -0000      1.6
+++ src/Partition/BisectionMapper.h     4 Aug 2003 18:43:56 -0000
@@ -69,115 +69,119 @@

   //

-  void map(const List_t & templist) const
-  {
-    int ncontexts = Pooma::contexts();
-    int npatch = 1;
-    for (int i =0;i<Dim; ++i)
-      npatch*=blocks_m[i].first();
-
-    std::list<Domain_t> bvec;
-
-    Domain_t allb;
-    for (int i = 0; i<Dim; ++i)
-      allb[i]=Interval<1>(0,blocks_m[i].first()-1);
-    bvec.push_back(allb);
-
-    while ( bvec.size() < ncontexts )
-      {
-       int s = 0;
-       typename std::list<Domain_t>::iterator bstart = bvec.begin();
-       typename std::list<Domain_t>::iterator bend = bvec.end();
-       typename std::list<Domain_t>::iterator bpatch;
-       // find the largest patch.
-       for ( ; bstart != bend ; ++bstart)
-         {
-           if (s < (*bstart).size() )
-             {
-               bpatch = bstart;
-               s = (*bstart).size();
-             }
-         }
-       // now find the largest dimension on the largest patch
-       int d = 0;
-       int sd = 0;
-       for (int i = 0; i<Dim; ++i)
-         {
-           if ( sd < (*bpatch)[i].size() )
-             {
-               d = i;
-               sd = (*bpatch)[i].size();
-             }
-         }
-       Domain_t hi(*bpatch),lo(*bpatch);
-       int lopoint = hi[d].first();
-       int hipoint = hi[d].last();
-       int mid     = lopoint + ( (hipoint - lopoint)/2);
-
-       if (lopoint<=mid)
-         lo[d] = Interval<1>(lopoint,mid);
-       else
-         lo[d] = Interval<1>(lopoint,lopoint);
-       if ( hipoint>=mid+1)
-         hi[d] = Interval<1>(mid+1,hipoint);
-       else
-         hi[d] = Interval<1>(hipoint,hipoint);
-       bvec.erase(bpatch++);
-       bvec.insert(bpatch,lo);
-       bvec.insert(bpatch,hi);
-      }
-    // now step through the intervals, using their elements as indexes into
-    // all_m;
-    int strides[Dim];
-    strides[0] = 1;
-    for ( int i=1; i<Dim; ++i)
-      strides[i] = strides[i-1]*blocks_m[i-1].first();
-
-    typename std::list<Domain_t>::iterator start = bvec.begin();
-    typename std::list<Domain_t>::iterator end = bvec.end();
-    int pcontext = 0;
-    for ( ; start != end ; ++start)
-      {
-       int idx[Dim],mi[Dim],mx[Dim];
-       for ( int  i = 0 ; i < Dim ; ++i)
-         {
-           idx[i] = mi[i] = (*start)[i].first();
-           mx[i]  = (*start)[i].last();
-         }
-
-       while ( idx[Dim-1] <= mx[Dim-1] )
-         {
-           int allIdx = 0;
-           for ( int i = 0 ; i < Dim ; ++i)
-             allIdx += idx[i]*strides[i];
-           (*templist[allIdx]).context() = pcontext;
-           ++idx[0];
-           for ( int i = 0 ; i < Dim ; ++i)
-             {
-               if ( idx[i] > mx[i] )
-                 {
-                   if ( i!=(Dim-1) )
-                     {
-                       ++idx[i+1];
-                       idx[i]=mi[i];
-                     }
-                   else
-                     ++idx[i];
-                 }
-               else
-                 break;
-             }
-         }
-       ++pcontext;
-      }
-    // set the affinity and local ID values
-    this->setAffinity(templist);
-  }
+  void map(const List_t & templist) const;

   // Memeber Data
   Loc<Dim> blocks_m;

 };
+
+template <int Dim>
+void BisectionMapper<Dim>::map(const List_t & templist) const
+{
+  int ncontexts = Pooma::contexts();
+  int npatch = 1;
+  for (int i =0;i<Dim; ++i)
+    npatch*=blocks_m[i].first();
+
+  std::list<Domain_t> bvec;
+
+  Domain_t allb;
+  for (int i = 0; i<Dim; ++i)
+    allb[i]=Interval<1>(0,blocks_m[i].first()-1);
+  bvec.push_back(allb);
+
+  while ( bvec.size() < ncontexts )
+    {
+      int s = 0;
+      typename std::list<Domain_t>::iterator bstart = bvec.begin();
+      typename std::list<Domain_t>::iterator bend = bvec.end();
+      typename std::list<Domain_t>::iterator bpatch;
+      // find the largest patch.
+      for ( ; bstart != bend ; ++bstart)
+       {
+         if (s < (*bstart).size() )
+           {
+             bpatch = bstart;
+             s = (*bstart).size();
+           }
+       }
+      // now find the largest dimension on the largest patch
+      int d = 0;
+      int sd = 0;
+      for (int i = 0; i<Dim; ++i)
+       {
+         if ( sd < (*bpatch)[i].size() )
+           {
+             d = i;
+             sd = (*bpatch)[i].size();
+           }
+       }
+      Domain_t hi(*bpatch),lo(*bpatch);
+      int lopoint = hi[d].first();
+      int hipoint = hi[d].last();
+      int mid     = lopoint + ( (hipoint - lopoint)/2);
+
+      if (lopoint<=mid)
+       lo[d] = Interval<1>(lopoint,mid);
+      else
+       lo[d] = Interval<1>(lopoint,lopoint);
+      if ( hipoint>=mid+1)
+       hi[d] = Interval<1>(mid+1,hipoint);
+      else
+       hi[d] = Interval<1>(hipoint,hipoint);
+      bvec.erase(bpatch++);
+      bvec.insert(bpatch,lo);
+      bvec.insert(bpatch,hi);
+    }
+  // now step through the intervals, using their elements as indexes into
+  // all_m;
+  int strides[Dim];
+  strides[0] = 1;
+  for ( int i=1; i<Dim; ++i)
+    strides[i] = strides[i-1]*blocks_m[i-1].first();
+
+  typename std::list<Domain_t>::iterator start = bvec.begin();
+  typename std::list<Domain_t>::iterator end = bvec.end();
+  int pcontext = 0;
+  for ( ; start != end ; ++start)
+    {
+      int idx[Dim],mi[Dim],mx[Dim];
+      for ( int  i = 0 ; i < Dim ; ++i)
+       {
+         idx[i] = mi[i] = (*start)[i].first();
+         mx[i]  = (*start)[i].last();
+       }
+
+      while ( idx[Dim-1] <= mx[Dim-1] )
+       {
+         int allIdx = 0;
+         for ( int i = 0 ; i < Dim ; ++i)
+           allIdx += idx[i]*strides[i];
+         (*templist[allIdx]).context() = pcontext;
+         ++idx[0];
+         for ( int i = 0 ; i < Dim ; ++i)
+           {
+             if ( idx[i] > mx[i] )
+               {
+                 if ( i!=(Dim-1) )
+                   {
+                     ++idx[i+1];
+                     idx[i]=mi[i];
+                   }
+                 else
+                   ++idx[i];
+               }
+             else
+               break;
+           }
+       }
+      ++pcontext;
+    }
+  // set the affinity and local ID values
+  this->setAffinity(templist);
+}
+

 #endif   // POOMA_BISECTIONMAPPER_H

Index: src/Partition/ContextMapper.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/ContextMapper.h,v
retrieving revision 1.21
diff -u -u -r1.21 ContextMapper.h
--- src/Partition/ContextMapper.h       1 Jul 2002 22:25:53 -0000       1.21
+++ src/Partition/ContextMapper.h       4 Aug 2003 18:43:57 -0000
@@ -83,36 +83,39 @@
   virtual ~ContextMapper(){};

   virtual void map(const List_t & templist) const = 0;
-

- void setAffinity(const List_t & templist) const
-  {
-    int affinityMax = Smarts::concurrency();
-    int idMax = 0;
-
-    typename List_t::const_iterator start = templist.begin();
-    typename List_t::const_iterator end = templist.end();
+  void setAffinity(const List_t & templist) const;

-    for ( ; start != end ; ++start)
-      if((*start)->context()==Pooma::context())
-       {
-         (*start)->localID()=idMax;
-         ++idMax;
-       }
-
-    start = templist.begin();
-    for ( ; start != end ; ++start)
-      {
-       if((*start)->context()==Pooma::context())
-         (*start)->affinity() = static_cast<int>( affinityMax *
-                                 ( (*start)->localID() /
-                                 static_cast<double>(idMax) ) );
+};
+
+template<int Dim>
+void ContextMapper<Dim>::setAffinity(const List_t & templist) const
+{
+  int affinityMax = Smarts::concurrency();
+  int idMax = 0;
+
+  typename List_t::const_iterator start = templist.begin();
+  typename List_t::const_iterator end = templist.end();
+
+  for ( ; start != end ; ++start)
+    if((*start)->context()==Pooma::context())
+      {
+       (*start)->localID()=idMax;
+       ++idMax;
       }

-    return;
-  }
+  start = templist.begin();
+  for ( ; start != end ; ++start)
+    {
+      if((*start)->context()==Pooma::context())
+       (*start)->affinity() = static_cast<int>
+         ( affinityMax * ( (*start)->localID()
+                           / static_cast<double>(idMax) ) );
+    }
+
+  return;
+}

-};

 template<int Dim>
 class LocalMapper
@@ -133,22 +136,23 @@
   LocalMapper()
   {}

-  void map(const List_t & templist) const
-  {
-    int idMax = templist.size();
-    int naff = Smarts::concurrency();
-    for (int i = 0; i< templist.size(); ++i)
-      {
-       templist[i]->context() = -1;
-       templist[i]->localID() = i;
-       templist[i]->affinity() = static_cast<int>( ( naff * ( i /
-                                  static_cast<double>(idMax) ) ) );
-      }
-  }
-
-
+  void map(const List_t & templist) const;

 };
+
+template<int Dim>
+void LocalMapper<Dim>::map(const List_t & templist) const
+{
+  int idMax = templist.size();
+  int naff = Smarts::concurrency();
+  for (int i = 0; i< templist.size(); ++i)
+    {
+      templist[i]->context() = -1;
+      templist[i]->localID() = i;
+      templist[i]->affinity() = static_cast<int>( ( naff * ( i /
+                               static_cast<double>(idMax) ) ) );
+    }
+}


 #endif     // POOMA_CONTEXTMAPPER_H
Index: src/Partition/ContiguousMapper.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/ContiguousMapper.h,v
retrieving revision 1.3
diff -u -u -r1.3 ContiguousMapper.h
--- src/Partition/ContiguousMapper.h    12 Jun 2000 21:57:57 -0000      1.3
+++ src/Partition/ContiguousMapper.h    4 Aug 2003 18:43:57 -0000
@@ -32,98 +32,103 @@
   {
   }

-  void map(const List_t & templist) const
-  {
-    int idx[Dim];
-    for (int i = 0;i<Dim;++i)
-      idx[i]=0;
-    int strides[Dim];
-    strides[Dim-1] = 1;
-    for ( int i=Dim-2; i>=0; --i)
-      strides[i] = strides[i+1]*blocks_m[i+1].last();
-
-    int npatch = 1;
-    for (int i=0; i<Dim; ++i)
-      npatch *= blocks_m[i].first();
-
-    int ncontexts = Pooma::contexts();
-    int npc = npatch/ncontexts;
-
-    int remainder = npatch - (npc*ncontexts);
-
-    int pcontext = 0;
-    int c = 0;
-    int patchdone = 0;
-    int patchleft = npatch;
-
-    int incriment[Dim];
-    for (int i =0 ; i<Dim; ++i) incriment[i] = 1;
-    while ( true  )
-      {
-       int allIdx = 0;
-       for ( int i = 0 ; i < Dim ; ++i)
-         allIdx += idx[i]*strides[i];
-       (*templist[allIdx]).context() = pcontext;
-
-       ++c;
-       ++patchdone;
-       --patchleft;
-
-       if(c >= npc )
-         {
-           // if we are at the end of a context, and there are still
-           // remainder patches left over, extend the number of
-           // patches per context by one, if we are not at an edge
-           // in the first dimension. However, if we have extra
-           // patches left over, and are in danger of running out
-           // of contexts to add patches to, add them now.
-
-           if (c == npc && remainder >0 &&
-               ((idx[0]-1 >= 0 && idx[0]+1<=(blocks_m[0].first()-1)) ||
-                (patchleft - ((npc+1)*(ncontexts-(pcontext+1))) >=0 )) )
-             --remainder;
-           else
-             {
-               c = 0;
-               ++pcontext;
-             }
-         }
-
-       bool t = true;
-       for ( int i = 0 ; i < Dim ; ++i)
-         {
-           t = t && (
-                     idx[i] == (blocks_m[i]-1) && incriment[i] == 1
-                     ||
-                     idx[i] == 0 && incriment[i] == -1);
-         }
-       if (t) break;
-
-       idx[0] += incriment[0];
-       for ( int i = 0 ; i < Dim ; ++i)
-         {
-           if ( idx[i] > blocks_m[i].last()-1)
-             {
-               idx[i+1]+=incriment[i+1];
-               idx[i]=blocks_m[i].last()-1;
-               incriment[i] *= -1;
-             }
-           else if (idx[i]<0)
-             {
-               idx[i+1]+=incriment[i+1];
-               idx[i]=0;
-               incriment[i] *= -1;
-             }
-           else
-             break;
-         }
-      }
+  void map(const List_t & templist) const;

-    ContextMapper<Dim>::setAffinity(templist);
-
-  }
   // Member Data
   Loc<Dim> blocks_m;
 };
+
+template<int Dim>
+void ContiguousMapper<Dim>::map(const List_t & templist) const
+{
+  int idx[Dim];
+  for (int i = 0;i<Dim;++i)
+    idx[i]=0;
+  int strides[Dim];
+  strides[Dim-1] = 1;
+  for ( int i=Dim-2; i>=0; --i)
+    strides[i] = strides[i+1]*blocks_m[i+1].last();
+
+  int npatch = 1;
+  for (int i=0; i<Dim; ++i)
+    npatch *= blocks_m[i].first();
+
+  int ncontexts = Pooma::contexts();
+  int npc = npatch/ncontexts;
+
+  int remainder = npatch - (npc*ncontexts);
+
+  int pcontext = 0;
+  int c = 0;
+  int patchdone = 0;
+  int patchleft = npatch;
+
+  int incriment[Dim];
+  for (int i =0 ; i<Dim; ++i) incriment[i] = 1;
+  while ( true  )
+    {
+      int allIdx = 0;
+      for ( int i = 0 ; i < Dim ; ++i)
+       allIdx += idx[i]*strides[i];
+      (*templist[allIdx]).context() = pcontext;
+
+      ++c;
+      ++patchdone;
+      --patchleft;
+
+      if(c >= npc )
+       {
+         // if we are at the end of a context, and there are still
+         // remainder patches left over, extend the number of
+         // patches per context by one, if we are not at an edge
+         // in the first dimension. However, if we have extra
+         // patches left over, and are in danger of running out
+         // of contexts to add patches to, add them now.
+
+         if (c == npc && remainder >0 &&
+             ((idx[0]-1 >= 0 && idx[0]+1<=(blocks_m[0].first()-1)) ||
+              (patchleft - ((npc+1)*(ncontexts-(pcontext+1))) >=0 )) )
+           --remainder;
+         else
+           {
+             c = 0;
+             ++pcontext;
+           }
+       }
+
+      bool t = true;
+      for ( int i = 0 ; i < Dim ; ++i)
+       {
+         t = t && (
+                   idx[i] == (blocks_m[i]-1) && incriment[i] == 1
+                   ||
+                   idx[i] == 0 && incriment[i] == -1);
+       }
+      if (t)
+       break;
+
+      idx[0] += incriment[0];
+      for ( int i = 0 ; i < Dim ; ++i)
+       {
+         if ( idx[i] > blocks_m[i].last()-1)
+           {
+             idx[i+1]+=incriment[i+1];
+             idx[i]=blocks_m[i].last()-1;
+             incriment[i] *= -1;
+           }
+         else if (idx[i]<0)
+           {
+             idx[i+1]+=incriment[i+1];
+             idx[i]=0;
+             incriment[i] *= -1;
+           }
+         else
+           break;
+       }
+    }
+
+  ContextMapper<Dim>::setAffinity(templist);
+}
+

 #endif
Index: src/Partition/DistributedMapper.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/DistributedMapper.h,v
retrieving revision 1.8
diff -u -u -r1.8 DistributedMapper.h
--- src/Partition/DistributedMapper.h   3 Dec 2001 19:38:34 -0000       1.8
+++ src/Partition/DistributedMapper.h   4 Aug 2003 18:43:58 -0000
@@ -59,34 +59,7 @@
   }


-  void map(const List_t & templist) const
-  {
-    int ncontexts = Pooma::contexts();
-    int npc = templist.size()/ncontexts;
-    // If there are more contexts than patches, assign one
-    // patch per context for as many patches as there are.
-    if(ncontexts> templist.size())
-      {
-       // we should probably alert the user here!!
-       npc = 1;
-       ncontexts = templist.size();
-      }
-
-    if (Dim == 1)
-      {
-       // work around, since UniformMapper is 1-dim
-       uniformMap(blocks_m,templist,WrappedInt<Dim>());
-      }
-    else if(npc<3)
-      {
-       ContiguousMapper<Dim>(blocks_m).map(templist);
-      }
-    else
-      {
-       BisectionMapper<Dim>(blocks_m).map(templist);
-      }
-    return;
-  }
+  void map(const List_t & templist) const;

   void uniformMap(const Loc<1> &blocks,
                  const List_t &templist,
@@ -109,6 +82,37 @@
   Loc<Dim> blocks_m;

 };
+
+template<int Dim>
+void DistributedMapper<Dim>::map(const List_t & templist) const
+{
+  int ncontexts = Pooma::contexts();
+  int npc = templist.size()/ncontexts;
+  // If there are more contexts than patches, assign one
+  // patch per context for as many patches as there are.
+  if(ncontexts> templist.size())
+    {
+      // we should probably alert the user here!!
+      npc = 1;
+      ncontexts = templist.size();
+    }
+
+  if (Dim == 1)
+    {
+      // work around, since UniformMapper is 1-dim
+      uniformMap(blocks_m,templist,WrappedInt<Dim>());
+    }
+  else if(npc<3)
+    {
+      ContiguousMapper<Dim>(blocks_m).map(templist);
+    }
+  else
+    {
+      BisectionMapper<Dim>(blocks_m).map(templist);
+    }
+  return;
+}
+

 #endif

Index: src/Partition/GridPartition.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/GridPartition.h,v
retrieving revision 1.29
diff -u -u -r1.29 GridPartition.h
--- src/Partition/GridPartition.h       3 Dec 2001 19:38:34 -0000       1.29
+++ src/Partition/GridPartition.h       4 Aug 2003 18:43:58 -0000
@@ -356,111 +356,7 @@
   template<class D>
   int partition(const D &domain,
                List_t & all,
-               const ContextMapper<Dim> &cmapper ) const
-  {
-    typedef typename DomainTraits<Domain_t>::Element_t Element_t;
-
-    // Make sure we have the right dimensionality.
-
-    CTAssert(Dim == DomainTraits<D>::dimensions);
-    CTAssert(Dim == DomainTraits<Domain_t>::dimensions);
-
-    Grid<Dim> tgrid = grid();
-
-    // if an empty domain was passed, we make empty patches
-    if (domain.empty())
-      {
-       int np = 1;
-       for (int i=0;i<Dim;++i)
-         np*=blocks()[i].first();
-
-       int start=0;
-       Domain_t o;
-       Domain_t a;
-       while (start<np)
-         {
-           int gid = all.size();
-           int lid = -1;
-           Value_t *node = new Value_t(o, a, -1, gid, lid);
-           all.push_back(node);
-           ++start;
-         }
-       cmapper.map(all);
-       return maxSize();
-      }
-
-
-    if (tgrid.empty()&&!domain.empty() )
-      {
-       tgrid = makeRGrid(domain,blocks_m);
-      }
-
-    typename Grid<Dim>::blockIterator start = tgrid.beginBlock();
-    typename Grid<Dim>::blockIterator end = tgrid.endBlock();
-
-    while (start!=end)
-      {
-       Loc<Dim> idx = start.point();
-       Domain_t o = Pooma::NoInit();
-       o = * start;
-       Domain_t a = Pooma::NoInit();
-       a = * start;
-
-       // Calculate the guard cell specification for this domain.
-
-       if (hasInternalGuards()||hasExternalGuards())
-         {
-           for (int i=0;i<Dim;i++)
-             {
-               if (idx[i]==0)
-                 {
-                   if (hasExternalGuards())
-                     {
-                       o[i]=Interval<1>(o[i].first()-externalGuards().lower(i),
-                                        o[i].last());
-                       a[i]=Interval<1>(a[i].first()-externalGuards().lower(i),
-                                        a[i].last());
-                     }
-                   if (hasInternalGuards() && idx[i]!=(blocks()[i].first()-1))
-                     a[i]=Interval<1>(a[i].first(),
-                                      a[i].last()+internalGuards().upper(i));
-                 }
-               if (idx[i]==blocks()[i].first()-1)
-                 {
-                   if (hasExternalGuards())
-                     {
-                       o[i]=Interval<1>(o[i].first(),
-                                        o[i].last()+externalGuards().upper(i));
-                       a[i]=Interval<1>(a[i].first(),
-                                        a[i].last()+externalGuards().upper(i));
-                     }
-                   if (hasInternalGuards()&&(idx[i]!=0))
-                     a[i]=Interval<1>(a[i].first()-internalGuards().lower(i),
-                                      a[i].last());
-                 }
-               if (idx[i]!=0&&
-                  idx[i]!=(blocks()[i].first()-1)&&
-                  hasInternalGuards()) // it's a fully internal patch
-                 a[i]=Interval<1>(o[i].first()-internalGuards().lower(i),
-                                  o[i].last()+internalGuards().upper(i));
-
-             }
-         }
-
-       // Add the domain to the layout.
-       int gid = all.size();
-       int lid = -1;
-       Value_t *node = new Value_t(o, a, -1, gid, lid);
-       all.push_back(node);
-
-       // Increment our counters and iterators.
-
-       ++start;
-      }
-
-    cmapper.map(all);
-    return maxSize();
-  }
+               const ContextMapper<Dim> &cmapper ) const;

   template<class D>
   int partition(const D &domain,
@@ -470,38 +366,7 @@
   }

   template<class Out>
-  void print(Out &o) const
-  {
-    int i;
-    o << "GridPartition<" << Dim << ">:" << std::endl;
-    o << "  blocks_m = " << blocks_m << std::endl;
-    o << "  hasInternalGuards_m  hasExternalGuards_m = ";
-    o << hasInternalGuards_m<< " "<<hasExternalGuards_m<< std::endl;
-    o << "  internalGuards_m:" << std::endl;
-    o << "      upper       ";
-    for (i=0; i < Dim; ++i)
-      o << internalGuards_m.upper(i) << " ";
-    o << std::endl;
-    o << "      lower       ";
-    for (i=0; i < Dim; ++i)
-      o << internalGuards_m.lower(i) << " ";
-    o << std::endl;
-    o << "  externalGuards_m:" << std::endl;
-    o << "      upper       ";
-    for (i=0; i < Dim; ++i)
-      o << externalGuards_m.upper(i) << " ";
-    o << std::endl;
-    o << "      lower       ";
-    for (i=0; i < Dim; ++i)
-      o << externalGuards_m.lower(i) << " ";
-    o << std::endl;
-    o << "  num_m = " << num_m << std::endl;
-    o << "  grid_m = ";
-    if (grid_m.empty() )
-      o << "(empty)" << std::endl;
-    else
-      o << grid_m << std::endl;
-  }
+  void print(Out &o) const;

 private:

@@ -534,6 +399,151 @@
   Grid<Dim> grid_m;
 };

+
+template<int Dim>
+template<class D>
+int GridPartition<Dim>::partition(const D &domain,
+                                 List_t & all,
+                                 const ContextMapper<Dim> &cmapper ) const
+{
+  typedef typename DomainTraits<Domain_t>::Element_t Element_t;
+
+  // Make sure we have the right dimensionality.
+
+  CTAssert(Dim == DomainTraits<D>::dimensions);
+  CTAssert(Dim == DomainTraits<Domain_t>::dimensions);
+
+  Grid<Dim> tgrid = grid();
+
+  // if an empty domain was passed, we make empty patches
+  if (domain.empty())
+    {
+      int np = 1;
+      for (int i=0;i<Dim;++i)
+       np*=blocks()[i].first();
+
+      int start=0;
+      Domain_t o;
+      Domain_t a;
+      while (start<np)
+       {
+         int gid = all.size();
+         int lid = -1;
+         Value_t *node = new Value_t(o, a, -1, gid, lid);
+         all.push_back(node);
+         ++start;
+       }
+      cmapper.map(all);
+      return maxSize();
+    }
+
+
+  if (tgrid.empty()&&!domain.empty() )
+    {
+      tgrid = makeRGrid(domain,blocks_m);
+    }
+
+  typename Grid<Dim>::blockIterator start = tgrid.beginBlock();
+  typename Grid<Dim>::blockIterator end = tgrid.endBlock();
+
+  while (start!=end)
+    {
+      Loc<Dim> idx = start.point();
+      Domain_t o = Pooma::NoInit();
+      o = * start;
+      Domain_t a = Pooma::NoInit();
+      a = * start;
+
+      // Calculate the guard cell specification for this domain.
+
+      if (hasInternalGuards()||hasExternalGuards())
+       {
+         for (int i=0;i<Dim;i++)
+           {
+             if (idx[i]==0)
+               {
+                 if (hasExternalGuards())
+                   {
+                     o[i]=Interval<1>(o[i].first()-externalGuards().lower(i),
+                                      o[i].last());
+                     a[i]=Interval<1>(a[i].first()-externalGuards().lower(i),
+                                      a[i].last());
+                   }
+                 if (hasInternalGuards() && idx[i]!=(blocks()[i].first()-1))
+                   a[i]=Interval<1>(a[i].first(),
+                                    a[i].last()+internalGuards().upper(i));
+               }
+             if (idx[i]==blocks()[i].first()-1)
+               {
+                 if (hasExternalGuards())
+                   {
+                     o[i]=Interval<1>(o[i].first(),
+                                      o[i].last()+externalGuards().upper(i));
+                     a[i]=Interval<1>(a[i].first(),
+                                      a[i].last()+externalGuards().upper(i));
+                   }
+                 if (hasInternalGuards()&&(idx[i]!=0))
+                   a[i]=Interval<1>(a[i].first()-internalGuards().lower(i),
+                                    a[i].last());
+               }
+             if (idx[i]!=0&&
+                 idx[i]!=(blocks()[i].first()-1)&&
+                 hasInternalGuards()) // it's a fully internal patch
+               a[i]=Interval<1>(o[i].first()-internalGuards().lower(i),
+                                o[i].last()+internalGuards().upper(i));
+
+           }
+       }
+
+      // Add the domain to the layout.
+      int gid = all.size();
+      int lid = -1;
+      Value_t *node = new Value_t(o, a, -1, gid, lid);
+      all.push_back(node);
+
+      // Increment our counters and iterators.
+
+      ++start;
+    }
+
+  cmapper.map(all);
+  return maxSize();
+}
+
+template<int Dim>
+template<class Out>
+void GridPartition<Dim>::print(Out &o) const
+{
+  int i;
+  o << "GridPartition<" << Dim << ">:" << std::endl;
+  o << "  blocks_m = " << blocks_m << std::endl;
+  o << "  hasInternalGuards_m  hasExternalGuards_m = ";
+  o << hasInternalGuards_m<< " "<<hasExternalGuards_m<< std::endl;
+  o << "  internalGuards_m:" << std::endl;
+  o << "      upper       ";
+  for (i=0; i < Dim; ++i)
+    o << internalGuards_m.upper(i) << " ";
+  o << std::endl;
+  o << "      lower       ";
+  for (i=0; i < Dim; ++i)
+    o << internalGuards_m.lower(i) << " ";
+  o << std::endl;
+  o << "  externalGuards_m:" << std::endl;
+  o << "      upper       ";
+  for (i=0; i < Dim; ++i)
+    o << externalGuards_m.upper(i) << " ";
+  o << std::endl;
+  o << "      lower       ";
+  for (i=0; i < Dim; ++i)
+    o << externalGuards_m.lower(i) << " ";
+  o << std::endl;
+  o << "  num_m = " << num_m << std::endl;
+  o << "  grid_m = ";
+  if (grid_m.empty() )
+    o << "(empty)" << std::endl;
+  else
+    o << grid_m << std::endl;
+}


 //-----------------------------------------------------------------------------
Index: src/Partition/SpatialPartition.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/SpatialPartition.h,v
retrieving revision 1.13
diff -u -u -r1.13 SpatialPartition.h
--- src/Partition/SpatialPartition.h    9 Jun 2000 00:35:16 -0000       1.13
+++ src/Partition/SpatialPartition.h    4 Aug 2003 18:43:59 -0000
@@ -275,60 +275,10 @@
   // Partition methods
   //============================================================

-
-
   template<class D,class Dom>
   int partition(const D &domain,
                std::vector< Node<Dom> *> & all,
-               const ContextMapper<1> & cmapper ) const
-    {
-
-      // Make sure we have the right dimensionality between the provided
-      // domain and the layout's domain.  We do NOT need to have the
-      // dimensionality match between the provided layout and reference
-      // layout, however.
-
-      CTAssert(DomainTraits<D>::dimensions ==
-              DomainTraits<Dom>::dimensions);
-
-      // For now, this will only work with a 1D provided layout.
-
-      CTAssert(DomainTraits<D>::dimensions == 1);
-
-      // The provided domain must actually be empty for this to work,
-      // since we generate empty domains.
-
-      PAssert(domain.empty());
-
-      // Loop through the patches in the reference domain now.  For each one,
-      // just add in an empty domain, assigned to the same context
-      // as the current node that we're iterating over.
-
-      typename RefLayout_t::const_iterator refpatch,
-                                           endref = reference().endGlobal();
-
-      for (refpatch=reference().beginGlobal(); refpatch != endref; ++refpatch)
-       {
-         Node<Dom> *node = new Node<Dom>(Dom(),
-                                         Dom(),
-                                         refpatch->context(),
-                                         refpatch->globalID(),
-                                         refpatch->localID());
-         all.push_back(node);
-       }
-
-      // This call to the mapper for the case of DefaultSPMapper
-      // is a no-op, and could be commented out. The above loop
-      // does both the partitioning and the mapping. The structure
-      // of the DefaultSPmapper is maintained for this special case
-      // even though it's redundant.
-
-      cmapper.map(all);
-
-      // Return the number of domains we added in.
-
-      return maxSize();
-    }
+               const ContextMapper<1> & cmapper ) const;

   template<class D,class Dom>
   int partition(const D & domain,
@@ -342,12 +292,7 @@
   //============================================================

   template<class Out>
-  void print(Out &o) const
-    {
-      o << "SpatialPartitioner:\n";
-      o << "  reference layout = " << reference() << "\n";
-      o << "  maximum patches = " << maxSize() << "\n";
-    }
+  void print(Out &o) const;

 private:
   // The reference layout
@@ -358,6 +303,68 @@

   SpatialPartition();
 };
+
+template<class ReferenceLayout>
+template<class D,class Dom>
+int SpatialPartition<ReferenceLayout>::partition(const D &domain,
+                                                std::vector< Node<Dom> *> & 
all,
+                                                const ContextMapper<1> & 
cmapper) const
+{
+  // Make sure we have the right dimensionality between the provided
+  // domain and the layout's domain.  We do NOT need to have the
+  // dimensionality match between the provided layout and reference
+  // layout, however.
+
+  CTAssert(DomainTraits<D>::dimensions ==
+          DomainTraits<Dom>::dimensions);
+
+  // For now, this will only work with a 1D provided layout.
+
+  CTAssert(DomainTraits<D>::dimensions == 1);
+
+  // The provided domain must actually be empty for this to work,
+  // since we generate empty domains.
+
+  PAssert(domain.empty());
+
+  // Loop through the patches in the reference domain now.  For each one,
+  // just add in an empty domain, assigned to the same context
+  // as the current node that we're iterating over.
+
+  typename RefLayout_t::const_iterator refpatch,
+    endref = reference().endGlobal();
+
+  for (refpatch=reference().beginGlobal(); refpatch != endref; ++refpatch)
+    {
+      Node<Dom> *node = new Node<Dom>(Dom(),
+                                     Dom(),
+                                     refpatch->context(),
+                                     refpatch->globalID(),
+                                     refpatch->localID());
+      all.push_back(node);
+    }
+
+  // This call to the mapper for the case of DefaultSPMapper
+  // is a no-op, and could be commented out. The above loop
+  // does both the partitioning and the mapping. The structure
+  // of the DefaultSPmapper is maintained for this special case
+  // even though it's redundant.
+
+  cmapper.map(all);
+
+  // Return the number of domains we added in.
+
+  return maxSize();
+}
+
+template<class ReferenceLayout>
+template<class Out>
+void SpatialPartition<ReferenceLayout>::print(Out &o) const
+{
+  o << "SpatialPartitioner:\n";
+  o << "  reference layout = " << reference() << "\n";
+  o << "  maximum patches = " << maxSize() << "\n";
+}


 //-----------------------------------------------------------------------------
Index: src/Partition/TilePartition.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/TilePartition.h,v
retrieving revision 1.12
diff -u -u -r1.12 TilePartition.h
--- src/Partition/TilePartition.h       23 Jan 2003 20:04:39 -0000      1.12
+++ src/Partition/TilePartition.h       4 Aug 2003 18:44:01 -0000
@@ -83,55 +83,58 @@
   {
   }

-  void map(const List_t & templist) const
-  {
-    int ncontexts = Pooma::contexts();
-    int npc = templist.size()/ncontexts;
-    if (templist.size()%ncontexts!=0) ++npc;
-
-    typename List_t::const_iterator start = templist.begin();
-    typename List_t::const_iterator end = templist.end();
-    int c = 0;
-    int p = 0;
-    for ( ; start!=end ; ++start)
-      {
-       (*start)->context() = p;
-       if(p == Pooma::context())
-         (*start)->localID() = c;
-
-       ++c;
-       if (c > npc)
-         {
-           ++p;
-           c = 0;
-         }
-      }
-
-    int affinityMax = Smarts::concurrency();
-    int idMax = 0;
-
-    start = templist.begin();
-    for ( ; start != end ; ++start)
-      if((*start)->context()==Pooma::context())
-       {
-         (*start)->localID()=idMax;
-         ++idMax;
-       }
-     start = templist.begin();
-     for ( ; start != end ; ++start)
-       {
-        if((*start)->context()==Pooma::context())
-          (*start)->affinity() = static_cast<int>( affinityMax *
-                                 ( (*start)->localID() /
-                                 static_cast<double>(idMax) ) );
-       }
-  }
+  void map(const List_t & templist) const;

   // member data
 private:

 };

+template<int Dim>
+void DefaultTPmapper<Dim>::map(const List_t & templist) const
+{
+  int ncontexts = Pooma::contexts();
+  int npc = templist.size()/ncontexts;
+  if (templist.size()%ncontexts!=0) ++npc;
+
+  typename List_t::const_iterator start = templist.begin();
+  typename List_t::const_iterator end = templist.end();
+  int c = 0;
+  int p = 0;
+  for ( ; start!=end ; ++start)
+    {
+      (*start)->context() = p;
+      if(p == Pooma::context())
+       (*start)->localID() = c;
+
+      ++c;
+      if (c > npc)
+       {
+         ++p;
+         c = 0;
+       }
+    }
+
+  int affinityMax = Smarts::concurrency();
+  int idMax = 0;
+
+  start = templist.begin();
+  for ( ; start != end ; ++start)
+    if((*start)->context()==Pooma::context())
+      {
+       (*start)->localID()=idMax;
+       ++idMax;
+      }
+  start = templist.begin();
+  for ( ; start != end ; ++start)
+    {
+      if((*start)->context()==Pooma::context())
+       (*start)->affinity() = static_cast<int>( affinityMax *
+                                                ( (*start)->localID() /
+                              static_cast<double>(idMax) ) );
+    }
+}
+


 //-----------------------------------------------------------------------------
@@ -319,78 +322,7 @@
   //============================================================

   template<class D>
-  int partition(const D &bbox,List_t &all,const ContextMapper<Dim> &cmapper) 
const
-  {
-    typedef typename DomainTraits<Domain_t>::Element_t Element_t;
-
-    // Make sure we have the right dimensionality.
-
-    CTAssert(Dim == DomainTraits<Domain_t>::dimensions);
-
-    typename PatchList_t::const_iterator start = tile_m.begin();
-    typename PatchList_t::const_iterator end = tile_m.end();
-
-    while (start!=end)
-      {
-       Domain_t o = Pooma::NoInit();
-       o = * start;
-       Domain_t oo = o;
-       Domain_t a = Pooma::NoInit();
-       a = * start;
-
-       if (hasInternalGuards()||hasExternalGuards())
-         {
-           for (int i=0;i<Dim;i++)
-             {
-               if (oo[i].first() == bbox[i].first())
-                 {
-                   if (hasExternalGuards())
-                     {
-                       o[i]=Interval<1>(o[i].first()-externalGuards().lower(i),
-                                        o[i].last());
-                       a[i]=Interval<1>(a[i].first()-externalGuards().lower(i),
-                                        a[i].last());
-                     }
-                   if (hasInternalGuards() && oo[i].last() != bbox[i].last() )
-                     a[i]=Interval<1>(a[i].first(),
-                                      a[i].last()+internalGuards().upper(i));
-                 }
-               if (oo[i].last()== bbox[i].last())
-                 {
-                   if (hasExternalGuards())
-                     {
-                       o[i]=Interval<1>(o[i].first(),
-                                        o[i].last()+externalGuards().upper(i));
-                       a[i]=Interval<1>(a[i].first(),
-                                        a[i].last()+externalGuards().upper(i));
-                     }
-                   if (hasInternalGuards()&&(oo[i].first() != bbox[i].first()))
-                     a[i]=Interval<1>(a[i].first()-internalGuards().lower(i),
-                                      a[i].last());
-                 }
-               if (oo[i].first()!=bbox[i].first() &&
-                   oo[i].last() != bbox[i].last() &&
-                  hasInternalGuards()) // it's a fully internal patch
-                 a[i]=Interval<1>(o[i].first()-internalGuards().lower(i),
-                                  o[i].last()+internalGuards().upper(i));
-
-             }
-         }
-
-       // Add the domain to the layout.
-
-       Value_t * node = new Value_t(o,a,-1,all.size(),-1);
-       all.push_back(node);
-
-       // Increment our counters and iterators.
-
-       ++start;
-      }
-
-    cmapper.map(all);
-
-    return all.size();
-  }
+  int partition(const D &bbox,List_t &all,const ContextMapper<Dim> &cmapper) 
const;

   template<class D>
   int partition(const D &bbox,List_t &all) const
@@ -399,32 +331,7 @@
   }

   template<class Out>
-  void print(Out &o) const
-  {
-    int i;
-    o << "TilePartition<" << Dim << ">:" << std::endl;
-    o << "  hasInternalGuards_m  hasExternalGuards_m = ";
-    o << hasInternalGuards_m<< " "<<hasExternalGuards_m<< std::endl;
-    o << "  internalGuards_m:" << std::endl;
-    o << "      upper       ";
-    for (i=0; i < Dim; ++i)
-      o << internalGuards_m.upper(i) << " ";
-    o << std::endl;
-    o << "      lower       ";
-    for (i=0; i < Dim; ++i)
-      o << internalGuards_m.lower(i) << " ";
-    o << std::endl;
-    o << "  externalGuards_m:" << std::endl;
-    o << "      upper       ";
-    for (i=0; i < Dim; ++i)
-      o << externalGuards_m.upper(i) << " ";
-    o << std::endl;
-    o << "      lower       ";
-    for (i=0; i < Dim; ++i)
-      o << externalGuards_m.lower(i) << " ";
-    o << std::endl;
-    o << "  num_m = " << num_m << std::endl;
-  }
+  void print(Out &o) const;

 private:

@@ -454,6 +361,110 @@

 };

+template<int Dim>
+template<class D>
+int TilePartition<Dim>::partition(const D &bbox, List_t &all,
+                                 const ContextMapper<Dim> &cmapper) const
+{
+  typedef typename DomainTraits<Domain_t>::Element_t Element_t;
+
+  // Make sure we have the right dimensionality.
+
+  CTAssert(Dim == DomainTraits<Domain_t>::dimensions);
+
+  typename PatchList_t::const_iterator start = tile_m.begin();
+  typename PatchList_t::const_iterator end = tile_m.end();
+
+  while (start!=end)
+    {
+      Domain_t o = Pooma::NoInit();
+      o = * start;
+      Domain_t oo = o;
+      Domain_t a = Pooma::NoInit();
+      a = * start;
+
+      if (hasInternalGuards()||hasExternalGuards())
+       {
+         for (int i=0;i<Dim;i++)
+           {
+             if (oo[i].first() == bbox[i].first())
+               {
+                 if (hasExternalGuards())
+                   {
+                     o[i]=Interval<1>(o[i].first()-externalGuards().lower(i),
+                                      o[i].last());
+                     a[i]=Interval<1>(a[i].first()-externalGuards().lower(i),
+                                      a[i].last());
+                   }
+                 if (hasInternalGuards() && oo[i].last() != bbox[i].last() )
+                   a[i]=Interval<1>(a[i].first(),
+                                    a[i].last()+internalGuards().upper(i));
+               }
+             if (oo[i].last()== bbox[i].last())
+               {
+                 if (hasExternalGuards())
+                   {
+                     o[i]=Interval<1>(o[i].first(),
+                                      o[i].last()+externalGuards().upper(i));
+                     a[i]=Interval<1>(a[i].first(),
+                                      a[i].last()+externalGuards().upper(i));
+                   }
+                 if (hasInternalGuards()&&(oo[i].first() != bbox[i].first()))
+                   a[i]=Interval<1>(a[i].first()-internalGuards().lower(i),
+                                    a[i].last());
+               }
+             if (oo[i].first()!=bbox[i].first() &&
+                 oo[i].last() != bbox[i].last() &&
+                 hasInternalGuards()) // it's a fully internal patch
+               a[i]=Interval<1>(o[i].first()-internalGuards().lower(i),
+                                o[i].last()+internalGuards().upper(i));
+
+           }
+       }
+
+      // Add the domain to the layout.
+
+      Value_t * node = new Value_t(o,a,-1,all.size(),-1);
+      all.push_back(node);
+
+      // Increment our counters and iterators.
+
+      ++start;
+    }
+
+  cmapper.map(all);
+
+  return all.size();
+}
+
+template<int Dim>
+template<class Out>
+void TilePartition<Dim>::print(Out &o) const
+{
+  int i;
+  o << "TilePartition<" << Dim << ">:" << std::endl;
+  o << "  hasInternalGuards_m  hasExternalGuards_m = ";
+  o << hasInternalGuards_m<< " "<<hasExternalGuards_m<< std::endl;
+  o << "  internalGuards_m:" << std::endl;
+  o << "      upper       ";
+  for (i=0; i < Dim; ++i)
+    o << internalGuards_m.upper(i) << " ";
+  o << std::endl;
+  o << "      lower       ";
+  for (i=0; i < Dim; ++i)
+    o << internalGuards_m.lower(i) << " ";
+  o << std::endl;
+  o << "  externalGuards_m:" << std::endl;
+  o << "      upper       ";
+  for (i=0; i < Dim; ++i)
+    o << externalGuards_m.upper(i) << " ";
+  o << std::endl;
+  o << "      lower       ";
+  for (i=0; i < Dim; ++i)
+    o << externalGuards_m.lower(i) << " ";
+  o << std::endl;
+  o << "  num_m = " << num_m << std::endl;
+}


 //-----------------------------------------------------------------------------
Index: src/Partition/UniformGridPartition.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Partition/UniformGridPartition.h,v
retrieving revision 1.28
diff -u -u -r1.28 UniformGridPartition.h
--- src/Partition/UniformGridPartition.h        11 Dec 2001 20:43:30 -0000      
1.28
+++ src/Partition/UniformGridPartition.h        4 Aug 2003 18:44:01 -0000
@@ -286,140 +286,10 @@
   // 'layoutData.addDomainList(List_t &templist)'.  Return the
   // total number of subdomains added.

-
   template<class D>
   int partition(const D &domain,
                List_t & all,
-               const ContextMapper<Dim>& cmapper) const
-  {
-
-    // The type info for domain we should be creating for the layout.
-
-    typedef typename DomainTraits<Domain_t>::Element_t Element_t;
-
-    // Make sure we have the right dimensionality.
-
-    CTAssert(Dim == DomainTraits<D>::dimensions);
-    CTAssert(Dim == DomainTraits<Domain_t>::dimensions);
-
-    // This will only work with UnitStride domains
-
-    CTAssert(DomainTraits<D>::unitStride == 1);
-    CTAssert(DomainTraits<Domain_t>::unitStride == 1);
-
-    // make sure the list is empty
-
-    PAssert(all.size() == 0);
-
-    // Cache the origin of the domain and make sure the domain is
-    // properly sized. Also, build a domain corresponding to the
-    // number of blocks in each direction for iterating over below.
-
-    Element_t origin[Dim];
-    Element_t sizes[Dim];
-    Interval<Dim> bdomain = Pooma::NoInit(); // dummy initializer
-
-    int i;
-
-    for (i = 0; i < Dim; ++i)
-      {
-       if (!domain.empty())
-         {
-           int gcwidth =
-             (internalGuards_m.lower(i) > internalGuards_m.upper(i)) ?
-             internalGuards_m.lower(i) : internalGuards_m.upper(i);
-
-           PInsist((domain[i].length() % blocks()[i].first()) == 0,
-                   "All the blocks in a grid must be the same size.");
-
-           origin[i]  = domain[i].first();
-           sizes[i]   = domain[i].length() / blocks()[i].first();
-
-           PInsist(sizes[i] >= gcwidth,
-                   "Block sizes too small for guard layer specification.");
-         }
-       bdomain[i] = Interval<1>(blocks()[i].first());
-      }
-
-    // Loop over all the blocks, creating new domains.
-
-    typename Interval<Dim>::const_iterator it = bdomain.begin();
-    while (it != bdomain.end())
-      {
-       // Start with an initially empty domain and empty guard cells.
-
-       Domain_t owned;
-       GuardLayers<Dim> iguards(0);
-       GuardLayers<Dim> eguards(0);
-
-       // Calculate the subdomain, if the global domain is not empty.
-       // If it is, we just use the empty domain.
-
-       if (!domain.empty())
-         {
-           Loc<Dim> pos = *it;
-           for (i = 0; i < Dim; ++i)
-             {
-               int position = pos[i].first();
-               Element_t a = origin[i] + sizes[i]*position;
-               Element_t b = a + sizes[i] - 1;
-               typedef typename
-                 DomainTraits<Domain_t>::OneDomain_t OneDomain_t;
-               owned[i] = OneDomain_t(a, b);
-             }
-
-           // Calculate the internal and external guard layer specifications
-           // for this domain.
-
-           if (hasGuards_m)
-             {
-               iguards = internalGuards_m;
-
-               // Check if we're at an edge, and, if so, use the
-               // external specification for that edge.
-
-               for (int d = 0; d < Dim; ++d)
-                 {
-                   int position = pos[d].first();
-                   if ( position == bdomain[d].first() )
-                     {
-                       eguards.lower(d) = externalGuards_m.lower(d);
-                       iguards.lower(d) = 0;
-                     }
-                   if ( position == bdomain[d].last() )
-                     {
-                       eguards.upper(d) = externalGuards_m.upper(d);
-                       iguards.upper(d) = 0;
-                     }
-                 }
-             }
-         }
-       typename Value_t::ID_t gid = all.size();
-       typename Value_t::ID_t lid = (-1);
-
-       // Create a new Node object to store the subdomain data.
-
-       GuardLayers<Dim>::addGuardLayers(owned,eguards);
-
-       Domain_t allocated = owned;
-
-       GuardLayers<Dim>::addGuardLayers(allocated,iguards);
-
-       Value_t *node = new Value_t(owned, allocated, -1, gid, lid);
-
-       all.push_back(node);
-
-       // Increment our counters and iterators.
-
-       ++it;
-      }
-
-    cmapper.map(all);
-
-    // At the end, return # of domains created.
-
-    return num_m;
-  }
+               const ContextMapper<Dim>& cmapper) const;

   template<class D>
   int partition(const D &domain, List_t & list) const
@@ -470,6 +340,141 @@
 //============================================================
 // UniformGridPartition inline method definitions
 //============================================================
+
+template<int Dim>
+template<class D>
+int UniformGridPartition<Dim>::partition(const D &domain,
+                                        List_t & all,
+                                        const ContextMapper<Dim>& cmapper) 
const
+{
+  // The type info for domain we should be creating for the layout.
+
+  typedef typename DomainTraits<Domain_t>::Element_t Element_t;
+
+  // Make sure we have the right dimensionality.
+
+  CTAssert(Dim == DomainTraits<D>::dimensions);
+  CTAssert(Dim == DomainTraits<Domain_t>::dimensions);
+
+  // This will only work with UnitStride domains
+
+  CTAssert(DomainTraits<D>::unitStride == 1);
+  CTAssert(DomainTraits<Domain_t>::unitStride == 1);
+
+  // make sure the list is empty
+
+  PAssert(all.size() == 0);
+
+  // Cache the origin of the domain and make sure the domain is
+  // properly sized. Also, build a domain corresponding to the
+  // number of blocks in each direction for iterating over below.
+
+  Element_t origin[Dim];
+  Element_t sizes[Dim];
+  Interval<Dim> bdomain = Pooma::NoInit(); // dummy initializer
+
+  int i;
+
+  for (i = 0; i < Dim; ++i)
+    {
+      if (!domain.empty())
+       {
+         int gcwidth =
+           (internalGuards_m.lower(i) > internalGuards_m.upper(i)) ?
+           internalGuards_m.lower(i) : internalGuards_m.upper(i);
+
+         PInsist((domain[i].length() % blocks()[i].first()) == 0,
+                 "All the blocks in a grid must be the same size.");
+
+         origin[i]  = domain[i].first();
+         sizes[i]   = domain[i].length() / blocks()[i].first();
+
+         PInsist(sizes[i] >= gcwidth,
+                 "Block sizes too small for guard layer specification.");
+       }
+      bdomain[i] = Interval<1>(blocks()[i].first());
+    }
+
+  // Loop over all the blocks, creating new domains.
+
+  typename Interval<Dim>::const_iterator it = bdomain.begin();
+  while (it != bdomain.end())
+    {
+      // Start with an initially empty domain and empty guard cells.
+
+      Domain_t owned;
+      GuardLayers<Dim> iguards(0);
+      GuardLayers<Dim> eguards(0);
+
+      // Calculate the subdomain, if the global domain is not empty.
+      // If it is, we just use the empty domain.
+
+      if (!domain.empty())
+       {
+         Loc<Dim> pos = *it;
+         for (i = 0; i < Dim; ++i)
+           {
+             int position = pos[i].first();
+             Element_t a = origin[i] + sizes[i]*position;
+             Element_t b = a + sizes[i] - 1;
+             typedef typename
+               DomainTraits<Domain_t>::OneDomain_t OneDomain_t;
+             owned[i] = OneDomain_t(a, b);
+           }
+
+         // Calculate the internal and external guard layer specifications
+         // for this domain.
+
+         if (hasGuards_m)
+           {
+             iguards = internalGuards_m;
+
+             // Check if we're at an edge, and, if so, use the
+             // external specification for that edge.
+
+             for (int d = 0; d < Dim; ++d)
+               {
+                 int position = pos[d].first();
+                 if ( position == bdomain[d].first() )
+                   {
+                     eguards.lower(d) = externalGuards_m.lower(d);
+                     iguards.lower(d) = 0;
+                   }
+                 if ( position == bdomain[d].last() )
+                   {
+                     eguards.upper(d) = externalGuards_m.upper(d);
+                     iguards.upper(d) = 0;
+                   }
+               }
+           }
+       }
+      typename Value_t::ID_t gid = all.size();
+      typename Value_t::ID_t lid = (-1);
+
+      // Create a new Node object to store the subdomain data.
+
+      GuardLayers<Dim>::addGuardLayers(owned,eguards);
+
+      Domain_t allocated = owned;
+
+      GuardLayers<Dim>::addGuardLayers(allocated,iguards);
+
+      Value_t *node = new Value_t(owned, allocated, -1, gid, lid);
+
+      all.push_back(node);
+
+      // Increment our counters and iterators.
+
+      ++it;
+    }
+
+  cmapper.map(all);
+
+  // At the end, return # of domains created.
+
+  return num_m;
+}
+

 //-----------------------------------------------------------------------------
 //



reply via email to

[Prev in Thread] Current Thread [Next in Thread]