]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move Trilinos index functions into a new header file. 4422/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 27 May 2017 21:56:09 +0000 (17:56 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Mon, 29 May 2017 02:37:31 +0000 (22:37 -0400)
doc/news/changes/minor/20170527DavidWells [new file with mode: 0644]
include/deal.II/lac/trilinos_index_access.h [new file with mode: 0644]
source/lac/trilinos_block_vector.cc
source/lac/trilinos_precondition_ml.cc
source/lac/trilinos_precondition_muelu.cc
source/lac/trilinos_sparse_matrix.cc
source/lac/trilinos_sparsity_pattern.cc
source/lac/trilinos_vector.cc

diff --git a/doc/news/changes/minor/20170527DavidWells b/doc/news/changes/minor/20170527DavidWells
new file mode 100644 (file)
index 0000000..5ed8c75
--- /dev/null
@@ -0,0 +1,4 @@
+New: There is a new header, <tt>lac/trilinos_index_access.h</tt>, that provides
+index and size functions for some common Trilinos objects that work correctly for
+both 32 and 64 bit code.
+<br> (David Wells, 2017/05/10)
diff --git a/include/deal.II/lac/trilinos_index_access.h b/include/deal.II/lac/trilinos_index_access.h
new file mode 100644 (file)
index 0000000..c57d42c
--- /dev/null
@@ -0,0 +1,222 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+#ifndef dealii__trilinos_index_access_h
+#define dealii__trilinos_index_access_h
+
+#include <deal.II/base/config.h>
+
+#ifdef DEAL_II_WITH_TRILINOS
+
+#include <deal.II/base/types.h>
+
+#include <Epetra_BlockMap.h>
+#include <Epetra_CrsGraph.h>
+#include <Epetra_CrsMatrix.h>
+#include <Epetra_MultiVector.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace TrilinosWrappers
+{
+  /**
+   * A helper function that queries the size of an Epetra_BlockMap object
+   * and calls either the 32 or 64 bit function to get the number of global
+   * elements in the map.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  n_global_elements(const Epetra_BlockMap &map)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return map.NumGlobalElements64();
+#else
+    return map.NumGlobalElements();
+#endif
+  }
+
+  /**
+   * A helper function that finds the minimum global index value on the
+   * calling processor by calling either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  min_my_gid(const Epetra_BlockMap &map)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return map.MinMyGID64();
+#else
+    return map.MinMyGID();
+#endif
+  }
+
+  /**
+   * A helper function that finds the maximum global index value on the
+   * calling processor by calling either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  max_my_gid(const Epetra_BlockMap &map)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return map.MaxMyGID64();
+#else
+    return map.MaxMyGID();
+#endif
+  }
+
+  /**
+   * A helper function that converts a local index to a global one calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  global_index(const Epetra_BlockMap &map,
+               const dealii::types::global_dof_index i)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return map.GID64(i);
+#else
+    return map.GID(i);
+#endif
+  }
+
+  /**
+   * A helper function that returns a pointer to the array containing the
+   * global indices assigned to the current process by calling either the 32
+   * or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type *
+  my_global_elements(const Epetra_BlockMap &map)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return map.MyGlobalElements64();
+#else
+    return map.MyGlobalElements();
+#endif
+  }
+
+  /**
+   * A helper function that finds the global number of rows by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  n_global_rows(const Epetra_CrsGraph &graph)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return graph.NumGlobalRows64();
+#else
+    return graph.NumGlobalRows();
+#endif
+  }
+
+  /**
+   * A helper function that finds the global number of columns by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  n_global_cols(const Epetra_CrsGraph &graph)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return graph.NumGlobalCols64();
+#else
+    return graph.NumGlobalCols();
+#endif
+  }
+
+  /**
+   * A helper function that finds the number of global entries by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  n_global_entries(const Epetra_CrsGraph &graph)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return graph.NumGlobalEntries64();
+#else
+    return graph.NumGlobalEntries();
+#endif
+  }
+
+  /**
+   * A helper function that finds the global row index by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  global_row_index(const Epetra_CrsMatrix &matrix,
+                   const dealii::types::global_dof_index i)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return matrix.GRID64(i);
+#else
+    return matrix.GRID(i);
+#endif
+  }
+
+  /**
+   * A helper function that finds the global column index by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  global_column_index(const Epetra_CrsMatrix &matrix,
+                      const dealii::types::global_dof_index i)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return matrix.GCID64(i);
+#else
+    return matrix.GCID(i);
+#endif
+  }
+
+  /**
+   * A helper function that finds the global length of a vector by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  global_length (const Epetra_MultiVector &vector)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return vector.GlobalLength64();
+#else
+    return vector.GlobalLength();
+#endif
+  }
+
+  /**
+   * A helper function that finds the global number of rows by calling
+   * either the 32 or 64 bit function.
+   */
+  inline
+  TrilinosWrappers::types::int_type
+  n_global_rows(const Epetra_RowMatrix &matrix)
+  {
+#ifdef DEAL_II_WITH_64BIT_INDICES
+    return matrix.NumGlobalRows64();
+#else
+    return matrix.NumGlobalRows();
+#endif
+  }
+}
+
+DEAL_II_NAMESPACE_CLOSE
+#endif // DEAL_II_WITH_TRILINOS
+#endif // dealii__trilinos_index_access_h
index 3f0b2fc64a11639429147ff5b6177a92b668933d..ed1e7bcd38af6f6e51ca6ba4a05a5419ec2cd3e2 100644 (file)
 
 #ifdef DEAL_II_WITH_TRILINOS
 
-#  include <deal.II/lac/trilinos_block_sparse_matrix.h>
+#include <deal.II/lac/trilinos_index_access.h>
+
+#include <deal.II/lac/trilinos_block_sparse_matrix.h>
 
 
 DEAL_II_NAMESPACE_OPEN
 
 namespace TrilinosWrappers
 {
-  namespace
-  {
-    // define a helper function that queries the size of an Epetra_Map object
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-#ifndef DEAL_II_WITH_64BIT_INDICES
-    int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements();
-    }
-#else
-    long long int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements64();
-    }
-#endif
-  }
-
-
   namespace MPI
   {
     BlockVector &
@@ -248,7 +230,7 @@ namespace TrilinosWrappers
     std::vector<size_type> block_sizes (no_blocks);
 
     for (size_type i=0; i<no_blocks; ++i)
-      block_sizes[i] = n_global_elements(input_maps[i]);
+      block_sizes[i] = TrilinosWrappers::n_global_elements(input_maps[i]);
 
 
     this->block_indices.reinit (block_sizes);
index cba0f83216afe78b9ddb8e6f3d2b16bc23b793e7..3912e3948014590064c5d2dff704587b4f63c3f9 100644 (file)
@@ -13,6 +13,7 @@
 //
 // ---------------------------------------------------------------------
 
+#include <deal.II/lac/trilinos_index_access.h>
 #include <deal.II/lac/trilinos_precondition.h>
 
 #ifdef DEAL_II_WITH_TRILINOS
@@ -20,6 +21,7 @@
 #  include <deal.II/lac/vector.h>
 #  include <deal.II/lac/sparse_matrix.h>
 #  include <deal.II/lac/trilinos_sparse_matrix.h>
+#  include <deal.II/lac/trilinos_index_access.h>
 
 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
 #  include <Ifpack.h>
@@ -35,43 +37,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace TrilinosWrappers
 {
-  namespace
-  {
-#ifndef DEAL_II_WITH_64BIT_INDICES
-    int n_global_rows (const Epetra_RowMatrix &matrix)
-    {
-      return matrix.NumGlobalRows();
-    }
-
-    int global_length (const Epetra_MultiVector &vector)
-    {
-      return vector.GlobalLength();
-    }
-
-    int gid(const Epetra_Map &map, unsigned int i)
-    {
-      return map.GID(i);
-    }
-#else
-    long long int n_global_rows (const Epetra_RowMatrix &matrix)
-    {
-      return matrix.NumGlobalRows64();
-    }
-
-    long long int global_length (const Epetra_MultiVector &vector)
-    {
-      return vector.GlobalLength64();
-    }
-
-    long long int gid(const Epetra_Map &map, dealii::types::global_dof_index i)
-    {
-      return map.GID64(i);
-    }
-#endif
-  }
-
-
-
   /* -------------------------- PreconditionAMG -------------------------- */
 
   PreconditionAMG::AdditionalData::
@@ -188,12 +153,12 @@ namespace TrilinosWrappers
 
     if (constant_modes_dimension > 0)
       {
-        const size_type global_size = n_global_rows(matrix);
+        const size_type global_size = TrilinosWrappers::n_global_rows(matrix);
         (void)global_length; // work around compiler warning about unused function in release mode
         Assert (global_size ==
-                static_cast<size_type>(global_length(distributed_constant_modes)),
+                static_cast<size_type>(TrilinosWrappers::global_length(distributed_constant_modes)),
                 ExcDimensionMismatch(global_size,
-                                     global_length(distributed_constant_modes)));
+                                     TrilinosWrappers::global_length(distributed_constant_modes)));
         const bool constant_modes_are_global
           = additional_data.constant_modes[0].size() == global_size;
         const size_type my_size = domain_map.NumMyElements();
@@ -209,7 +174,7 @@ namespace TrilinosWrappers
             for (size_type row=0; row<my_size; ++row)
               {
                 const TrilinosWrappers::types::int_type mode_index =
-                  constant_modes_are_global ? gid(domain_map,row) : row;
+                  constant_modes_are_global ? TrilinosWrappers::global_index(domain_map,row) : row;
                 distributed_constant_modes[d][row] =
                   additional_data.constant_modes[d][mode_index];
               }
index 7589c908d76561968a4655b178a8d3779036ee66..c70281cec2e6a008e36dcdd1c32b32fba9f113b0 100644 (file)
@@ -13,6 +13,7 @@
 //
 // ---------------------------------------------------------------------
 
+#include <deal.II/lac/trilinos_index_access.h>
 #include <deal.II/lac/trilinos_precondition.h>
 
 #ifdef DEAL_II_WITH_TRILINOS
@@ -20,6 +21,7 @@
 
 #  include <deal.II/lac/vector.h>
 #  include <deal.II/lac/sparse_matrix.h>
+#  include <deal.II/lac/trilinos_index_access.h>
 #  include <deal.II/lac/trilinos_sparse_matrix.h>
 
 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
@@ -38,43 +40,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace TrilinosWrappers
 {
-  namespace
-  {
-#ifndef DEAL_II_WITH_64BIT_INDICES
-    int n_global_rows (const Epetra_RowMatrix &matrix)
-    {
-      return matrix.NumGlobalRows();
-    }
-
-    int global_length (const Epetra_MultiVector &vector)
-    {
-      return vector.GlobalLength();
-    }
-
-    int gid(const Epetra_Map &map, unsigned int i)
-    {
-      return map.GID(i);
-    }
-#else
-    long long int n_global_rows (const Epetra_RowMatrix &matrix)
-    {
-      return matrix.NumGlobalRows64();
-    }
-
-    long long int global_length (const Epetra_MultiVector &vector)
-    {
-      return vector.GlobalLength64();
-    }
-
-    long long int gid(const Epetra_Map &map, dealii::types::global_dof_index i)
-    {
-      return map.GID64(i);
-    }
-#endif
-  }
-
-
-
   PreconditionAMGMueLu::AdditionalData::
   AdditionalData (const bool                             elliptic,
                   const unsigned int                     n_cycles,
@@ -181,7 +146,7 @@ namespace TrilinosWrappers
 
     if (constant_modes_dimension > 0)
       {
-        const size_type n_rows = n_global_rows(matrix);
+        const size_type n_rows = TrilinosWrappers::n_global_rows(matrix);
         const bool constant_modes_are_global =
           additional_data.constant_modes[0].size() == n_rows;
         const size_type n_relevant_rows =
@@ -191,9 +156,9 @@ namespace TrilinosWrappers
           Assert (n_relevant_rows == my_size,
                   ExcDimensionMismatch(n_relevant_rows, my_size));
         Assert (n_rows ==
-                static_cast<size_type>(global_length(distributed_constant_modes)),
+                static_cast<size_type>(TrilinosWrappers::global_length(distributed_constant_modes)),
                 ExcDimensionMismatch(n_rows,
-                                     global_length(distributed_constant_modes)));
+                                     TrilinosWrappers::global_length(distributed_constant_modes)));
 
         (void)n_relevant_rows;
         (void)global_length;
@@ -204,7 +169,7 @@ namespace TrilinosWrappers
           for (size_type row=0; row<my_size; ++row)
             {
               TrilinosWrappers::types::int_type global_row_id =
-                constant_modes_are_global ? gid(domain_map,row) : row;
+                constant_modes_are_global ? TrilinosWrappers::global_index(domain_map,row) : row;
               distributed_constant_modes[d][row] =
                 additional_data.constant_modes[d][global_row_id];
             }
index 69fe10bba68b41438ded400df565640b049e7d7a..bf1c800007b6a49733189674ba7a7b6747341a44 100644 (file)
@@ -13,6 +13,7 @@
 //
 // ---------------------------------------------------------------------
 
+#include <deal.II/lac/trilinos_index_access.h>
 #include <deal.II/lac/trilinos_sparse_matrix.h>
 
 #ifdef DEAL_II_WITH_TRILINOS
@@ -24,6 +25,7 @@
 #  include <deal.II/lac/dynamic_sparsity_pattern.h>
 #  include <deal.II/lac/sparsity_tools.h>
 #  include <deal.II/lac/la_parallel_vector.h>
+#  include <deal.II/lac/trilinos_index_access.h>
 #  include <deal.II/lac/trilinos_precondition.h>
 
 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
@@ -37,79 +39,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace TrilinosWrappers
 {
-  namespace
-  {
-#ifndef DEAL_II_WITH_64BIT_INDICES
-    // define a helper function that queries the size of an Epetra_Map object
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-    int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements();
-    }
-
-    int min_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MinMyGID();
-    }
-
-    int max_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MaxMyGID();
-    }
-
-    int n_global_cols(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalCols();
-    }
-
-    int global_column_index(const Epetra_CrsMatrix &matrix, int i)
-    {
-      return matrix.GCID(i);
-    }
-
-    int global_row_index(const Epetra_CrsMatrix &matrix, int i)
-    {
-      return matrix.GRID(i);
-    }
-#else
-    // define a helper function that queries the size of an Epetra_Map object
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-    long long int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements64();
-    }
-
-    long long int min_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MinMyGID64();
-    }
-
-    long long int max_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MaxMyGID64();
-    }
-
-    long long int n_global_cols(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalCols64();
-    }
-
-    long long int global_column_index(const Epetra_CrsMatrix &matrix, int i)
-    {
-      return matrix.GCID64(i);
-    }
-
-    long long int global_row_index(const Epetra_CrsMatrix &matrix, int i)
-    {
-      return matrix.GRID64(i);
-    }
-#endif
-  }
-
   namespace internal
   {
     template <typename VectorType>
@@ -526,9 +455,9 @@ namespace TrilinosWrappers
       if (input_row_map.Comm().MyPID() == 0)
         {
           AssertDimension (sparsity_pattern.n_rows(),
-                           static_cast<size_type>(n_global_elements(input_row_map)));
+                           static_cast<size_type>(TrilinosWrappers::n_global_elements(input_row_map)));
           AssertDimension (sparsity_pattern.n_cols(),
-                           static_cast<size_type>(n_global_elements(input_col_map)));
+                           static_cast<size_type>(TrilinosWrappers::n_global_elements(input_col_map)));
         }
 
       column_space_map.reset (new Epetra_Map (input_col_map));
