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>
140 };
141 
176 template <typename User>
177 struct InputTraits {
178 
182 
187 
192 
196 
200 
205 
208  static inline std::string name() {return "InputAdapter";}
209 };
210 
211 #ifndef DOXYGEN_SHOULD_SKIP_THIS
212 
213 // This combination of macros is used to define a single line
214 // Z2_STATIC_ASSERT_TYPES for each InputTraits with custom template types
215 #define Z2_ISSAME(s,type) (std::is_same< s, type >::value)
216 
217 #define Z2_STYPES(s) ( Z2_ISSAME(s,float) || \
218  Z2_ISSAME(s,double) || Z2_ISSAME(s,int) )
219 
220 #define Z2_LTYPES(l) ( Z2_ISSAME(l,int) || \
221  Z2_ISSAME(l,long) || Z2_ISSAME(l,long long) || Z2_ISSAME(l,ssize_t) )
222 
223 #define Z2_GTYPES(g) ( Z2_ISSAME(g,int) || Z2_ISSAME(g,long) || \
224  Z2_ISSAME(g,long long) || Z2_ISSAME(g,ssize_t) || \
225  Z2_ISSAME(g,unsigned int) || Z2_ISSAME(g,unsigned long) || \
226  Z2_ISSAME(g,unsigned long long) || Z2_ISSAME(g,size_t) )
227 
228 #define Z2_SERROR "Invalid scalar type. It must be float, double, or int."
229 
230 #define Z2_LERROR "Invalid local ordinal type. It must be int, long, " \
231  "long long, or ssize_t."
232 
233 #define Z2_GERROR "Invalid global ordinal type. It must be int, long, " \
234  "long long, ssize_t, unsigned int, unsigned long long, size_t."
235 
236 #ifdef Z2_INVERT_STATIC_ASSERT_FOR_UNIT_TESTING
237  #define Z2_STATIC_ASSERT_TYPES static_assert( ( !Z2_STYPES(scalar_t) || \
238  !Z2_LTYPES(lno_t) || !Z2_GTYPES(gno_t) ), \
239  "Inverted unit test for InputTraits was supposed to fail but did not." );
240 #else
241  #define Z2_STATIC_ASSERT_TYPES static_assert( Z2_STYPES(scalar_t), \
242  Z2_SERROR ); static_assert( Z2_LTYPES(lno_t), Z2_LERROR ); \
243  static_assert( Z2_GTYPES(gno_t), Z2_GERROR );
244 #endif
245 
246 template <typename Scalar,
247  typename LocalOrdinal,
248  typename GlobalOrdinal>
249 struct InputTraits<BasicUserTypes<Scalar, LocalOrdinal, GlobalOrdinal> >
250 {
251  typedef Scalar scalar_t;
252  typedef LocalOrdinal lno_t;
253  typedef GlobalOrdinal gno_t;
254  typedef LocalOrdinal offset_t;
257  static inline std::string name() {return "BasicUserTypes";}
258 
259  Z2_STATIC_ASSERT_TYPES // validate the types
260 };
261 
262 template <typename Scalar,
263  typename LocalOrdinal,
264  typename GlobalOrdinal,
265  typename Node>
266 struct InputTraits<Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
267 {
268  typedef Scalar scalar_t;
269  typedef LocalOrdinal lno_t;
270  typedef GlobalOrdinal gno_t;
271  typedef size_t offset_t;
273  typedef Node node_t;
274  static inline std::string name() {return "Xpetra::CrsMatrix";}
275 
276  Z2_STATIC_ASSERT_TYPES // validate the types
277 };
278 
279 template <typename Scalar,
280  typename LocalOrdinal,
281  typename GlobalOrdinal,
282  typename Node>
283 struct InputTraits<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
284 {
285  typedef Scalar scalar_t;
286  typedef LocalOrdinal lno_t;
287  typedef GlobalOrdinal gno_t;
288  typedef size_t offset_t;
290  typedef Node node_t;
291  static inline std::string name() {return "Tpetra::CrsMatrix";}
292 
293  Z2_STATIC_ASSERT_TYPES // validate the types
294 };
295 
296 #ifdef HAVE_ZOLTAN2_EPETRA
297 template < >
298 struct InputTraits<Epetra_CrsMatrix>
299 {
300  typedef double scalar_t;
301  typedef int lno_t;
302  typedef int gno_t;
303  typedef size_t offset_t;
306  static inline std::string name() {return "Epetra_CrsMatrix";}
307 };
308 #endif
309 
310 template <typename Scalar,
311  typename LocalOrdinal,
312  typename GlobalOrdinal,
313  typename Node>
314 struct InputTraits<Xpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
315 {
316  typedef Scalar scalar_t;
317  typedef LocalOrdinal lno_t;
318  typedef GlobalOrdinal gno_t;
319  typedef size_t offset_t;
321  typedef Node node_t;
322  static inline std::string name() {return "Xpetra::RowMatrix";}
323 
324  Z2_STATIC_ASSERT_TYPES // validate the types
325 };
326 
327 template <typename Scalar,
328  typename LocalOrdinal,
329  typename GlobalOrdinal,
330  typename Node>
331 struct InputTraits<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
332 {
333  typedef Scalar scalar_t;
334  typedef LocalOrdinal lno_t;
335  typedef GlobalOrdinal gno_t;
336  typedef size_t offset_t;
338  typedef Node node_t;
339  static inline std::string name() {return "Tpetra::RowMatrix";}
340 
341  Z2_STATIC_ASSERT_TYPES // validate the types
342 };
343 
344 template <typename LocalOrdinal,
345  typename GlobalOrdinal,
346  typename Node>
347 struct InputTraits<Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> >
348 {
349  typedef default_scalar_t scalar_t;
350  typedef LocalOrdinal lno_t;
351  typedef GlobalOrdinal gno_t;
352  typedef size_t offset_t;
354  typedef Node node_t;
355  static inline std::string name() {return "Tpetra::RowGraph";}
356 };
357 
358 template <typename LocalOrdinal,
359  typename GlobalOrdinal,
360  typename Node>
361 struct InputTraits<Xpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
362 {
363  typedef default_scalar_t scalar_t;
364  typedef LocalOrdinal lno_t;
365  typedef GlobalOrdinal gno_t;
366  typedef size_t offset_t;
368  typedef Node node_t;
369  static inline std::string name() {return "Xpetra::CrsGraph";}
370 
371  Z2_STATIC_ASSERT_TYPES // validate the types
372 };
373 
374 template <typename LocalOrdinal,
375  typename GlobalOrdinal,
376  typename Node>
377 struct InputTraits<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
378 {
379  typedef default_scalar_t scalar_t;
380  typedef LocalOrdinal lno_t;
381  typedef GlobalOrdinal gno_t;
382  typedef size_t offset_t;
384  typedef Node node_t;
385  static inline std::string name() {return "Tpetra::CrsGraph";}
386 
387  Z2_STATIC_ASSERT_TYPES // validate the types
388 };
389 
390 #ifdef HAVE_ZOLTAN2_EPETRA
391 template < >
392 struct InputTraits<Epetra_CrsGraph>
393 {
394  typedef double scalar_t;
395  typedef int lno_t;
396  typedef int gno_t;
397  typedef size_t offset_t;
400  static inline std::string name() {return "Epetra_CrsGraph";}
401 };
402 #endif
403 
404 template <typename Scalar,
405  typename LocalOrdinal,
406  typename GlobalOrdinal,
407  typename Node>
408 struct InputTraits<Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
409 {
410  typedef Scalar scalar_t;
411  typedef LocalOrdinal lno_t;
412  typedef GlobalOrdinal gno_t;
413  typedef size_t offset_t;
415  typedef Node node_t;
416  static inline std::string name() {return "Xpetra::Vector";}
417 
418  Z2_STATIC_ASSERT_TYPES // validate the types
419 };
420 
424 template <typename Scalar,
425  typename LocalOrdinal,
426  typename GlobalOrdinal,
427  typename Node>
428 struct InputTraits<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
429 {
430  typedef Scalar scalar_t;
431  typedef LocalOrdinal lno_t;
432  typedef GlobalOrdinal gno_t;
433  typedef size_t offset_t;
435  typedef Node node_t;
436  static inline std::string name() {return "Tpetra::Vector";}
437 
438  Z2_STATIC_ASSERT_TYPES // validate the types
439 };
440 
441 #ifdef HAVE_ZOLTAN2_EPETRA
442 template < >
443 struct InputTraits<Epetra_Vector>
444 {
445  typedef double scalar_t;
446  typedef int lno_t;
447  typedef int gno_t;
448  typedef size_t offset_t;
451  static inline std::string name() {return "Epetra_Vector";}
452 };
453 #endif
454 
455 template <typename Scalar,
456  typename LocalOrdinal,
457  typename GlobalOrdinal,
458  typename Node>
459 struct InputTraits<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
460 {
461  typedef Scalar scalar_t;
462  typedef LocalOrdinal lno_t;
463  typedef GlobalOrdinal gno_t;
464  typedef size_t offset_t;
466  typedef Node node_t;
467  static inline std::string name() {return "Xpetra::MultiVector";}
468 
469  Z2_STATIC_ASSERT_TYPES // validate the types
470 };
471 
472 template <typename Scalar,
473  typename LocalOrdinal,
474  typename GlobalOrdinal,
475  typename Node>
476 struct InputTraits<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
477 {
478  typedef Scalar scalar_t;
479  typedef LocalOrdinal lno_t;
480  typedef GlobalOrdinal gno_t;
481  typedef size_t offset_t;
483  typedef Node node_t;
484  static inline std::string name() {return "Tpetra::MultiVector";}
485 
486  Z2_STATIC_ASSERT_TYPES // validate the types
487 };
488 
489 #ifdef HAVE_ZOLTAN2_EPETRA
490 template < >
491 struct InputTraits<Epetra_MultiVector>
492 {
493  typedef double scalar_t;
494  typedef int lno_t;
495  typedef int gno_t;
496  typedef size_t offset_t;
499  static inline std::string name() {return "Epetra_MultiVector";}
500 };
501 #endif
502 
503 #endif // DOXYGEN_SHOULD_SKIP_THIS
504 
505 
506 } // namespace Zoltan2
507 #endif // ZOLTAN2_INPUTTRAITS_HPP
Tpetra::Vector< z2TestScalar, z2TestLO, z2TestGO > Vector
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::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.
Vector::node_type Node
Gathering definitions used in software development.
::Tpetra::Details::DefaultTypes::node_type default_node_t
default_scalar_t scalar_t
The data type for weights and coordinates.