Zoltan2
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 #ifdef HAVE_TPETRA_EXPLICIT_INSTANTIATION
105 
106 # ifdef HAVE_TPETRA_DOUBLE
107  typedef double zscalar_t;
108 # define HAVE_EPETRA_SCALAR_TYPE
109 # else
110  typedef float zscalar_t;
111 # endif
112 
113 # if defined HAVE_TPETRA_INT_INT
114  typedef int zlno_t;
115  typedef int zgno_t;
116 # if defined HAVE_EPETRA_SCALAR_TYPE
117 # define HAVE_EPETRA_DATA_TYPES
118 # endif
119 # elif defined HAVE_TPETRA_INT_LONG
120  typedef int zlno_t;
121  typedef long zgno_t;
122 # elif defined HAVE_TPETRA_INT_LONG_LONG
123  typedef int zlno_t;
124  typedef long long zgno_t;
125 # elif defined HAVE_TPETRA_INT_UNSIGNED
126  typedef int zlno_t;
127  typedef unsigned zgno_t;
128 # else
129 # error "Tpetra uses ETI, but no lno/gno instantiation is recognized"
130 # endif
131 
132 #else // !HAVE_TPETRA_EXPLICIT_INSTANTIATION
133 
134 # if defined TEST_STK_DATA_TYPES
135  typedef double zscalar_t;
136  typedef ssize_t zlno_t;
137  typedef size_t zgno_t;
138 # else // !TEST_STK_DATA_TYPES
139  typedef double zscalar_t;
140  typedef int zlno_t;
141  typedef int zgno_t;
142 # define HAVE_EPETRA_DATA_TYPES
143 # endif // TEST_STK_DATA_TYPES
144 
145 #endif // HAVE_TPETRA_EXPLICIT_INSTANTIATION
146 
147 #ifndef HAVE_ZOLTAN2_EPETRA
148 # undef HAVE_EPETRA_SCALAR_TYPE
149 # undef HAVE_EPETRA_DATA_TYPES
150 #endif
151 
153 
154 #define MEMORY_CHECK(iPrint, msg) \
155  if (iPrint){ \
156  long kb = Zoltan2::getProcessKilobytes(); \
157  std::cout.width(10); \
158  std::cout.fill('*'); \
159  std::cout << kb << " KB, " << msg << std::endl; \
160  std::cout.width(0); \
161  std::cout.fill(' '); \
162  }
163 
164 #include <ErrorHandlingForTests.hpp>
165 #include <UserInputForTests.hpp>
166 #include <PrintData.hpp>
167 
168 #endif
Generate input for testing purposes.
double zscalar_t
#define PATH_NAME(path)
int zlno_t
int zgno_t
A gathering of useful namespace methods.
Tpetra::Map ::node_type znode_t
std::string zoltanTestDirectory(".")
std::string testDataFilePath(".")