[cig-commits] r15601 - short/3D/PyLith/trunk/libsrc/topology

brad at geodynamics.org brad at geodynamics.org
Wed Aug 26 17:26:06 PDT 2009


Author: brad
Date: 2009-08-26 17:26:06 -0700 (Wed, 26 Aug 2009)
New Revision: 15601

Modified:
   short/3D/PyLith/trunk/libsrc/topology/Field.cc
   short/3D/PyLith/trunk/libsrc/topology/Field.hh
Log:
Eliminated use of temporary PETSc vector in scatter by making it a class member.

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.cc	2009-08-27 00:16:42 UTC (rev 15600)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.cc	2009-08-27 00:26:06 UTC (rev 15601)
@@ -33,6 +33,7 @@
   _mesh(mesh),
   _vector(0),
   _scatter(0),
+  _scatterVec(0),
   _vecFieldType(OTHER),
   _dimensionsOkay(false)
 { // constructor
@@ -62,6 +63,11 @@
     err = VecScatterDestroy(_scatter); _scatter = 0;
     CHECK_PETSC_ERROR(err);
   } // if
+
+  if (0 != _scatterVec) {
+    err = VecDestroy(_scatterVec); _scatterVec = 0;
+    CHECK_PETSC_ERROR(err);
+  } // if
 } // deallocate
 
 // ----------------------------------------------------------------------
@@ -250,6 +256,8 @@
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
   //std::cout << "Making Field " << _label << " section type 3" << std::endl;
   logger.stagePush("Field");
+
+  deallocate();
   _vecFieldType = src._vecFieldType;
   _scale = src._scale;
   _dimensionsOkay = false;
@@ -267,10 +275,14 @@
     _section->setBC(srcSection->getBC());
     _section->copyFibration(srcSection);
 
+    PetscErrorCode err = 0;
     if (0 != src._scatter) {
       _scatter = src._scatter;
-      PetscErrorCode err = PetscObjectReference((PetscObject) _scatter);
+      err = PetscObjectReference((PetscObject) _scatter);
       CHECK_PETSC_ERROR(err);
+      _scatterVec = src._scatterVec;
+      err = PetscObjectReference((PetscObject) _scatterVec);
+      CHECK_PETSC_ERROR(err);
     } // if
   } // if
   logger.stagePop();
@@ -654,9 +666,17 @@
     err = VecScatterDestroy(_scatter); _scatter = 0;
     CHECK_PETSC_ERROR(err);
   } // if
-
   err = MeshCreateGlobalScatter(_mesh.sieveMesh(), _section, &_scatter);
   CHECK_PETSC_ERROR(err);
+
+  if (0 != _scatterVec) {
+    err = VecDestroy(_scatterVec); _scatterVec = 0;
+    CHECK_PETSC_ERROR(err);
+  } // if
+  assert(_section->sizeWithBC() > 0);
+  err = VecCreateSeqWithArray(PETSC_COMM_SELF,
+			      _section->sizeWithBC(), _section->restrictSpace(),
+			      &_scatterVec); CHECK_PETSC_ERROR(err);
 } // createScatter
 
 // ----------------------------------------------------------------------
@@ -680,18 +700,14 @@
 { // scatterSectionToVector
   assert(!_section.isNull());
   assert(0 != _scatter);
+  assert(0 != _scatterVec);
   assert(0 != vector);
 
   PetscErrorCode err = 0;
-  PetscVec localVec = 0;
-  err = VecCreateSeqWithArray(PETSC_COMM_SELF,
-			      _section->sizeWithBC(), _section->restrictSpace(),
-			      &localVec); CHECK_PETSC_ERROR(err);
-  err = VecScatterBegin(_scatter, localVec, vector,
+  err = VecScatterBegin(_scatter, _scatterVec, vector,
 			INSERT_VALUES, SCATTER_FORWARD); CHECK_PETSC_ERROR(err);
-  err = VecScatterEnd(_scatter, localVec, vector,
+  err = VecScatterEnd(_scatter, _scatterVec, vector,
 		      INSERT_VALUES, SCATTER_FORWARD); CHECK_PETSC_ERROR(err);
-  err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
 } // scatterSectionToVector
 
 // ----------------------------------------------------------------------
@@ -715,18 +731,14 @@
 { // scatterVectorToSection
   assert(!_section.isNull());
   assert(0 != _scatter);
+  assert(0 != _scatterVec);
   assert(0 != vector);
 
   PetscErrorCode err = 0;
-  PetscVec localVec = 0;
-  err = VecCreateSeqWithArray(PETSC_COMM_SELF,
-			      _section->sizeWithBC(), _section->restrictSpace(),
-			      &localVec); CHECK_PETSC_ERROR(err);
-  err = VecScatterBegin(_scatter, vector, localVec,
+  err = VecScatterBegin(_scatter, vector, _scatterVec,
 			INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
-  err = VecScatterEnd(_scatter, vector, localVec,
+  err = VecScatterEnd(_scatter, vector, _scatterVec,
 		      INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
-  err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
 } // scatterVectorToSection
 
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.hh	2009-08-27 00:16:42 UTC (rev 15600)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.hh	2009-08-27 00:26:06 UTC (rev 15601)
@@ -291,6 +291,7 @@
   ALE::Obj<RealSection> _section; ///< Real section with data.
   PetscVec _vector; ///< PETSc vector associated with field.
   PetscVecScatter _scatter; ///< PETSc scatter associated with field.
+  PetscVec _scatterVec; ///< PETSC vector used in scattering.
   VectorFieldEnum _vecFieldType; ///< Type of vector field.
   bool _dimensionsOkay; ///< Flag indicating it is okay to dimensionalize.
 



More information about the CIG-COMMITS mailing list