]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement the destroy_communicator() function. Use it for Trilinos objects, and make...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 7 Sep 2009 00:13:02 +0000 (00:13 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 7 Sep 2009 00:13:02 +0000 (00:13 +0000)
git-svn-id: https://svn.dealii.org/trunk@19404 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/utilities.cc
deal.II/lac/include/lac/trilinos_vector.h
deal.II/lac/source/trilinos_sparse_matrix.cc
deal.II/lac/source/trilinos_sparsity_pattern.cc
deal.II/lac/source/trilinos_vector.cc

index 6a14aa3f33bbce923b36ad4eddf9300049961de7..eb5062b9708d7f2474b3eccb649fe7b205a323a8 100644 (file)
@@ -665,6 +665,28 @@ namespace Utilities
              ExcInternalError());
       return new Epetra_SerialComm(dynamic_cast<const Epetra_SerialComm&>(communicator));
     }
+
+
+
+    void destroy_communicator (Epetra_Comm &communicator)
+    {
+      Assert (&communicator != 0, ExcInternalError());
+      
+                                      // save the communicator, reset
+                                      // the map, and delete the
+                                      // communicator if this whole
+                                      // thing was created as an MPI
+                                      // communicator
+      Epetra_MpiComm
+       *mpi_comm = dynamic_cast<Epetra_MpiComm *>(&communicator);
+      if (mpi_comm != 0)
+       {
+         MPI_Comm comm = mpi_comm->GetMpiComm();
+         *mpi_comm = Epetra_MpiComm(MPI_COMM_SELF);
+         MPI_Comm_free (&comm);
+       }
+    }
+
     
 
     unsigned int get_n_mpi_processes (const Epetra_Comm &mpi_communicator)
index c5dc2e01aee85d301977436383b90caf92722ac4..7588fc86915aac2535db5658a3d9d4bcc0360b88 100755 (executable)
@@ -159,7 +159,7 @@ namespace TrilinosWrappers
  * @ingroup TrilinosWrappers
  * @ingroup Vectors
  * @see @ref SoftwareTrilinos