@@ -548,8 +477,8 @@ namespace TrilinosWrappers
           return;
         }
 
-      const size_type first_row = min_my_gid(input_row_map),
-                      last_row = max_my_gid(input_row_map)+1;
+      const size_type first_row = TrilinosWrappers::min_my_gid(input_row_map),
+                      last_row = TrilinosWrappers::max_my_gid(input_row_map)+1;
       std::vector<int> n_entries_per_row(last_row-first_row);
 
       for (size_type row=first_row; row<last_row; ++row)
@@ -609,7 +538,7 @@ namespace TrilinosWrappers
 
       // check whether we got the number of columns right.
       AssertDimension (sparsity_pattern.n_cols(),
-                       static_cast<size_type>(n_global_cols(*graph)));
+                       static_cast<size_type>(TrilinosWrappers::n_global_cols(*graph)));
       (void)n_global_cols;
 
       // And now finally generate the matrix.
@@ -659,9 +588,9 @@ namespace TrilinosWrappers
       nonlocal_matrix_exporter.reset();
 
       AssertDimension (sparsity_pattern.n_rows(),
-                       static_cast<size_type>(n_global_elements(input_row_map)));
+                       static_cast<size_type>(TrilinosWrappers::n_global_elements(input_row_map)));
       AssertDimension (sparsity_pattern.n_cols(),
-                       static_cast<size_type>(n_global_elements(input_col_map)));
+                       static_cast<size_type>(TrilinosWrappers::n_global_elements(input_col_map)));
 
       column_space_map.reset (new Epetra_Map (input_col_map));
 
