Zoltan2  Version of the Day
IdentifierTraits.cpp
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 
46 // TODO: doxygen comments
47 
48 // TODO: just testing that the test compiles and looks reasonable
49 // We need to test the validity of the values returned in check_traits.
50 
51 #include <Zoltan2_TestHelpers.hpp>
53 #include <ostream>
54 #include <string>
55 #include <algorithm>
56 #include <utility>
57 #include <Teuchos_GlobalMPISession.hpp>
58 
59 using namespace std;
60 
61 // TODO - add answers to check_traits to verify the results
62 template <typename T>
64  Teuchos::RCP<const Teuchos::Comm<int> > &tcomm , T &val, T &higherVal)
65 {
66  const Teuchos::Comm<int> *comm = tcomm.get();
68  T valueList[2] = {val, higherVal};
69 
70  double k(0);
71  if (id::hasUniqueKey())
72  k = id::key(val);
73 
74  std::cout << "ID type: " << id::name() << std::endl;
75  std::cout << "Value: " << id::stringify(val) << std::endl;
76  std::cout << "\"Higher\" value: " << id::stringify(higherVal) << std::endl;
77  std::cout << "Int hash code (non-unique): " << id::hashCode(val) << std::endl;
78  std::cout << "Supports unique key: " << id::hasUniqueKey() << std::endl;
79  if (id::hasUniqueKey())
80  std::cout << "Key value: " << k << std::endl;
81  std::cout << "Is Teuchos Global Ordinal: " << id::isGlobalOrdinal() << std::endl;
82  std::cout << "Is valid id type: " << id::is_valid_id_type() << std::endl;
83 
85 
86  bool supported = true;
87  T lo, hi;
88  std::cout << "minMax: ";
89  try{
90  id::minMax(valueList, 2, lo, hi);
91  }
92  catch(...){
93  supported = false;
94  }
95 
96  if (supported)
97  std::cout << id::stringify(lo) << ", " << id::stringify(hi) << std::endl;
98  else
99  std::cout << "not supported" << std::endl;
100 
102 
103  supported = true;
104  T gmin, gmax;
105  std::cout << "global minMax: ";
106  try{
107  id::globalMinMax(*comm, false, lo, hi, gmin, gmax);
108  }
109  catch(...){
110  supported = false;
111  }
112 
113  if (supported)
114  std::cout << id::stringify(lo) << ", " << id::stringify(hi) << std::endl;
115  else
116  std::cout << "not supported" << std::endl;
117 
119 
120  supported = true;
121  T diff;
122  std::cout << "Difference : ";
123  try{
124  diff = id::difference(val, higherVal);
125  }
126  catch(...){
127  supported = false;
128  }
129 
130  if (supported)
131  std::cout << id::stringify(diff) << std::endl;
132  else
133  std::cout << "not supported" << std::endl;
134 
136 
137  supported = true;
138  bool consec=false;
139  std::cout << "Are consecutive: ";
140  try{
141  consec = id::areConsecutive(valueList, 2);
142  }
143  catch(...){
144  supported = false;
145  }
146 
147  if (supported)
148  std::cout << consec << std::endl;
149  else
150  std::cout << "not supported" << std::endl;
151 
152  std::cout << std::endl;
153 }
154 int main(int argc, char *argv[])
155 {
156  Teuchos::GlobalMPISession session(&argc, &argv);
157  Teuchos::RCP<const Teuchos::Comm<int> > nullComm;
158  Teuchos::RCP<const Teuchos::Comm<int> > comm =
159  Teuchos::DefaultComm<int>::getDefaultSerialComm(nullComm);
160 
161  int rank = session.getRank();
162 
163  if (rank == 0){
164  char c='a';
165  char c_other ='v';
166  unsigned char uc='A';
167  unsigned char uc_other ='Z';
168  short int si=1024;
169  short int si_other =11024;
170  unsigned short int usi=1024;
171  unsigned short int usi_other =11024;
172  int i=1024;
173  int i_other=11024;
174  unsigned int ui=1024;
175  unsigned int ui_other=11024;
176  long int li=1024;
177  long int li_other=11024;
178  long unsigned int lui =1024;
179  long unsigned int lui_other =11024;
180 #ifdef HAVE_ZOLTAN2_LONG_LONG
181  long long int lli = 3000000000;
182  long long int lli_other = 3102400000000;
183  unsigned long long int ulli = 3000000000;
184  unsigned long long int ulli_other = 3102400000000;
185 #endif
186  std::pair<int, int> pairVals(1024, 1024);
187  std::pair<int, int> pairVals_other(11024, 11024);
188 
189  std::pair<long, long> pairValsLong(1024, 1024);
190  std::pair<long, long> pairValsLong_other(11024, 11024);
191 
192  string strVal("right front wheel");
193  string strVal_other("left front wheel");
194 
195  check_traits(comm, c, c_other);
196  check_traits(comm, uc, uc_other);
197  check_traits(comm, si, si_other);
198  check_traits(comm, usi, usi_other);
199  check_traits(comm, i, i_other);
200  check_traits(comm, ui, ui_other);
201  check_traits(comm, li, li_other);
202  check_traits(comm, lui, lui_other);
203 #ifdef HAVE_ZOLTAN2_LONG_LONG
204  check_traits(comm, lli, lli_other);
205  check_traits(comm, ulli, ulli_other);
206 #endif
207  check_traits(comm, pairVals, pairVals_other);
208  check_traits(comm, pairValsLong, pairValsLong_other);
209  check_traits(comm, strVal, strVal_other);
210 
211  std::cout << "PASS" << std::endl;
212  }
213 
214  return 0;
215 }
216 
common code used by tests
Defines basic traits for user global identifiers.
The functions to be defined for users&#39; global ID types.
int main(int argc, char *argv[])
void check_traits(Teuchos::RCP< const Teuchos::Comm< int > > &tcomm, T &val, T &higherVal)