Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_TestHelpers.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 
49 #ifndef ZOLTAN2_TESTHELPERS_HPP
50 #define ZOLTAN2_TESTHELPERS_HPP
51 
52 #include <Zoltan2_Util.hpp>
53 #include <iostream>
54 
55 #include <Tpetra_Map.hpp>
56 typedef Tpetra::Map<>::node_type znode_t;
57 
58 // The path to the directory of test data
59 
60 #define STR_VALUE(path) #path
61 #define PATH_NAME(path) STR_VALUE(path)
62 
63 #ifdef Z2_DATA_DIR
64  std::string testDataFilePath(PATH_NAME(Z2_DATA_DIR));
65 #else
66  std::string testDataFilePath(".");
67 #endif
68 
69 // The path to the Zoltan1 test directory. We use
70 // some of their data for testing.
71 
72 #ifdef Z1_TEST_DIR
73  std::string zoltanTestDirectory(PATH_NAME(Z1_TEST_DIR));
74 #else
75  std::string zoltanTestDirectory(".");
76 #endif
77 
79 //
80 // If Tpetra is compiled with explicit instantiation,
81 // we have to choose data types that are compiled into Tpetra.
82 //
83 // Epetra uses (scalar/lno/gno) == (double/int/int) data types. If we
84 // are using these data types, we can test Epetra user input.
85 
86 // TODO: KDD 8/13/14
87 // Global definitions of types gno_t, lno_t, zgid_t and
88 // scalar_t can cause bugs in the code. If a class fails to define these
89 // types, but this file is included before the class file, the types
90 // from Zoltan2_TestHelpers.hpp will be used in the class. Compilation in
91 // user programs (without Zoltan2_TestHelpers.hpp) would then fail. An
92 // example of this bug was in the GeometricGenerator class, which used
93 // scalar_t without defining it.
94 // In this "fix," I changed gno_t, lno_t, zgid_t, scalar_t, and node_t to
95 // zgno_t, zlno_t, zzgid_t, zscalar_t and znode_t in Zoltan2_TestHelpers.hpp.
96 // This change is not the best fix; a better fix would remove the global
97 // definitions, but that would require more work. (An even better change
98 // would use the Teuchos test framework to cycle through various options,
99 // but that would require even more work and should be delayed until we
100 // revamp the testing.)
101 
102 #include <TpetraCore_config.h>
103 
104  typedef int zpart_t; // added this for consistency but needs further discussion
105 
106 #ifdef HAVE_TPETRA_EXPLICIT_INSTANTIATION
107 
108 # ifdef HAVE_TPETRA_DOUBLE
109  typedef double zscalar_t;
110 # define HAVE_EPETRA_SCALAR_TYPE
111 # else
112  typedef float zscalar_t;
113 # endif
114 
115 # if defined HAVE_TPETRA_INT_INT
116  typedef int zlno_t;
117  typedef int zgno_t;
118 # if defined HAVE_EPETRA_SCALAR_TYPE
119 # define HAVE_EPETRA_DATA_TYPES
120 # endif
121 # elif defined HAVE_TPETRA_INT_LONG
122  typedef int zlno_t;
123  typedef long zgno_t;
124 # elif defined HAVE_TPETRA_INT_LONG_LONG
125  typedef int zlno_t;
126  typedef long long zgno_t;
127 # elif defined HAVE_TPETRA_INT_UNSIGNED
128  typedef int zlno_t;
129  typedef unsigned zgno_t;
130 # else
131 # error "Tpetra uses ETI, but no lno/gno instantiation is recognized"
132 # endif
133 
134 #else // !HAVE_TPETRA_EXPLICIT_INSTANTIATION
135 
136 # if defined TEST_STK_DATA_TYPES
137  typedef double zscalar_t;
138  typedef ssize_t zlno_t;
139  typedef size_t zgno_t;
140 # else // !TEST_STK_DATA_TYPES
141  typedef double zscalar_t;
142  typedef int zlno_t;
143  typedef int zgno_t;
144 # define HAVE_EPETRA_DATA_TYPES
145 # endif // TEST_STK_DATA_TYPES
146 
147 #endif // HAVE_TPETRA_EXPLICIT_INSTANTIATION
148 
149 #ifndef HAVE_ZOLTAN2_EPETRA
150 # undef HAVE_EPETRA_SCALAR_TYPE
151 # undef HAVE_EPETRA_DATA_TYPES
152 #endif
153 
155 
156 #define MEMORY_CHECK(iPrint, msg) \
157  if (iPrint){ \
158  long kb = Zoltan2::getProcessKilobytes(); \
159  std::cout.width(10); \
160  std::cout.fill('*'); \
161  std::cout << kb << " KB, " << msg << std::endl; \
162  std::cout.width(0); \
163  std::cout.fill(' '); \
164  }
165 
166 #include <ErrorHandlingForTests.hpp>
167 #include <UserInputForTests.hpp>
168 #include <PrintData.hpp>
169 
170 #endif
Generate input for testing purposes.
double zscalar_t
#define PATH_NAME(path)
int zlno_t
int zpart_t
int zgno_t
A gathering of useful namespace methods.
Tpetra::Map::node_type znode_t
std::string zoltanTestDirectory(".")
std::string testDataFilePath(".")