@@ -669,8 +598,8 @@ namespace TrilinosWrappers
       // serial case
       if (relevant_rows.size() == 0)
         {
-          relevant_rows.set_size(n_global_elements(input_row_map));
-          relevant_rows.add_range(0, n_global_elements(input_row_map));
+          relevant_rows.set_size(TrilinosWrappers::n_global_elements(input_row_map));
+          relevant_rows.add_range(0, TrilinosWrappers::n_global_elements(input_row_map));
         }
       relevant_rows.compress();
       Assert(relevant_rows.n_elements() >= static_cast<unsigned int>(input_row_map.NumMyElements()),
@@ -786,7 +715,7 @@ namespace TrilinosWrappers
       graph->OptimizeStorage();
 
       AssertDimension (sparsity_pattern.n_cols(),static_cast<size_type>(
-                         n_global_cols(*graph)));
+                         TrilinosWrappers::n_global_cols(*graph)));
 
       matrix.reset (new Epetra_FECrsMatrix(Copy, *graph, false));
     }
@@ -2244,45 +2173,38 @@ namespace TrilinosWrappers
                                                inputleft.range_partitioner());
           Assert (inputleft.domain_partitioner().LinearMap() == true,
                   ExcMessage("Matrix must be partitioned contiguously between procs."));
