Zoltan2
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 #include <Kokkos_DefaultNode.hpp>
70 
71 namespace Zoltan2{
72 
73 // Default local ordinal
74 typedef int default_lno_t;
75 
76 // Default global ordinal
77 typedef int default_gno_t;
78 
79 // Default scalar type (for weights, coordinates)
80 typedef double default_scalar_t;
81 
82 // Default part number type.
83 typedef int default_part_t; // Restrictions in MPI interface will make it
84  // somewhat difficult to change default_part_t to
85  // long long, since we use part_t for ranks
86  // and we sometimes broadcast arrays whose
87  // size has type part_t.
88  // part_t must be a signed data type.
89 
90 // Until Kokkos node types are supported, use default
91 typedef Tpetra::Map<>::node_type default_node_t;
92 
134 template <typename scalar=double, typename lno=int, typename gno=int>
136 };
137 
172 template <typename User>
173 struct InputTraits {
174 
178 
183 
188 
192 
197 
200  static inline std::string name() {return "InputAdapter";}
201 };
202 
203 #ifndef DOXYGEN_SHOULD_SKIP_THIS
204 
205 // This combination of macros is used to define a single line
206 // Z2_STATIC_ASSERT_TYPES for each InputTraits with custom template types
207 #define Z2_ISSAME(s,type) (std::is_same< s, type >::value)
208 
209 #define Z2_STYPES(s) ( Z2_ISSAME(s,float) || \
210  Z2_ISSAME(s,double) || Z2_ISSAME(s,int) )
211 
212 #define Z2_LTYPES(l) ( Z2_ISSAME(l,int) || \
213  Z2_ISSAME(l,long) || Z2_ISSAME(l,long long) || Z2_ISSAME(l,ssize_t) )
214 
215 #define Z2_GTYPES(g) ( Z2_ISSAME(g,int) || Z2_ISSAME(g,long) || \
216  Z2_ISSAME(g,long long) || Z2_ISSAME(g,ssize_t) || \
217  Z2_ISSAME(g,unsigned int) || Z2_ISSAME(g,unsigned long) || \
218  Z2_ISSAME(g,unsigned long long) || Z2_ISSAME(g,size_t) )
219 
220 #define Z2_SERROR "Invalid scalar type. It must be float, double, or int."
221 
222 #define Z2_LERROR "Invalid local ordinal type. It must be int, long, " \
223  "long long, or ssize_t."
224 
225 #define Z2_GERROR "Invalid global ordinal type. It must be int, long, " \
226  "long long, ssize_t, unsigned int, unsigned long long, size_t."
227 
228 #ifdef Z2_INVERT_STATIC_ASSERT_FOR_UNIT_TESTING
229  #define Z2_STATIC_ASSERT_TYPES static_assert( ( !Z2_STYPES(scalar_t) || \
230  !Z2_LTYPES(lno_t) || !Z2_GTYPES(gno_t) ), \
231  "Inverted unit test for InputTraits was supposed to fail but did not." );
232 #else
233  #define Z2_STATIC_ASSERT_TYPES static_assert( Z2_STYPES(scalar_t), \
234  Z2_SERROR ); static_assert( Z2_LTYPES(lno_t), Z2_LERROR ); \
235  static_assert( Z2_GTYPES(gno_t), Z2_GERROR );
236 #endif
237 
238 template <typename Scalar,
239  typename LocalOrdinal,
240  typename GlobalOrdinal>
241 struct InputTraits<BasicUserTypes<Scalar, LocalOrdinal, GlobalOrdinal> >
242 {
243  typedef Scalar scalar_t;
244  typedef LocalOrdinal lno_t;
245  typedef GlobalOrdinal gno_t;
248  static inline std::string name() {return "BasicUserTypes";}
249 
250  Z2_STATIC_ASSERT_TYPES // validate the types
251 };
252 
253 template <typename Scalar,
254  typename LocalOrdinal,
255  typename GlobalOrdinal,
256  typename Node>
257 struct InputTraits<Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
258 {
259  typedef Scalar scalar_t;
260  typedef LocalOrdinal lno_t;
261  typedef GlobalOrdinal gno_t;
263  typedef Node node_t;
264  static inline std::string name() {return "Xpetra::CrsMatrix";}
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<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
274 {
275  typedef Scalar scalar_t;
276  typedef LocalOrdinal lno_t;
277  typedef GlobalOrdinal gno_t;
279  typedef Node node_t;
280  static inline std::string name() {return "Tpetra::CrsMatrix";}
281 
282  Z2_STATIC_ASSERT_TYPES // validate the types
283 };
284 
285 #ifdef HAVE_ZOLTAN2_EPETRA
286 template < >
287 struct InputTraits<Epetra_CrsMatrix>
288 {
289  typedef double scalar_t;
290  typedef int lno_t;
291  typedef int gno_t;
294  static inline std::string name() {return "Epetra_CrsMatrix";}
295 };
296 #endif
297 
298 template <typename Scalar,
299  typename LocalOrdinal,
300  typename GlobalOrdinal,
301  typename Node>
302 struct InputTraits<Xpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
303 {
304  typedef Scalar scalar_t;
305  typedef LocalOrdinal lno_t;
306  typedef GlobalOrdinal gno_t;
308  typedef Node node_t;
309  static inline std::string name() {return "Xpetra::RowMatrix";}
310 
311  Z2_STATIC_ASSERT_TYPES // validate the types
312 };
313 
314 template <typename Scalar,
315  typename LocalOrdinal,
316  typename GlobalOrdinal,
317  typename Node>
318 struct InputTraits<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
319 {
320  typedef Scalar scalar_t;
321  typedef LocalOrdinal lno_t;
322  typedef GlobalOrdinal gno_t;
324  typedef Node node_t;
325  static inline std::string name() {return "Tpetra::RowMatrix";}
326 
327  Z2_STATIC_ASSERT_TYPES // validate the types
328 };
329 
330 template <typename LocalOrdinal,
331  typename GlobalOrdinal,
332  typename Node>
333 struct InputTraits<Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> >
334 {
335  typedef default_scalar_t scalar_t;
336  typedef LocalOrdinal lno_t;
337  typedef GlobalOrdinal gno_t;
339  typedef Node node_t;
340  static inline std::string name() {return "Tpetra::RowGraph";}
341 };
342 
343 template <typename LocalOrdinal,
344  typename GlobalOrdinal,
345  typename Node>
346 struct InputTraits<Xpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
347 {
348  typedef default_scalar_t scalar_t;
349  typedef LocalOrdinal lno_t;
350  typedef GlobalOrdinal gno_t;
352  typedef Node node_t;
353  static inline std::string name() {return "Xpetra::CrsGraph";}
354 
355  Z2_STATIC_ASSERT_TYPES // validate the types
356 };
357 
358 template <typename LocalOrdinal,
359  typename GlobalOrdinal,
360  typename Node>
361 struct InputTraits<Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >
362 {
363  typedef default_scalar_t scalar_t;
364  typedef LocalOrdinal lno_t;
365  typedef GlobalOrdinal gno_t;
367  typedef Node node_t;
368  static inline std::string name() {return "Tpetra::CrsGraph";}
369 
370  Z2_STATIC_ASSERT_TYPES // validate the types
371 };
372 
373 #ifdef HAVE_ZOLTAN2_EPETRA
374 template < >
375 struct InputTraits<Epetra_CrsGraph>
376 {
377  typedef double scalar_t;
378  typedef int lno_t;
379  typedef int gno_t;
382  static inline std::string name() {return "Epetra_CrsGraph";}
383 };
384 #endif
385 
386 template <typename Scalar,
387  typename LocalOrdinal,
388  typename GlobalOrdinal,
389  typename Node>
390 struct InputTraits<Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
391 {
392  typedef Scalar scalar_t;
393  typedef LocalOrdinal lno_t;
394  typedef GlobalOrdinal gno_t;
396  typedef Node node_t;
397  static inline std::string name() {return "Xpetra::Vector";}
398 
399  Z2_STATIC_ASSERT_TYPES // validate the types
400 };
401 
405 template <typename Scalar,
406  typename LocalOrdinal,
407  typename GlobalOrdinal,
408  typename Node>
409 struct InputTraits<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
410 {
411  typedef Scalar scalar_t;
412  typedef LocalOrdinal lno_t;
413  typedef GlobalOrdinal gno_t;
415  typedef Node node_t;
416  static inline std::string name() {return "Tpetra::Vector";}
417 
418  Z2_STATIC_ASSERT_TYPES // validate the types
419 };
420 
421 #ifdef HAVE_ZOLTAN2_EPETRA
422 template < >
423 struct InputTraits<Epetra_Vector>
424 {
425  typedef double scalar_t;
426  typedef int lno_t;
427  typedef int gno_t;
430  static inline std::string name() {return "Epetra_Vector";}
431 };
432 #endif
433 
434 template <typename Scalar,
435  typename LocalOrdinal,
436  typename GlobalOrdinal,
437  typename Node>
438 struct InputTraits<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
439 {
440  typedef Scalar scalar_t;
441  typedef LocalOrdinal lno_t;
442  typedef GlobalOrdinal gno_t;
444  typedef Node node_t;
445  static inline std::string name() {return "Xpetra::MultiVector";}
446 
447  Z2_STATIC_ASSERT_TYPES // validate the types
448 };
449 
450 template <typename Scalar,
451  typename LocalOrdinal,
452  typename GlobalOrdinal,
453  typename Node>
454 struct InputTraits<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
455 {
456  typedef Scalar scalar_t;
457  typedef LocalOrdinal lno_t;
458  typedef GlobalOrdinal gno_t;
460  typedef Node node_t;
461  static inline std::string name() {return "Tpetra::MultiVector";}
462 
463  Z2_STATIC_ASSERT_TYPES // validate the types
464 };
465 
466 #ifdef HAVE_ZOLTAN2_EPETRA
467 template < >
468 struct InputTraits<Epetra_MultiVector>
469 {
470  typedef double scalar_t;
471  typedef int lno_t;
472  typedef int gno_t;
475  static inline std::string name() {return "Epetra_MultiVector";}
476 };
477 #endif
478 
479 #endif // DOXYGEN_SHOULD_SKIP_THIS
480 
481 
482 } // namespace Zoltan2
483 #endif // ZOLTAN2_INPUTTRAITS_HPP
Tpetra::Map ::node_type default_node_t
default_part_t part_t
The data type to represent part numbers.
A simple class that can be the User template argument for an InputAdapter.
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.
double default_scalar_t
Tpetra::Vector< z2TestScalar, z2TestLO, z2TestGO > Vector
Gathering definitions used in software development.
Vector::node_type Node
default_scalar_t scalar_t
The data type for weights and coordinates.