1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_trilinos_index_access_h
17 #define dealii_trilinos_index_access_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_TRILINOS
22 
23 #  include <deal.II/base/types.h>
24 
25 #  include <Epetra_BlockMap.h>
26 #  include <Epetra_CrsGraph.h>
27 #  include <Epetra_CrsMatrix.h>
28 #  include <Epetra_MultiVector.h>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
32 namespace TrilinosWrappers
33 {
34   /**
35    * A helper function that queries the size of an Epetra_BlockMap object
36    * and calls either the 32 or 64 bit function to get the number of global
37    * elements in the map.
38    */
39   inline TrilinosWrappers::types::int_type
n_global_elements(const Epetra_BlockMap & map)40   n_global_elements(const Epetra_BlockMap &map)
41   {
42 #  ifdef DEAL_II_WITH_64BIT_INDICES
43     return map.NumGlobalElements64();
44 #  else
45     return map.NumGlobalElements();
46 #  endif
47   }
48 
49   /**
50    * A helper function that finds the minimum global index value on the
51    * calling processor by calling either the 32 or 64 bit function.
52    */
53   inline TrilinosWrappers::types::int_type
min_my_gid(const Epetra_BlockMap & map)54   min_my_gid(const Epetra_BlockMap &map)
55   {
56 #  ifdef DEAL_II_WITH_64BIT_INDICES
57     return map.MinMyGID64();
58 #  else
59     return map.MinMyGID();
60 #  endif
61   }
62 
63   /**
64    * A helper function that finds the maximum global index value on the
65    * calling processor by calling either the 32 or 64 bit function.
66    */
67   inline TrilinosWrappers::types::int_type
max_my_gid(const Epetra_BlockMap & map)68   max_my_gid(const Epetra_BlockMap &map)
69   {
70 #  ifdef DEAL_II_WITH_64BIT_INDICES
71     return map.MaxMyGID64();
72 #  else
73     return map.MaxMyGID();
74 #  endif
75   }
76 
77   /**
78    * A helper function that converts a local index to a global one calling
79    * either the 32 or 64 bit function.
80    */
81   inline TrilinosWrappers::types::int_type
global_index(const Epetra_BlockMap & map,const dealii::types::global_dof_index i)82   global_index(const Epetra_BlockMap &               map,
83                const dealii::types::global_dof_index i)
84   {
85 #  ifdef DEAL_II_WITH_64BIT_INDICES
86     return map.GID64(i);
87 #  else
88     return map.GID(i);
89 #  endif
90   }
91 
92   /**
93    * A helper function that returns a pointer to the array containing the
94    * global indices assigned to the current process by calling either the 32
95    * or 64 bit function.
96    */
97   inline TrilinosWrappers::types::int_type *
my_global_elements(const Epetra_BlockMap & map)98   my_global_elements(const Epetra_BlockMap &map)
99   {
100 #  ifdef DEAL_II_WITH_64BIT_INDICES
101     return map.MyGlobalElements64();
102 #  else
103     return map.MyGlobalElements();
104 #  endif
105   }
106 
107   /**
108    * A helper function that finds the global number of rows by calling
109    * either the 32 or 64 bit function.
110    */
111   inline TrilinosWrappers::types::int_type
n_global_rows(const Epetra_CrsGraph & graph)112   n_global_rows(const Epetra_CrsGraph &graph)
113   {
114 #  ifdef DEAL_II_WITH_64BIT_INDICES
115     return graph.NumGlobalRows64();
116 #  else
117     return graph.NumGlobalRows();
118 #  endif
119   }
120 
121   /**
122    * A helper function that finds the global number of columns by calling
123    * either the 32 or 64 bit function.
124    */
125   inline TrilinosWrappers::types::int_type
n_global_cols(const Epetra_CrsGraph & graph)126   n_global_cols(const Epetra_CrsGraph &graph)
127   {
128 #  ifdef DEAL_II_WITH_64BIT_INDICES
129     return graph.NumGlobalCols64();
130 #  else
131     return graph.NumGlobalCols();
132 #  endif
133   }
134 
135   /**
136    * A helper function that finds the number of global entries by calling
137    * either the 32 or 64 bit function.
138    */
139   inline TrilinosWrappers::types::int_type
n_global_entries(const Epetra_CrsGraph & graph)140   n_global_entries(const Epetra_CrsGraph &graph)
141   {
142 #  ifdef DEAL_II_WITH_64BIT_INDICES
143     return graph.NumGlobalEntries64();
144 #  else
145     return graph.NumGlobalEntries();
146 #  endif
147   }
148 
149   /**
150    * A helper function that finds the global row index by calling
151    * either the 32 or 64 bit function.
152    */
153   inline TrilinosWrappers::types::int_type
global_row_index(const Epetra_CrsMatrix & matrix,const dealii::types::global_dof_index i)154   global_row_index(const Epetra_CrsMatrix &              matrix,
155                    const dealii::types::global_dof_index i)
156   {
157 #  ifdef DEAL_II_WITH_64BIT_INDICES
158     return matrix.GRID64(i);
159 #  else
160     return matrix.GRID(i);
161 #  endif
162   }
163 
164   /**
165    * A helper function that finds the global column index by calling
166    * either the 32 or 64 bit function.
167    */
168   inline TrilinosWrappers::types::int_type
global_column_index(const Epetra_CrsMatrix & matrix,const dealii::types::global_dof_index i)169   global_column_index(const Epetra_CrsMatrix &              matrix,
170                       const dealii::types::global_dof_index i)
171   {
172 #  ifdef DEAL_II_WITH_64BIT_INDICES
173     return matrix.GCID64(i);
174 #  else
175     return matrix.GCID(i);
176 #  endif
177   }
178 
179   /**
180    * A helper function that finds the global length of a vector by calling
181    * either the 32 or 64 bit function.
182    */
183   inline TrilinosWrappers::types::int_type
global_length(const Epetra_MultiVector & vector)184   global_length(const Epetra_MultiVector &vector)
185   {
186 #  ifdef DEAL_II_WITH_64BIT_INDICES
187     return vector.GlobalLength64();
188 #  else
189     return vector.GlobalLength();
190 #  endif
191   }
192 
193   /**
194    * A helper function that finds the global number of rows by calling
195    * either the 32 or 64 bit function.
196    */
197   inline TrilinosWrappers::types::int_type
n_global_rows(const Epetra_RowMatrix & matrix)198   n_global_rows(const Epetra_RowMatrix &matrix)
199   {
200 #  ifdef DEAL_II_WITH_64BIT_INDICES
201     return matrix.NumGlobalRows64();
202 #  else
203     return matrix.NumGlobalRows();
204 #  endif
205   }
206 } // namespace TrilinosWrappers
207 
208 DEAL_II_NAMESPACE_CLOSE
209 #endif // DEAL_II_WITH_TRILINOS
210 #endif // dealii_trilinos_index_access_h
211