-          for (unsigned int i=0; i<inputleft.local_size(); ++i)
+          for (dealii::types::global_dof_index i=0; i<inputleft.local_size(); ++i)
             {
               int num_entries, * indices;
               inputleft.trilinos_sparsity_pattern().ExtractMyRowView(i, num_entries,
                                                                      indices);
               Assert (num_entries >= 0, ExcInternalError());
-#ifndef DEAL_II_WITH_64BIT_INDICES
-              const size_type GID = inputleft.trilinos_matrix().RowMap().GID(i);
-              for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
-                sparsity_transposed.add (inputleft.trilinos_matrix().ColMap().GID(indices[j]),
-                                         GID);
-#else
-              const size_type GID = inputleft.trilinos_matrix().RowMap().GID64(i);
+
+              const auto &trilinos_matrix = inputleft.trilinos_matrix();
+              const size_type GID = TrilinosWrappers::global_index(trilinos_matrix.RowMap(), i);
               for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
-                sparsity_transposed.add (inputleft.trilinos_matrix().ColMap().GID64(indices[j]),
-                                         GID);
-#endif
+                sparsity_transposed.add
+                (TrilinosWrappers::global_index(trilinos_matrix.ColMap(),
+                                                indices[j]),
+                 GID);
             }
 
           sparsity_transposed.compress();
           transposed_mat.reinit (sparsity_transposed);