- * @author Martin Kronbichler, Wolfgang Bangerth, 2008
+ * @author Martin Kronbichler, Wolfgang Bangerth, 2008, 2009
  */
     class Vector : public VectorBase
     {
@@ -219,6 +219,11 @@ namespace TrilinosWrappers
         explicit Vector (const Epetra_Map             &InputMap,
                          const dealii::Vector<Number> &v);
 
+                                        /**
+                                         * Destructor.
+                                         */
+       ~Vector ();
+       
                                       /**
                                        * Reinit functionality. This
                                        * function destroys the old
index bdd43ee75da8d9513b20bd625627529bdfdf5d5d..01ab086ff87addfb2d3a29c9ed7c0e029576fc6b 100755 (executable)
@@ -258,7 +258,9 @@ namespace TrilinosWrappers
 
 
   SparseMatrix::~SparseMatrix ()
-  {}
+  {
+    Utilities::Trilinos::destroy_communicator (*communicator);
+  }
 
 
 
@@ -517,6 +519,7 @@ namespace TrilinosWrappers
                                     // model the communicator on the
                                     // one used for the sparsity
                                     // pattern
+    Utilities::Trilinos::destroy_communicator (*communicator);
     communicator.reset (Utilities::Trilinos::
                        duplicate_communicator (sparsity_pattern.trilinos_communicator()));
     
index a582dd80803e4b7579a23160b3dc1df9f2dd42bf..71a4ffe94e68c578f83ae23d860601d9079cc685 100755 (executable)
@@ -127,7 +127,8 @@ namespace TrilinosWrappers
   SparsityPattern::SparsityPattern (const Epetra_Map                &InputMap,
                                    const std::vector<unsigned int> &n_entries_per_row)
                  :
-                 communicator (Utilities::Trilinos::duplicate_communicator (InputMap.Comm())),
+                 communicator (Utilities::Trilinos::
+                               duplicate_communicator (InputMap.Comm())),
                   row_map (Utilities::Trilinos::duplicate_map (InputMap, *communicator)),
                  col_map (row_map),
                  compressed (false),
@@ -150,9 +151,12 @@ namespace TrilinosWrappers
                                    const Epetra_Map  &InputColMap,
                                    const unsigned int n_entries_per_row)
                  :
-                 communicator (Utilities::Trilinos::duplicate_communicator (InputRowMap.Comm())),
-                  row_map (Utilities::Trilinos::duplicate_map (InputRowMap, *communicator)),
-                  col_map (Utilities::Trilinos::duplicate_map (InputColMap, *communicator)),
+                 communicator (Utilities::Trilinos::
+                               duplicate_communicator (InputRowMap.Comm())),
+                  row_map (Utilities::Trilinos::
+                          duplicate_map (InputRowMap, *communicator)),
+                  col_map (Utilities::Trilinos::
+                          duplicate_map (InputColMap, *communicator)),
                  compressed (false),
                  graph (row_map.Comm().NumProc() > 1 ?
                         (std::auto_ptr<Epetra_FECrsGraph>
@@ -171,9 +175,12 @@ namespace TrilinosWrappers
                                    const Epetra_Map                &InputColMap,
                                    const std::vector<unsigned int> &n_entries_per_row)
                  :
-                 communicator (Utilities::Trilinos::duplicate_communicator (InputRowMap.Comm())),
-                  row_map (Utilities::Trilinos::duplicate_map (InputRowMap, *communicator)),
-                  col_map (Utilities::Trilinos::duplicate_map (InputColMap, *communicator)),
+                 communicator (Utilities::Trilinos::
+                               duplicate_communicator (InputRowMap.Comm())),
+                  row_map (Utilities::Trilinos::
+                          duplicate_map (InputRowMap, *communicator)),
+                  col_map (Utilities::Trilinos::
+                          duplicate_map (InputColMap, *communicator)),
                  compressed (false),
                  graph (row_map.Comm().NumProc() > 1 ?
                         (std::auto_ptr<Epetra_FECrsGraph>
@@ -239,7 +246,16 @@ namespace TrilinosWrappers
 
 
   SparsityPattern::~SparsityPattern ()
-  {}
+  {
+// this is sorta tricky. we can't destroy the communicator here
+// if we have initialized a matrix with it because the matrix
+// keeps a reference count to the sparsity pattern and so
+// the communicator has to stay alive even though the sparsity
+// pattern goes out of scope :-(
+//
+// TODO: find a way to fix this    
+//    Utilities::Trilinos::destroy_communicator (*communicator);
+  }
 
 
 
@@ -268,6 +284,7 @@ namespace TrilinosWrappers
                           const Epetra_Map   &input_col_map,
                           const unsigned int  n_entries_per_row)
   {
+    Utilities::Trilinos::destroy_communicator (*communicator);
     communicator.reset (Utilities::Trilinos::
                        duplicate_communicator (input_row_map.Comm()));
 
@@ -330,6 +347,7 @@ namespace TrilinosWrappers
            ExcDimensionMismatch (n_entries_per_row.size(),
                                  input_row_map.NumGlobalElements()));
 
+    Utilities::Trilinos::destroy_communicator (*communicator);
     communicator.reset (Utilities::Trilinos::
                        duplicate_communicator (input_row_map.Comm()));
 
@@ -379,6 +397,7 @@ namespace TrilinosWrappers
            ExcDimensionMismatch (sp.n_cols(),
                                  input_col_map.NumGlobalElements()));
 
+    Utilities::Trilinos::destroy_communicator (*communicator);
     communicator.reset (Utilities::Trilinos::
                        duplicate_communicator (input_row_map.Comm()));
 
@@ -447,6 +466,7 @@ namespace TrilinosWrappers
            ExcDimensionMismatch (sp.n_cols(),
                                  input_col_map.NumGlobalElements()));
 
+    Utilities::Trilinos::destroy_communicator (*communicator);
     communicator.reset (Utilities::Trilinos::
                        duplicate_communicator (input_row_map.Comm()));
 
index b53d8bed257890b8709954b09bc17c7e585fc08b..923cccdf6485564a4201be0ed3730123e8b93e84 100755 (executable)
@@ -95,12 +95,20 @@ namespace TrilinosWrappers
 
 
 
+    Vector::~Vector ()
+    {
+      Utilities::Trilinos::destroy_communicator (*communicator);
+    }
+    
+
+
     void
     Vector::reinit (const Epetra_Map &input_map,
                    const bool        fast)
     {
       vector.reset();
 
+      Utilities::Trilinos::destroy_communicator (*communicator);
       communicator.reset (Utilities::Trilinos::
                          duplicate_communicator(input_map.Comm()));
       map = Utilities::Trilinos::duplicate_map (input_map, *communicator);
@@ -136,6 +144,7 @@ namespace TrilinosWrappers
          if (vector->Map().SameAs(v.vector->Map()) == false)
            {
              vector.reset();
+             Utilities::Trilinos::destroy_communicator (*communicator);
              communicator.reset (Utilities::Trilinos::
                                  duplicate_communicator(v.trilinos_vector()
                                                         .Map().Comm()));
@@ -212,6 +221,7 @@ namespace TrilinosWrappers
        {
          vector.reset();
 
+         Utilities::Trilinos::destroy_communicator (*communicator);
          communicator.reset (Utilities::Trilinos::
                              duplicate_communicator(v.trilinos_vector().
                                                     Map().Comm()));

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.