Zoltan2  Version of the Day
BasicIdentifierInput.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 // Basic testing of Zoltan2::BasicIdentifierInput
47 
49 #include <Zoltan2_TestHelpers.hpp>
50 
51 #include <Teuchos_GlobalMPISession.hpp>
52 #include <Teuchos_DefaultComm.hpp>
53 #include <Teuchos_RCP.hpp>
54 #include <Teuchos_CommHelpers.hpp>
55 
56 using Teuchos::RCP;
57 using Teuchos::Comm;
58 using Teuchos::DefaultComm;
59 
60 int main(int argc, char *argv[])
61 {
62  Teuchos::GlobalMPISession session(&argc, &argv);
63  RCP<const Comm<int> > comm = DefaultComm<int>::getComm();
64  int rank = comm->getRank();
65  int nprocs = comm->getSize();
66  int fail = 0, gfail=0;
67 
68  // Create global identifiers with weights
69 
70  lno_t numLocalIds = 10;
71  int weightDim = 2;
72 
73  gno_t *myIds = new gno_t [numLocalIds];
74  scalar_t *weights = new scalar_t [numLocalIds*weightDim];
75  gno_t base = rank * numLocalIds * numLocalIds;
76 
77  for (lno_t i=0; i < numLocalIds; i++){
78  myIds[i] = base+i;
79  weights[i*weightDim] = 1.0;
80  weights[i*weightDim + 1] = (nprocs-rank) / (i+1);
81  }
82 
83  // Create a Zoltan2::BasicIdentifierInput object
84  // and verify that it is correct
85 
87  std::vector<const scalar_t *> weightValues;
88  std::vector<int> strides;
89 
90  weightValues.push_back(weights);
91  weightValues.push_back(weights + 1);
92  strides.push_back(2);
93  strides.push_back(2);
94 
95  Zoltan2::BasicIdentifierInput<userTypes_t> ia( numLocalIds, myIds,
96  weightValues, strides);
97 
98  if (rank == 0)
99  std::cout << "Testing " << ia.inputAdapterName() << std::endl;
100 
101  if (!fail && ia.getLocalNumberOfIdentifiers() != size_t(numLocalIds)){
102  fail = 4;
103  }
104 
105  if (!fail && ia.getNumberOfWeights() != weightDim)
106  fail = 5;
107 
108  const gno_t *globalIdsIn;
109  scalar_t const *weightsIn[2];
110  int weightStridesIn[2];
111 
112  if (!fail && ia.getIdentifierList(globalIdsIn) != size_t(numLocalIds))
113  fail = 6;
114 
115  for (int w=0; !fail && w < weightDim; w++){
116  if (ia.getIdentifierWeights(w, weightsIn[w], weightStridesIn[w]) <
117  size_t(numLocalIds * weightStridesIn[w]))
118  fail = 20;
119  }
120 
121  const scalar_t *w1 = weightsIn[0];
122  const scalar_t *w2 = weightsIn[1];
123  int incr1 = weightStridesIn[0];
124  int incr2 = weightStridesIn[1];
125 
126  for (lno_t i=0; !fail && i < numLocalIds; i++){
127 
128  if (globalIdsIn[i] != base+i)
129  fail = 8;
130 
131  if (!fail && w1[i*incr1] != 1.0)
132  fail = 9;
133 
134  if (!fail && w2[i*incr2] != weights[i*weightDim+1])
135  fail = 10;
136  }
137 
138  delete [] myIds;
139  delete [] weights;
140 
141  gfail = globalFail(comm, fail);
142  if (gfail)
143  printFailureCode(comm, fail); // will exit(1)
144 
145  if (rank == 0)
146  std::cout << "PASS" << std::endl;
147 }
148 
int globalFail(const RCP< const Comm< int > > &comm, int fail)
int getNumberOfWeights() const
Return the number of weights associated with each identifier. If the number of weights is zero...
string inputAdapterName() const
Returns a descriptive name that identifies the concrete adapter.
size_t getIdentifierList(const gid_t *&Ids) const
This class represents a collection of global Identifiers and their associated weights, if any.
A simple class that can be the User template argument for an InputAdapter.
size_t getIdentifierWeights(int dimension, const scalar_t *&weights, int &stride) const
Provide a pointer to one of the dimensions of this process&#39; optional weights.
common code used by tests
int main(int argc, char *argv[])
size_t getLocalNumberOfIdentifiers() const
Return the number of identifiers on this process.
double scalar_t
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
Zoltan2::BasicUserTypes< scalar_t, gno_t, lno_t, gno_t > userTypes_t
Defines the BasicIdentifierInput class.