-          for (unsigned int i=0; i<inputleft.local_size(); ++i)
+          for (dealii::types::global_dof_index i=0; i<inputleft.local_size(); ++i)
             {
               int num_entries, * indices;
               double *values;
               inputleft.trilinos_matrix().ExtractMyRowView(i, num_entries,
                                                            values, indices);
               Assert (num_entries >= 0, ExcInternalError());
-#ifndef DEAL_II_WITH_64BIT_INDICES
-              const size_type GID = inputleft.trilinos_matrix().RowMap().GID(i);
-              for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
-                transposed_mat.set (inputleft.trilinos_matrix().ColMap().GID(indices[j]),
-                                    GID, values[j]);
-#else
-              const size_type GID = inputleft.trilinos_matrix().RowMap().GID64(i);
+
+              const auto &trilinos_matrix = inputleft.trilinos_matrix();
+              const size_type GID = TrilinosWrappers::global_index(trilinos_matrix.RowMap(), i);
               for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
-                transposed_mat.set (inputleft.trilinos_matrix().ColMap().GID64(indices[j]),
+                transposed_mat.set (TrilinosWrappers::global_index(trilinos_matrix.ColMap(),
+                                                                   indices[j]),
                                     GID, values[j]);
-#endif
             }
           transposed_mat.compress(VectorOperation::insert);
           ML_Operator_WrapEpetraCrsMatrix
@@ -2426,8 +2348,8 @@ namespace TrilinosWrappers
           {
             matrix->ExtractMyRowView (i, num_entries, values, indices);
             for (TrilinosWrappers::types::int_type j=0; j<num_entries; ++j)
-              out << "(" << global_row_index(*matrix,i) << ","
-                  << global_column_index(*matrix,indices[j]) << ") "
+              out << "(" << TrilinosWrappers::global_row_index(*matrix,i) << ","
+                  << TrilinosWrappers::global_column_index(*matrix,indices[j]) << ") "
                   << values[j] << std::endl;
           }
       }
