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 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
50 #ifndef ZOLTAN2_INPUTTRAITS_HPP
51 #define ZOLTAN2_INPUTTRAITS_HPP
52 
53 #include <Zoltan2_Standards.hpp>
54 
55 #include <Tpetra_CrsMatrix.hpp>
56 #include <Tpetra_RowMatrix.hpp>
57 #include <Tpetra_CrsGraph.hpp>
58 #include <Tpetra_RowGraph.hpp>
59 
60 #ifdef HAVE_ZOLTAN2_EPETRA
61 #include <Epetra_CrsMatrix.h>
62 #include <Epetra_CrsGraph.h>
63 #endif
64 
65 #include <Xpetra_CrsMatrix.hpp>
66 #include <Xpetra_RowMatrix.hpp>
67 #include <Xpetra_TpetraRowMatrix.hpp>
68 #include <Xpetra_CrsGraph.hpp>
69 
70 namespace Zoltan2{
71 
72 // Default local ordinal
73 typedef ::Tpetra::Details::DefaultTypes::local_ordinal_type default_lno_t;
74 
75 // Default global ordinal
76 typedef ::Tpetra::Details::DefaultTypes::global_ordinal_type default_gno_t;
77 
78 // Default offset type
79 typedef size_t default_offset_t;
80 
81 // Default scalar type (for weights, coordinates)
82 typedef ::Tpetra::Details::DefaultTypes::scalar_type default_scalar_t;
83 
84 // Until Kokkos node types are supported, use default
85 typedef ::Tpetra::Details::DefaultTypes::node_type default_node_t;
86 
87 // Default part number type.
88 typedef int default_part_t; // Restrictions in MPI interface will make it
89  // somewhat difficult to change default_part_t to
90  // long long, since we use part_t for ranks
91  // and we sometimes broadcast arrays whose
92  // size has type part_t.
93  // part_t must be a signed data type.
94 
136 template <typename scalar=default_scalar_t,
137  typename lno=default_lno_t,
138  typename gno=default_gno_t,
139  typename node=default_node_t>
141 };
142 
177 template <typename User>
178 struct InputTraits {
179 
183 
188 
193 
197 
201 
206 
209  static inline std::string name() {return "InputAdapter";}
210 };
211 
212 #ifndef DOXYGEN_SHOULD_SKIP_THIS
213 
214 #ifdef _MSC_VER
215  typedef SSIZE_T ssize_t;
216 #endif
217 
218 // This combination of macros is used to define a single line
219 // Z2_STATIC_ASSERT_TYPES for each InputTraits with custom template types
220 #define Z2_ISSAME(s,type) (std::is_same< s, type >::value)
221 
222 #define Z2_STYPES(s) ( Z2_ISSAME(s,float) || \
223  Z2_ISSAME(s,double) || Z2_ISSAME(s,int) || Z2_ISSAME(s,long) || \
224  Z2_ISSAME(s,long long) || Z2_ISSAME(s, int64_t) || Z2_ISSAME(s, int32_t))
225 
226 #define Z2_LTYPES(l) ( Z2_ISSAME(l,int) || \
227  Z2_ISSAME(l,long) || Z2_ISSAME(l,long long) || Z2_ISSAME(l,ssize_t) )
228 
229 #define Z2_GTYPES(g) ( Z2_ISSAME(g,int) || Z2_ISSAME(g,long) || \
230  Z2_ISSAME(g,long long) || Z2_ISSAME(g,ssize_t) || \
231  Z2_ISSAME(g,unsigned int) || Z2_ISSAME(g,unsigned long) || \
232  Z2_ISSAME(g,unsigned long long) || Z2_ISSAME(g,size_t) )
233 
234 #define Z2_SERROR "Invalid scalar type. It must be float, double, int, long, long long, int32_t, or int64_t."
235 
236 #define Z2_LERROR "Invalid local ordinal type. It must be int, long, " \
237  "long long, or ssize_t."
238 
239 #define Z2_GERROR "Invalid global ordinal type. It must be int, long, " \
240  "long long, ssize_t, unsigned int, unsigned long long, size_t."
241 
242 #ifdef Z2_INVERT_STATIC_ASSERT_FOR_UNIT_TESTING
243  #define Z2_STATIC_ASSERT_TYPES static_assert( ( !Z2_STYPES(scalar_t) || \
244  !Z2_LTYPES(lno_t) || !Z2_GTYPES(gno_t) ), \
245  "Inverted unit test for InputTraits was supposed to fail but did not." );
246 #else
247  #define Z2_STATIC_ASSERT_TYPES static_assert( Z2_STYPES(scalar_t), \
248  Z2_SERROR ); static_assert( Z2_LTYPES(lno_t), Z2_LERROR ); \
249  static_assert( Z2_GTYPES(gno_t), Z2_GERROR );
250 #endif
251 
252 template <typename Scalar,
253  typename LocalOrdinal,
254  typename GlobalOrdinal,
255  typename Node>
256 struct InputTraits<BasicUserTypes<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
257 {
258  typedef Scalar scalar_t;
259  typedef LocalOrdinal lno_t;
260  typedef GlobalOrdinal gno_t;
261  typedef LocalOrdinal offset_t;
263  typedef Node node_t;
264  static inline std::string name() {return "BasicUserTypes";}
265 
266  Z2_STATIC_ASSERT_TYPES // validate the types
267 };
268 
269 template <typename Scalar,
270  typename LocalOrdinal,
271  typename GlobalOrdinal,
272  typename Node>
273 struct InputTraits<Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
274 {
275  typedef Scalar scalar_t;
276  typedef LocalOrdinal lno_t;
277  typedef GlobalOrdinal gno_t;
278  typedef size_t offset_t;
280  typedef Node node_t;
281  static inline std::string name() {return "Xpetra::CrsMatrix";}
282 
283  Z2_STATIC_ASSERT_TYPES // validate the types
284 };
285 
286 template <typename Scalar,
287  typename LocalOrdinal,
288  typename GlobalOrdinal,
289  typename Node>
290 struct InputTraits<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
291 {
292  typedef Scalar scalar_t;
293  typedef LocalOrdinal lno_t;
294  typedef GlobalOrdinal gno_t;
295  typedef size_t offset_t;
297  typedef Node node_t;
298  static inline std::string name() {return "Tpetra::CrsMatrix";}
299 
300  Z2_STATIC_ASSERT_TYPES // validate the types
301 };
302 
303 #ifdef HAVE_ZOLTAN2_EPETRA
304 template < >
305 struct InputTraits<Epetra_CrsMatrix>
306 {
307  typedef double scalar_t;
308  typedef int lno_t;
309  typedef int gno_t;
310  typedef size_t offset_t;
313  static inline std::string name() {return "Epetra_CrsMatrix";}
314 };
315 #endif
316 
317 template <typename Scalar,
318  typename LocalOrdinal,
319  typename GlobalOrdinal,
320  typename Node>
321 struct InputTraits<Xpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
322 {
323  typedef Scalar scalar_t;
324  typedef LocalOrdinal lno_t;
325  typedef GlobalOrdinal gno_t;
326  typedef size_t offset_t;
328  typedef Node node_t;
329  static inline std::string name() {return "Xpetra::RowMatrix";}
330 
331  Z2_STATIC_ASSERT_TYPES // validate the types
332 };
333 
334 template <typename Scalar,
335  typename LocalOrdinal,
336  typename GlobalOrdinal,
337  typename Node>
338 struct InputTraits<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
339 {
340  typedef Scalar scalar_t;
341  typedef LocalOrdinal lno_t;
342  typedef GlobalOrdinal gno_t;
343  typedef size_t offset_t;
345  typedef Node node_t;
346  static inline std::string name() {return "Tpetra::RowMatrix";}
347 
348  Z2_STATIC_ASSERT_TYPES // validate the types
349 };
350 
351 template <typename LocalOrdinal,
352  typename GlobalOrdinal,
353  typename Node>
354 struct InputTraits<Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> >
355 {
356  typedef default_scalar_t scalar_t;
357  typedef LocalOrdinal lno_t;
358  typedef GlobalOrdinal gno_t;
359  typedef size_t offset_t;
361  typedef Node node_t;
362  static inline std::string name() {return "Tpetra::RowGraph";}
363 };
364 
365 template <typename LocalOrdinal,
366  typename GlobalOrdinal,
367  typename Node>
368 struct InputTraits<Xpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
369 {
370  typedef default_scalar_t scalar_t;
371  typedef LocalOrdinal lno_t;
372  typedef GlobalOrdinal gno_t;
373  typedef size_t offset_t;
375  typedef Node node_t;
376  static inline std::string name() {return "Xpetra::CrsGraph";}
377 
378  Z2_STATIC_ASSERT_TYPES // validate the types
379 };
380 
381 template <typename LocalOrdinal,
382  typename GlobalOrdinal,
383  typename Node>
384 struct InputTraits<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
385 {
386  typedef default_scalar_t scalar_t;
387  typedef LocalOrdinal lno_t;
388  typedef GlobalOrdinal gno_t;
389  typedef size_t offset_t;
391  typedef Node node_t;
392  static inline std::string name() {return "Tpetra::CrsGraph";}
393 
394  Z2_STATIC_ASSERT_TYPES // validate the types
395 };
396 
397 #ifdef HAVE_ZOLTAN2_EPETRA
398 template < >
399 struct InputTraits<Epetra_CrsGraph>
400 {
401  typedef double scalar_t;
402  typedef int lno_t;
403  typedef int gno_t;
404  typedef size_t offset_t;
407  static inline std::string name() {return "Epetra_CrsGraph";}
408 };
409 #endif
410 
411 template <typename Scalar,
412  typename LocalOrdinal,
413  typename GlobalOrdinal,
414  typename Node>
415 struct InputTraits<Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
416 {
417  typedef Scalar scalar_t;
418  typedef LocalOrdinal lno_t;
419  typedef GlobalOrdinal gno_t;
420  typedef size_t offset_t;
422  typedef Node node_t;
423  static inline std::string name() {return "Xpetra::Vector";}
424 
425  Z2_STATIC_ASSERT_TYPES // validate the types
426 };
427 
431 template <typename Scalar,
432  typename LocalOrdinal,
433  typename GlobalOrdinal,
434  typename Node>
435 struct InputTraits<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
436 {
437  typedef Scalar scalar_t;
438  typedef LocalOrdinal lno_t;
439  typedef GlobalOrdinal gno_t;
440  typedef size_t offset_t;
442  typedef Node node_t;
443  static inline std::string name() {return "Tpetra::Vector";}
444 
445  Z2_STATIC_ASSERT_TYPES // validate the types
446 };
447 
448 #ifdef HAVE_ZOLTAN2_EPETRA
449 template < >
450 struct InputTraits<Epetra_Vector>
451 {
452  typedef double scalar_t;
453  typedef int lno_t;
454  typedef int gno_t;
455  typedef size_t offset_t;
458  static inline std::string name() {return "Epetra_Vector";}
459 };
460 #endif
461 
462 template <typename Scalar,
463  typename LocalOrdinal,
464  typename GlobalOrdinal,
465  typename Node>
466 struct InputTraits<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
467 {
468  typedef Scalar scalar_t;
469  typedef LocalOrdinal lno_t;
470  typedef GlobalOrdinal gno_t;
471  typedef size_t offset_t;
473  typedef Node node_t;
474  static inline std::string name() {return "Xpetra::MultiVector";}
475 
476  Z2_STATIC_ASSERT_TYPES // validate the types
477 };
478 
479 template <typename Scalar,
480  typename LocalOrdinal,
481  typename GlobalOrdinal,
482  typename Node>
483 struct InputTraits<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
484 {
485  typedef Scalar scalar_t;
486  typedef LocalOrdinal lno_t;
487  typedef GlobalOrdinal gno_t;
488  typedef size_t offset_t;
490  typedef Node node_t;
491  static inline std::string name() {return "Tpetra::MultiVector";}
492 
493  Z2_STATIC_ASSERT_TYPES // validate the types
494 };
495 
496 #ifdef HAVE_ZOLTAN2_EPETRA
497 template < >
498 struct InputTraits<Epetra_MultiVector>
499 {
500  typedef double scalar_t;
501  typedef int lno_t;
502  typedef int gno_t;
503  typedef size_t offset_t;
506  static inline std::string name() {return "Epetra_MultiVector";}
507 };
508 #endif
509 
510 #endif // DOXYGEN_SHOULD_SKIP_THIS
511 
512 
513 } // namespace Zoltan2
514 #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:80
::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:81
default_scalar_t scalar_t
The data type for weights and coordinates.