Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_InputTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #ifndef ZOLTAN2_INPUTTRAITS_HPP
15 #define ZOLTAN2_INPUTTRAITS_HPP
16 
17 #include <Zoltan2_Standards.hpp>
18 
19 #include <Tpetra_CrsMatrix.hpp>
20 #include <Tpetra_RowMatrix.hpp>
21 #include <Tpetra_CrsGraph.hpp>
22 #include <Tpetra_RowGraph.hpp>
23 
24 #ifdef HAVE_ZOLTAN2_EPETRA
25 #include <Epetra_CrsMatrix.h>
26 #include <Epetra_CrsGraph.h>
27 #endif
28 
29 #include <Xpetra_CrsMatrix.hpp>
30 #include <Xpetra_RowMatrix.hpp>
31 #include <Xpetra_TpetraRowMatrix.hpp>
32 #include <Xpetra_CrsGraph.hpp>
33 
34 namespace Zoltan2{
35 
36 // Default local ordinal
37 typedef ::Tpetra::Details::DefaultTypes::local_ordinal_type default_lno_t;
38 
39 // Default global ordinal
40 typedef ::Tpetra::Details::DefaultTypes::global_ordinal_type default_gno_t;
41 
42 // Default offset type
43 typedef size_t default_offset_t;
44 
45 // Default scalar type (for weights, coordinates)
46 typedef ::Tpetra::Details::DefaultTypes::scalar_type default_scalar_t;
47 
48 // Until Kokkos node types are supported, use default
49 typedef ::Tpetra::Details::DefaultTypes::node_type default_node_t;
50 
51 // Default part number type.
52 typedef int default_part_t; // Restrictions in MPI interface will make it
53  // somewhat difficult to change default_part_t to
54  // long long, since we use part_t for ranks
55  // and we sometimes broadcast arrays whose
56  // size has type part_t.
57  // part_t must be a signed data type.
58 
100 template <typename scalar=default_scalar_t,
101  typename lno=default_lno_t,
102  typename gno=default_gno_t,
103  typename node=default_node_t>
105 };
106 
141 template <typename User>
142 struct InputTraits {
143 
147 
152 
157 
161 
165 
170 
173  static inline std::string name() {return "InputAdapter";}
174 };
175 
176 #ifndef DOXYGEN_SHOULD_SKIP_THIS
177 
178 #ifdef _MSC_VER
179  typedef SSIZE_T ssize_t;
180 #endif
181 
182 // This combination of macros is used to define a single line
183 // Z2_STATIC_ASSERT_TYPES for each InputTraits with custom template types
184 #define Z2_ISSAME(s,type) (std::is_same< s, type >::value)
185 
186 #define Z2_STYPES(s) ( Z2_ISSAME(s,float) || \
187  Z2_ISSAME(s,double) || Z2_ISSAME(s,int) || Z2_ISSAME(s,long) || \
188  Z2_ISSAME(s,long long) || Z2_ISSAME(s, int64_t) || Z2_ISSAME(s, int32_t))
189 
190 #define Z2_LTYPES(l) ( Z2_ISSAME(l,int) || \
191  Z2_ISSAME(l,long) || Z2_ISSAME(l,long long) || Z2_ISSAME(l,ssize_t) )
192 
193 #define Z2_GTYPES(g) ( Z2_ISSAME(g,int) || Z2_ISSAME(g,long) || \
194  Z2_ISSAME(g,long long) || Z2_ISSAME(g,ssize_t) || \
195  Z2_ISSAME(g,unsigned int) || Z2_ISSAME(g,unsigned long) || \
196  Z2_ISSAME(g,unsigned long long) || Z2_ISSAME(g,size_t) )
197 
198 #define Z2_SERROR "Invalid scalar type. It must be float, double, int, long, long long, int32_t, or int64_t."
199 
200 #define Z2_LERROR "Invalid local ordinal type. It must be int, long, " \
201  "long long, or ssize_t."
202 
203 #define Z2_GERROR "Invalid global ordinal type. It must be int, long, " \
204  "long long, ssize_t, unsigned int, unsigned long long, size_t."
205 
206 #ifdef Z2_INVERT_STATIC_ASSERT_FOR_UNIT_TESTING
207  #define Z2_STATIC_ASSERT_TYPES static_assert( ( !Z2_STYPES(scalar_t) || \
208  !Z2_LTYPES(lno_t) || !Z2_GTYPES(gno_t) ), \
209  "Inverted unit test for InputTraits was supposed to fail but did not." );
210 #else
211  #define Z2_STATIC_ASSERT_TYPES static_assert( Z2_STYPES(scalar_t), \
212  Z2_SERROR ); static_assert( Z2_LTYPES(lno_t), Z2_LERROR ); \
213  static_assert( Z2_GTYPES(gno_t), Z2_GERROR );
214 #endif
215 
216 template <typename Scalar,
217  typename LocalOrdinal,
218  typename GlobalOrdinal,
219  typename Node>
220 struct InputTraits<BasicUserTypes<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
221 {
222  typedef Scalar scalar_t;
223  typedef LocalOrdinal lno_t;
224  typedef GlobalOrdinal gno_t;
225  typedef LocalOrdinal offset_t;
227  typedef Node node_t;
228  static inline std::string name() {return "BasicUserTypes";}
229 
230  Z2_STATIC_ASSERT_TYPES // validate the types
231 };
232 
233 template <typename Scalar,
234  typename LocalOrdinal,
235  typename GlobalOrdinal,
236  typename Node>
237 struct InputTraits<Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
238 {
239  typedef Scalar scalar_t;
240  typedef LocalOrdinal lno_t;
241  typedef GlobalOrdinal gno_t;
242  typedef size_t offset_t;
244  typedef Node node_t;
245  static inline std::string name() {return "Xpetra::CrsMatrix";}
246 
247  Z2_STATIC_ASSERT_TYPES // validate the types
248 };
249 
250 template <typename Scalar,
251  typename LocalOrdinal,
252  typename GlobalOrdinal,
253  typename Node>
254 struct InputTraits<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
255 {
256  typedef Scalar scalar_t;
257  typedef LocalOrdinal lno_t;
258  typedef GlobalOrdinal gno_t;
259  typedef size_t offset_t;
261  typedef Node node_t;
262  static inline std::string name() {return "Tpetra::CrsMatrix";}
263 
264  Z2_STATIC_ASSERT_TYPES // validate the types
265 };
266 
267 #ifdef HAVE_ZOLTAN2_EPETRA
268 template < >
269 struct InputTraits<Epetra_CrsMatrix>
270 {
271  typedef double scalar_t;
272  typedef int lno_t;
273  typedef int gno_t;
274  typedef size_t offset_t;
277  static inline std::string name() {return "Epetra_CrsMatrix";}
278 };
279 #endif
280 
281 template <typename Scalar,
282  typename LocalOrdinal,
283  typename GlobalOrdinal,
284  typename Node>
285 struct InputTraits<Xpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
286 {
287  typedef Scalar scalar_t;
288  typedef LocalOrdinal lno_t;
289  typedef GlobalOrdinal gno_t;
290  typedef size_t offset_t;
292  typedef Node node_t;
293  static inline std::string name() {return "Xpetra::RowMatrix";}
294 
295  Z2_STATIC_ASSERT_TYPES // validate the types
296 };
297 
298 template <typename Scalar,
299  typename LocalOrdinal,
300  typename GlobalOrdinal,
301  typename Node>
302 struct InputTraits<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
303 {
304  typedef Scalar scalar_t;
305  typedef LocalOrdinal lno_t;
306  typedef GlobalOrdinal gno_t;
307  typedef size_t offset_t;
309  typedef Node node_t;
310  static inline std::string name() {return "Tpetra::RowMatrix";}
311 
312  Z2_STATIC_ASSERT_TYPES // validate the types
313 };
314 
315 template <typename LocalOrdinal,
316  typename GlobalOrdinal,
317  typename Node>
318 struct InputTraits<Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> >
319 {
320  typedef default_scalar_t scalar_t;
321  typedef LocalOrdinal lno_t;
322  typedef GlobalOrdinal gno_t;
323  typedef size_t offset_t;
325  typedef Node node_t;
326  static inline std::string name() {return "Tpetra::RowGraph";}
327 };
328 
329 template <typename LocalOrdinal,
330  typename GlobalOrdinal,
331  typename Node>
332 struct InputTraits<Xpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
333 {
334  typedef default_scalar_t scalar_t;
335  typedef LocalOrdinal lno_t;
336  typedef GlobalOrdinal gno_t;
337  typedef size_t offset_t;
339  typedef Node node_t;
340  static inline std::string name() {return "Xpetra::CrsGraph";}
341 
342  Z2_STATIC_ASSERT_TYPES // validate the types
343 };
344 
345 template <typename LocalOrdinal,
346  typename GlobalOrdinal,
347  typename Node>
348 struct InputTraits<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
349 {
350  typedef default_scalar_t scalar_t;
351  typedef LocalOrdinal lno_t;
352  typedef GlobalOrdinal gno_t;
353  typedef size_t offset_t;
355  typedef Node node_t;
356  static inline std::string name() {return "Tpetra::CrsGraph";}
357 
358  Z2_STATIC_ASSERT_TYPES // validate the types
359 };
360 
361 #ifdef HAVE_ZOLTAN2_EPETRA
362 template < >
363 struct InputTraits<Epetra_CrsGraph>
364 {
365  typedef double scalar_t;
366  typedef int lno_t;
367  typedef int gno_t;
368  typedef size_t offset_t;
371  static inline std::string name() {return "Epetra_CrsGraph";}
372 };
373 #endif
374 
375 template <typename Scalar,
376  typename LocalOrdinal,
377  typename GlobalOrdinal,
378  typename Node>
379 struct InputTraits<Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
380 {
381  typedef Scalar scalar_t;
382  typedef LocalOrdinal lno_t;
383  typedef GlobalOrdinal gno_t;
384  typedef size_t offset_t;
386  typedef Node node_t;
387  static inline std::string name() {return "Xpetra::Vector";}
388 
389  Z2_STATIC_ASSERT_TYPES // validate the types
390 };
391 
395 template <typename Scalar,
396  typename LocalOrdinal,
397  typename GlobalOrdinal,
398  typename Node>
399 struct InputTraits<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
400 {
401  typedef Scalar scalar_t;
402  typedef LocalOrdinal lno_t;
403  typedef GlobalOrdinal gno_t;
404  typedef size_t offset_t;
406  typedef Node node_t;
407  static inline std::string name() {return "Tpetra::Vector";}
408 
409  Z2_STATIC_ASSERT_TYPES // validate the types
410 };
411 
412 #ifdef HAVE_ZOLTAN2_EPETRA
413 template < >
414 struct InputTraits<Epetra_Vector>
415 {
416  typedef double scalar_t;
417  typedef int lno_t;
418  typedef int gno_t;
419  typedef size_t offset_t;
422  static inline std::string name() {return "Epetra_Vector";}
423 };
424 #endif
425 
426 template <typename Scalar,
427  typename LocalOrdinal,
428  typename GlobalOrdinal,
429  typename Node>
430 struct InputTraits<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
431 {
432  typedef Scalar scalar_t;
433  typedef LocalOrdinal lno_t;
434  typedef GlobalOrdinal gno_t;
435  typedef size_t offset_t;
437  typedef Node node_t;
438  static inline std::string name() {return "Xpetra::MultiVector";}
439 
440  Z2_STATIC_ASSERT_TYPES // validate the types
441 };
442 
443 template <typename Scalar,
444  typename LocalOrdinal,
445  typename GlobalOrdinal,
446  typename Node>
447 struct InputTraits<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
448 {
449  typedef Scalar scalar_t;
450  typedef LocalOrdinal lno_t;
451  typedef GlobalOrdinal gno_t;
452  typedef size_t offset_t;
454  typedef Node node_t;
455  static inline std::string name() {return "Tpetra::MultiVector";}
456 
457  Z2_STATIC_ASSERT_TYPES // validate the types
458 };
459 
460 #ifdef HAVE_ZOLTAN2_EPETRA
461 template < >
462 struct InputTraits<Epetra_MultiVector>
463 {
464  typedef double scalar_t;
465  typedef int lno_t;
466  typedef int gno_t;
467  typedef size_t offset_t;
470  static inline std::string name() {return "Epetra_MultiVector";}
471 };
472 #endif
473 
474 #endif // DOXYGEN_SHOULD_SKIP_THIS
475 
476 
477 } // namespace Zoltan2
478 #endif // ZOLTAN2_INPUTTRAITS_HPP
default_part_t part_t
The data type to represent part numbers.
default_offset_t offset_t
The data type to represent offsets.
A simple class that can be the User template argument for an InputAdapter.
::Tpetra::Details::DefaultTypes::global_ordinal_type default_gno_t
::Tpetra::Details::DefaultTypes::local_ordinal_type default_lno_t
Tpetra::Vector< z2TestScalar, z2TestLO, z2TestGO > Vector
Definition: coloring1.cpp:45
::Tpetra::Details::DefaultTypes::scalar_type default_scalar_t
size_t default_offset_t
The traits required of User input classes or structures.
static std::string name()
The name of the user&#39;s input object.
default_lno_t lno_t
The ordinal type (e.g., int, long, int64_t) that represents local counts and local indices...
default_gno_t gno_t
The ordinal type (e.g., int, long, int64_t) that can represent global counts and identifiers.
default_node_t node_t
The Kokkos node type. This is only meaningful for users of Tpetra objects.
Gathering definitions used in software development.
::Tpetra::Details::DefaultTypes::node_type default_node_t
Vector::node_type Node
Definition: coloring1.cpp:46
default_scalar_t scalar_t
The data type for weights and coordinates.