index d75f8aa7156f7f72f48c98dd64363bdbbdd2bd0f..fe3876889d5162381980731e2265849b109a60a1 100644 (file)
 //
 // ---------------------------------------------------------------------
 
+#include <deal.II/lac/trilinos_index_access.h>
 #include <deal.II/lac/trilinos_sparsity_pattern.h>
 
 #ifdef DEAL_II_WITH_TRILINOS
 
 #  include <deal.II/base/utilities.h>
 #  include <deal.II/base/mpi.h>
-#  include <deal.II/lac/sparsity_pattern.h>
+
 #  include <deal.II/lac/dynamic_sparsity_pattern.h>
+#  include <deal.II/lac/sparsity_pattern.h>
+#  include <deal.II/lac/trilinos_index_access.h>
 
 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
 #  include <Epetra_Export.h>
@@ -30,85 +33,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace TrilinosWrappers
 {
-  namespace
-  {
-    // define a helper function that queries the size of an Epetra_Map object
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-#ifndef DEAL_II_WITH_64BIT_INDICES
-    int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements();
-    }
-
-    int min_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MinMyGID();
-    }
-
-    int max_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MaxMyGID();
-    }
-
-    int n_global_rows(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalRows();
-    }
-
-    int n_global_cols(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalCols();
-    }
-
-    int n_global_entries(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalEntries();
-    }
-
-    int local_to_global_index(const Epetra_BlockMap &map, int i)
-    {
-      return map.GID(i);
-    }
-#else
-    long long int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements64();
-    }
-
-    long long int min_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MinMyGID64();
-    }
-
-    long long int max_my_gid(const Epetra_BlockMap &map)
-    {
-      return map.MaxMyGID64();
-    }
-
-    long long int n_global_rows(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalRows64();
-    }
-
-    long long int n_global_cols(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalCols64();
-    }
-
-    long long int n_global_entries(const Epetra_CrsGraph &graph)
-    {
-      return graph.NumGlobalEntries64();
-    }
-
-    long long int local_to_global_index(const Epetra_BlockMap &map, int i)
-    {
-      return map.GID64(i);
-    }
-#endif
-  }
-
   namespace SparsityPatternIterators
   {
     void
@@ -392,13 +316,13 @@ namespace TrilinosWrappers
       nonlocal_graph.reset();
       graph.reset ();
       AssertDimension (n_entries_per_row.size(),
-                       static_cast<size_type>(n_global_elements(row_map)));
+                       static_cast<size_type>(TrilinosWrappers::n_global_elements(row_map)));
 
       column_space_map.reset (new Epetra_Map (col_map));
-      std::vector<int> local_entries_per_row(max_my_gid(row_map)-
-                                             min_my_gid(row_map));
+      std::vector<int> local_entries_per_row(TrilinosWrappers::max_my_gid(row_map)-
+                                             TrilinosWrappers::min_my_gid(row_map));
       for (unsigned int i=0; i<local_entries_per_row.size(); ++i)
-        local_entries_per_row[i] = n_entries_per_row[min_my_gid(row_map)+i];
+        local_entries_per_row[i] = n_entries_per_row[TrilinosWrappers::min_my_gid(row_map)+i];
 
       if (row_map.Comm().NumProc() > 1)
         graph.reset(new Epetra_FECrsGraph(Copy, row_map,
@@ -434,17 +358,17 @@ namespace TrilinosWrappers
       graph.reset ();
 
       AssertDimension (sp.n_rows(),
-                       static_cast<size_type>(n_global_elements(row_map)));
+                       static_cast<size_type>(TrilinosWrappers::n_global_elements(row_map)));
       AssertDimension (sp.n_cols(),
-                       static_cast<size_type>(n_global_elements(col_map)));
+                       static_cast<size_type>(TrilinosWrappers::n_global_elements(col_map)));
 
       column_space_map.reset (new Epetra_Map (col_map));
 
       Assert (row_map.LinearMap() == true,
               ExcMessage ("This function only works if the row map is contiguous."));
 
-      const size_type first_row = min_my_gid(row_map),
-                      last_row = max_my_gid(row_map)+1;
+      const size_type first_row = TrilinosWrappers::min_my_gid(row_map),
+                      last_row = TrilinosWrappers::max_my_gid(row_map)+1;
       std::vector<int> n_entries_per_row(last_row - first_row);
 
       // Trilinos wants the row length as an int this is hopefully never going
@@ -932,7 +856,7 @@ namespace TrilinosWrappers
     if (graph->Filled() == true)
       n_cols = n_global_cols(*graph);
     else
