[MOAB-dev] r1932 - in MOAB/trunk: parallel tools/mbcoupler

tautges at mcs.anl.gov tautges at mcs.anl.gov
Thu Jun 26 13:39:15 CDT 2008


Author: tautges
Date: 2008-06-26 13:39:15 -0500 (Thu, 26 Jun 2008)
New Revision: 1932

Modified:
   MOAB/trunk/parallel/tuple_list.h
   MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
   MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
Log:
Modified tuple_list to not try to allocate zero-sized memory.

Don't try to map remotely if a locally containing element is found.

Fixed a few bad dimensions of tuple lists and other assorted bugs.


Modified: MOAB/trunk/parallel/tuple_list.h
===================================================================
--- MOAB/trunk/parallel/tuple_list.h	2008-06-26 14:55:10 UTC (rev 1931)
+++ MOAB/trunk/parallel/tuple_list.h	2008-06-26 18:39:15 UTC (rev 1932)
@@ -36,10 +36,10 @@
 {
   tl->n=0; tl->max=max;
   tl->mi=mi,tl->ml=ml,tl->mul=mul,tl->mr=mr;
-  tl->vi=tmalloc(sint, max*mi);
-  tl->vl=tmalloc(slong,max*ml);
-  tl->vul=tmalloc(ulong,max*mul);
-  tl->vr=tmalloc(real, max*mr);
+  tl->vi=(max ? tmalloc(sint, max*mi) : 0);
+  tl->vl=(max ? tmalloc(slong,max*ml) : 0);
+  tl->vul=(max ? tmalloc(ulong,max*mul) : 0);
+  tl->vr=(max ? tmalloc(real, max*mr) : 0);
 }
 
 static void tuple_list_free(tuple_list *tl) {
@@ -57,7 +57,7 @@
 
 static void tuple_list_grow(tuple_list *tl)
 {
-  tuple_list_resize(tl,tl->max+tl->max/2+1);
+  tuple_list_resize(tl,(tl->max ? tl->max+tl->max/2+1 : 2));
 }
 
 void tuple_list_permute(tuple_list *tl, uint *perm, void *work);

Modified: MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2008-06-26 14:55:10 UTC (rev 1931)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2008-06-26 18:39:15 UTC (rev 1932)
@@ -90,52 +90,62 @@
 
     // allocate tuple_list to hold point data: (p, i, , xyz), i = point index
   tuple_list target_pts;
-  tuple_list_init_max(&target_pts, 2, 0, 0, 3, 3*num_points);
+  tuple_list_init_max(&target_pts, 2, 0, 0, 3, num_points);
 
     // initialize source_pts and local_pts
   tuple_list source_pts;
   mappedPts = new tuple_list;
-  tuple_list_init_max(&source_pts, 3, 0, 0, 0, target_pts.n); 
-  tuple_list_init_max(mappedPts, 0, 0, 1, 3, target_pts.n); 
+  tuple_list_init_max(&source_pts, 3, 0, 0, 0, target_pts.max); 
+  tuple_list_init_max(mappedPts, 0, 0, 1, 3, target_pts.max); 
 
   mappedPts->n = 0;
   source_pts.n = 0;
   MBErrorCode result;
 
+    // keep track of which points have been located
+  std::vector<unsigned char> located_pts(num_points, 0);
+
     // for each point, find box(es) containing the point,
     // appending results to tuple_list;
     // keep local points separately, in local_pts, which has pairs
     // of <local_index, mapped_index>, where mapped_index is the index
     // of <local_index, mapped_index>, where mapped_index is the index
     // into the mappedPts tuple list
+
+  unsigned int my_rank = myPc->proc_config().proc_rank();
+  bool point_located;
   
   for (int i = 0; i < 3*num_points; i+=3) 
-  {	
+  {
+      // test point locally first
+    result = test_local_box(xyz+i, my_rank, i/3, i/3, point_located);
+    if (MB_SUCCESS != result) return result;
+    if (point_located) {
+      located_pts[i/3] = 0x1;
+      continue;
+    }
+
+      // if not located locally, test other procs' boxes
     for (unsigned int j = 0; j < myPc->proc_config().proc_size(); j++)
     {
-        // test if point is in box
+      if (j == my_rank) continue;
+      
+        // test if point is in proc's box
       if (allBoxes[6*j] <= xyz[i] && xyz[i] <= allBoxes[6*j+3] && 
           allBoxes[6*j+1] <= xyz[i+1] && xyz[i+1] <= allBoxes[6*j+4] && 
           allBoxes[6*j+2] <= xyz[i+2] && xyz[i+2] <= allBoxes[6*j+5])
       {
-        if (j == myPc->proc_config().proc_rank())
-        {
-          result = test_local_box(xyz+i, j, i/3, i/3);
-        }
-        else {
-            // check size, grow if we're at max
-          if (target_pts.n == target_pts.max)
-            tuple_list_grow(&target_pts);
-
-	target_pts.n++;
+          // if in this proc's box, will send to proc to test further
+          // check size, grow if we're at max
+        if (target_pts.n == target_pts.max)
+          tuple_list_grow(&target_pts);
   
-          target_pts.vi[2*target_pts.n] = j;
-          target_pts.vi[2*target_pts.n+1] = i/3;
-
-          target_pts.vr[3*target_pts.n] = xyz[i];
-          target_pts.vr[3*target_pts.n+1] = xyz[i+1];
-          target_pts.vr[3*target_pts.n+2] = xyz[i+2];
-        }
+        target_pts.vi[2*target_pts.n] = j;
+        target_pts.vi[2*target_pts.n+1] = i/3;
+        target_pts.vr[3*target_pts.n] = xyz[i];
+        target_pts.vr[3*target_pts.n+1] = xyz[i+1];
+        target_pts.vr[3*target_pts.n+2] = xyz[i+2];
+        target_pts.n++;
       }
     }
   }
@@ -160,18 +170,19 @@
     // mappedPts->vul[i] = local handle of mapped entity
     // mappedPts->vr[3*i..3*i+2] = natural coordinates in mapped entity
 
+    // test target points against my elements
   for (unsigned i = 0; i < target_pts.n; i++) 
   {
     result = test_local_box(target_pts.vr+3*i, 
-                            target_pts.vi[3*i], target_pts.vi[3*i+1], i, 
-                            &source_pts);
+                            target_pts.vi[2*i], target_pts.vi[2*i+1], i, 
+                            point_located, &source_pts);
     if (MB_SUCCESS != result) return result;
   }
 
   // no longer need target_pts
   tuple_list_free(&target_pts);
 
-  // perform scatter/gather to send proc/index tuples back to procs
+    // send target points back to target procs
   gs_transfer(1, &source_pts, 0, myPc->proc_config().crystal_router());
 
   // store proc/index tuples in targetPts, and/or pass back to application;
@@ -184,24 +195,27 @@
   // Local index is mapped into either myRange, holding the handles of
   // local mapped entities, or myXyz, holding locations of mapped pts
 
-  // go through and count non-negatives
+  // count non-negatives
   int num_pts = 0;
   for (unsigned int i = 0; i < source_pts.n; i++)
     if (-1 != source_pts.vi[3*i+2]) num_pts++;
 
+    // store information about located points
   targetPts = new tuple_list;
   tuple_list *tl_tmp = targetPts;
   if (!store_local) tl_tmp = tl;
   tuple_list_init_max(tl_tmp, 3, 0, 0, 1, num_pts);
   for (unsigned int i = 0; i < source_pts.n; i++) {
-    if (-1 != source_pts.vi[3*i+2]) {
-      tl_tmp->n++;
+    if (-1 != source_pts.vi[3*i+2] && !located_pts[3*i+1]) {
       tl_tmp->vi[3*i] = source_pts.vi[3*i];
       tl_tmp->vi[3*i+1] = source_pts.vi[3*i+1];
       tl_tmp->vi[3*i+2] = source_pts.vi[3*i+2];
+      tl_tmp->n++;
     }
   }
 
+  assert(tl_tmp->n + localMappedPts.size()/2 == (unsigned int) num_points);
+  
     // no longer need source_pts
   tuple_list_free(&source_pts);
 
@@ -218,6 +232,7 @@
 
 MBErrorCode MBCoupler::test_local_box(double *xyz, 
                                       int from_proc, int remote_index, int index, 
+                                      bool &point_located,
                                       tuple_list *tl)
 {
   
@@ -227,8 +242,6 @@
   MBErrorCode result = nat_param(xyz, entities, nat_coords);
   if (MB_SUCCESS != result) return result;
 
-  if (entities.empty()) return MB_SUCCESS;
-  
     // grow if we know we'll exceed size
   if (mappedPts->n+entities.size() >= mappedPts->max)
     tuple_list_grow(mappedPts);
@@ -237,6 +250,7 @@
     tl->vi[3*index] = from_proc;
     tl->vi[3*index+1] = remote_index;
     tl->vi[3*index+2] = -1;
+    point_located = false;
     return MB_SUCCESS;
   }
   
@@ -244,11 +258,11 @@
   std::vector<MBCartVect>::iterator ncit = nat_coords.begin();
   for (; eit != entities.end(); eit++, ncit++) {
       // store in tuple mappedPts
-    mappedPts->n++;
     mappedPts->vr[3*mappedPts->n] = (*ncit)[0];
     mappedPts->vr[3*mappedPts->n+1] = (*ncit)[1];
     mappedPts->vr[3*mappedPts->n+2] = (*ncit)[2];
     mappedPts->vul[mappedPts->n] = *eit;
+    mappedPts->n++;
 
       // also store local point, mapped point indices
     if (tl) 
@@ -256,16 +270,18 @@
       if (tl->n == tl->max) tuple_list_grow(tl);
 
         // store in tuple source_pts
-      tl->n++;
       tl->vi[3*tl->n] = from_proc;
       tl->vi[3*tl->n+1] = remote_index;
       tl->vi[3*tl->n+2] = mappedPts->n;
+      tl->n++;
     }
     else {
       localMappedPts.push_back(index);
       localMappedPts.push_back(mappedPts->n);
     }
   }
+
+  point_located = true;
   
   return MB_SUCCESS;
 }
@@ -385,6 +401,7 @@
         -1.0 <= tmp_nat_coords[2] && tmp_nat_coords[2] <= 1.0) {
       entities.push_back(*iter);
       nat_coords.push_back(tmp_nat_coords);
+      return MB_SUCCESS;
     }
   }
   

Modified: MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2008-06-26 14:55:10 UTC (rev 1931)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2008-06-26 18:39:15 UTC (rev 1932)
@@ -143,6 +143,7 @@
   
   MBErrorCode test_local_box(double *xyz, 
                              int from_proc, int remote_index, int index, 
+                             bool &point_located,
                              tuple_list *tl = NULL);
   
     /* \brief MOAB instance




More information about the moab-dev mailing list