Zoltan2
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::BasicIdentifierAdapter
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  zlno_t numLocalIds = 10;
71  int nWeights = 2;
72 
73  zgno_t *myIds = new zgno_t[numLocalIds];
74  zscalar_t *weights = new zscalar_t [numLocalIds*nWeights];
75  zgno_t base = rank * numLocalIds * numLocalIds;
76 
77  for (zlno_t i=0; i < numLocalIds; i++){
78  myIds[i] = zgno_t(base+i);
79  weights[i*nWeights] = 1.0;
80  weights[i*nWeights + 1] = (nprocs-rank) / (i+1);
81  }
82 
83  // Create a Zoltan2::BasicIdentifierAdapter object
84  // and verify that it is correct
85 
87  std::vector<const zscalar_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 
96  weightValues, strides);
97 
98  if (!fail && ia.getLocalNumIDs() != size_t(numLocalIds)){
99  fail = 4;
100  }
101 
102  if (!fail && ia.getNumWeightsPerID() != nWeights)
103  fail = 5;
104 
105  const zgno_t *globalIdsIn;
106  zscalar_t const *weightsIn[2];
107  int weightStridesIn[2];
108 
109  ia.getIDsView(globalIdsIn);
110 
111  for (int w=0; !fail && w < nWeights; w++)
112  ia.getWeightsView(weightsIn[w], weightStridesIn[w], w);
113 
114  const zscalar_t *w1 = weightsIn[0];
115  const zscalar_t *w2 = weightsIn[1];
116  int incr1 = weightStridesIn[0];
117  int incr2 = weightStridesIn[1];
118 
119  for (zlno_t i=0; !fail && i < numLocalIds; i++){
120 
121  if (globalIdsIn[i] != zgno_t(base+i))
122  fail = 8;
123 
124  if (!fail && w1[i*incr1] != 1.0)
125  fail = 9;
126 
127  if (!fail && w2[i*incr2] != weights[i*nWeights+1])
128  fail = 10;
129  }
130 
131  delete [] myIds;
132  delete [] weights;
133 
134  gfail = globalFail(comm, fail);
135  if (gfail)
136  printFailureCode(comm, fail); // will exit(1)
137 
138  if (rank == 0)
139  std::cout << "PASS" << std::endl;
140 }
141 
int globalFail(const RCP< const Comm< int > > &comm, int fail)
void getIDsView(const gno_t *&Ids) const
Provide a pointer to this process&#39; identifiers.
double zscalar_t
A simple class that can be the User template argument for an InputAdapter.
static ArrayRCP< ArrayRCP< zscalar_t > > weights
int zlno_t
common code used by tests
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > userTypes_t
This class represents a collection of global Identifiers and their associated weights, if any.
static const std::string fail
int zgno_t
Defines the BasicIdentifierAdapter class.
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const
Provide pointer to a weight array with stride.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
int main(int argc, char *argv[])