-      n_cols = n_global_elements(*column_space_map);
+      n_cols = TrilinosWrappers::n_global_elements(*column_space_map);
 
     return n_cols;
   }
@@ -953,8 +877,8 @@ namespace TrilinosWrappers
   SparsityPattern::local_range () const
   {
     size_type begin, end;
-    begin =  min_my_gid(graph->RowMap());
-    end = max_my_gid(graph->RowMap())+1;
+    begin =  TrilinosWrappers::min_my_gid(graph->RowMap());
+    end = TrilinosWrappers::max_my_gid(graph->RowMap())+1;
 
     return std::make_pair (begin, end);
   }
@@ -1089,8 +1013,8 @@ namespace TrilinosWrappers
           {
             graph->ExtractMyRowView (i, num_entries, indices);
             for (int j=0; j<num_entries; ++j)
-              out << "(" << local_to_global_index(graph->RowMap(), i)
-                  << "," << local_to_global_index(graph->ColMap(), indices[j]) << ") "
+              out << "(" << TrilinosWrappers::global_index(graph->RowMap(), i)
+                  << "," << TrilinosWrappers::global_index(graph->ColMap(), indices[j]) << ") "
                   << std::endl;
           }
       }
@@ -1104,20 +1028,23 @@ namespace TrilinosWrappers
   SparsityPattern::print_gnuplot (std::ostream &out) const
   {
     Assert (graph->Filled() == true, ExcInternalError());
-    for (unsigned int row=0; row<local_size(); ++row)
+    for (dealii::types::global_dof_index row=0; row<local_size(); ++row)
       {
         int *indices;
         int num_entries;
         graph->ExtractMyRowView (row, num_entries, indices);
 
-        for (int j=0; j<num_entries; ++j)
+        Assert(num_entries >= 0, ExcInternalError());
+        // avoid sign comparison warning
+        const dealii::types::global_dof_index num_entries_ = num_entries;
+        for (dealii::types::global_dof_index j=0; j<num_entries_; ++j)
           // while matrix entries are usually
           // written (i,j), with i vertical and
           // j horizontal, gnuplot output is
           // x-y, that is we have to exchange
           // the order of output
-          out << static_cast<int>(local_to_global_index(graph->ColMap(), indices[j]))
-              << " " << -static_cast<int>(local_to_global_index(graph->RowMap(), row)) << std::endl;
+          out << static_cast<int>(TrilinosWrappers::global_index(graph->ColMap(), indices[j]))
+              << " " << -static_cast<int>(TrilinosWrappers::global_index(graph->RowMap(), row)) << std::endl;
       }
 
     AssertThrow (out, ExcIO());
index ac96692027deb8de5c6f8955c1fc33e6e48b9d1f..9f33b388ceae373142b3cfb2a0df562b2b71a484 100644 (file)
 //
 // ---------------------------------------------------------------------
 
+#include <deal.II/lac/trilinos_index_access.h>
 #include <deal.II/lac/trilinos_vector.h>
 
 #ifdef DEAL_II_WITH_TRILINOS
 
 #  include <deal.II/base/mpi.h>
-#  include <deal.II/lac/trilinos_sparse_matrix.h>
 #  include <deal.II/lac/trilinos_block_vector.h>
+#  include <deal.II/lac/trilinos_index_access.h>
+#  include <deal.II/lac/trilinos_sparse_matrix.h>
 
 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
 #  include <Epetra_Import.h>
@@ -33,65 +35,8 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace TrilinosWrappers
 {
-  namespace
-  {
-#ifndef DEAL_II_WITH_64BIT_INDICES
-    // define a helper function that queries the size of an Epetra_BlockMap object
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-    int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements();
-    }
-    // define a helper function that queries the pointer to internal array
-    // containing list of global IDs assigned to the calling processor
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-    int *my_global_elements(const Epetra_BlockMap &map)
-    {
-      return map.MyGlobalElements();
-    }
-    // define a helper function that queries the global vector length of an
-    // Epetra_FEVector object  by calling either the 32- or 64-bit
-    // function necessary.
-    int global_length(const Epetra_FEVector &vector)
-    {
-      return vector.GlobalLength();
-    }
-#else
-    // define a helper function that queries the size of an Epetra_BlockMap object
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-    long long int n_global_elements (const Epetra_BlockMap &map)
-    {
-      return map.NumGlobalElements64();
-    }
-    // define a helper function that queries the pointer to internal array
-    // containing list of global IDs assigned to the calling processor
-    // by calling either the 32- or 64-bit function necessary, and returns the
-    // result in the correct data type so that we can use it in calling other
-    // Epetra member functions that are overloaded by index type
-    long long int *my_global_elements(const Epetra_BlockMap &map)
-    {
-      return map.MyGlobalElements64();
-    }
-    // define a helper function that queries the global vector length of an
-    // Epetra_FEVector object  by calling either the 32- or 64-bit
-    // function necessary.
-    long long int global_length(const Epetra_FEVector &vector)
-    {
-      return vector.GlobalLength64();
-    }
-#endif
-  }
-
   namespace MPI
   {
-
-
     Vector::Vector ()
     {
       last_action = Zero;
@@ -139,9 +84,9 @@ namespace TrilinosWrappers
       VectorBase()
     {
       AssertThrow (parallel_partitioner.size() ==
-                   static_cast<size_type>(n_global_elements(v.vector->Map())),
+                   static_cast<size_type>(TrilinosWrappers::n_global_elements(v.vector->Map())),
                    ExcDimensionMismatch (parallel_partitioner.size(),
-                                         n_global_elements(v.vector->Map())));
+                                         TrilinosWrappers::n_global_elements(v.vector->Map())));
 
       last_action = Zero;
 
@@ -307,7 +252,7 @@ namespace TrilinosWrappers
       for (size_type block=0; block<v.n_blocks(); ++block)
         {
           TrilinosWrappers::types::int_type *glob_elements =
-            my_global_elements(v.block(block).vector_partitioner());
+            TrilinosWrappers::my_global_elements(v.block(block).vector_partitioner());
           for (size_type i=0; i<v.block(block).local_size(); ++i)
             global_ids[added_elements++] = glob_elements[i] + block_offset;
           owned_elements.add_indices(v.block(block).owned_elements,
@@ -338,9 +283,9 @@ namespace TrilinosWrappers
 
       if (import_data == true)
         {
-          AssertThrow (static_cast<size_type>(global_length(*actual_vec))
+          AssertThrow (static_cast<size_type>(TrilinosWrappers::global_length(*actual_vec))
                        == v.size(),
-                       ExcDimensionMismatch (global_length(*actual_vec),
+                       ExcDimensionMismatch (TrilinosWrappers::global_length(*actual_vec),
                                              v.size()));
 
           Epetra_Import data_exchange (vector->Map(), actual_vec->Map());
@@ -565,11 +510,11 @@ namespace TrilinosWrappers
   Vector::reinit (const Epetra_Map &input_map,
                   const bool     /*omit_zeroing_entries*/)
   {
-    Epetra_LocalMap map (n_global_elements(input_map),
+    Epetra_LocalMap map (TrilinosWrappers::n_global_elements(input_map),
                          input_map.IndexBase(),
                          input_map.Comm());
     vector.reset (new Epetra_FEVector(map));
-    owned_elements = complete_index_set(n_global_elements(input_map));
+    owned_elements = complete_index_set(TrilinosWrappers::n_global_elements(input_map));
 
     last_action = Zero;
   }
@@ -622,7 +567,7 @@ namespace TrilinosWrappers
 #endif
         if (!same_communicators || local_range() != v.local_range())
           {
-            Epetra_LocalMap map (global_length(*(v.vector)),
+            Epetra_LocalMap map (TrilinosWrappers::global_length(*(v.vector)),
                                  v.vector->Map().IndexBase(),
                                  v.vector->Comm());
             vector.reset (new Epetra_FEVector(map));
@@ -679,7 +624,7 @@ namespace TrilinosWrappers
   {
     if (size() != v.size())
       {
-        Epetra_LocalMap map (n_global_elements(v.vector->Map()),
+        Epetra_LocalMap map (TrilinosWrappers::n_global_elements(v.vector->Map()),
                              v.vector->Map().IndexBase(),
                              v.vector->Comm());
         vector.reset (new Epetra_FEVector(map));
@@ -696,7 +641,7 @@ namespace TrilinosWrappers
   {
     if (size() != v.size())
       {
-        Epetra_LocalMap map (n_global_elements(v.vector->Map()),
+        Epetra_LocalMap map (TrilinosWrappers::n_global_elements(v.vector->Map()),
                              v.vector->Map().IndexBase(),
                              v.vector->Comm());
         vector.reset (new Epetra_FEVector(map));

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.