Zoltan2  Version of the Day
block.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 
53 
54 using namespace std;
55 
62 // Zoltan2 is templated. What data types will we use for
63 // scalars (coordinate values and weights), for local ids, and
64 // for global ids?
65 //
66 // If Zoltan2 was compiled with explicit instantiation, we will
67 // use the the library's data types. These macros are defined
68 // in Zoltan2_config.h.
69 
70 #ifdef HAVE_ZOLTAN2_INST_FLOAT_INT_LONG
71 typedef float scalar_t;
72 typedef int localId_t;
73 typedef long globalId_t;
74 #else
75  #ifdef HAVE_ZOLTAN2_INST_DOUBLE_INT_LONG
76  typedef double scalar_t;
77  typedef int localId_t;
78  typedef long globalId_t;
79  #else
80  #ifdef HAVE_ZOLTAN2_INST_FLOAT_INT_INT
81  typedef float scalar_t;
82  typedef int localId_t;
83  typedef int globalId_t;
84  #else
85  #ifdef HAVE_ZOLTAN2_INST_DOUBLE_INT_INT
86  typedef double scalar_t;
87  typedef int localId_t;
88  typedef int globalId_t;
89  #else
90  typedef float scalar_t;
91  typedef int localId_t;
92  typedef int globalId_t;
93  #endif
94  #endif
95  #endif
96 #endif
97 
98 int main(int argc, char *argv[])
99 {
100 #ifdef HAVE_ZOLTAN2_MPI
101  MPI_Init(&argc, &argv);
102  int rank, nprocs;
103  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
104  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
105 #else
106  int rank=0, nprocs=1;
107 #endif
108 
110  // Generate some input data.
111 
112  size_t localCount = 40*(rank+1);
113  globalId_t *globalIds = new globalId_t [localCount];
114 
115  if (rank==0)
116  for (int i=0, num=40; i <= nprocs ; i++, num+=40)
117  cout << "Rank " << i << " has " << num << " ids." << endl;
118 
119  globalId_t offset = 0;
120  for (int i=1; i <= rank; i++)
121  offset += 40*i;
122 
123  for (size_t i=0; i < localCount; i++)
124  globalIds[i] = offset++;
125 
127  // Create a Zoltan2 input adapter with no weights
128 
129  // TODO explain
131 
132  // TODO explain
134 
135  std::vector<const scalar_t *> noWeights;
136  std::vector<int> noStrides;
137 
138  inputAdapter_t ia(localCount, globalIds, noWeights, noStrides);
139 
141  // Create parameters for an Block problem
142 
143  Teuchos::ParameterList params("test params");
144  params.set("debug_level", "basic_status");
145  params.set("debug_procs", "0");
146  params.set("error_check_level", "debug_mode_assertions");
147 
148  params.set("algorithm", "block");
149  params.set("imbalance_tolerance", 1.1);
150  params.set("num_global_parts", nprocs);
151 
153  // Create a Zoltan2 partitioning problem
154 
155 #ifdef HAVE_ZOLTAN2_MPI
158  MPI_COMM_WORLD);
159 #else
162 #endif
163 
165  // Solve the problem
166 
167  problem->solve();
168 
170  // Check the solution.
171 
172  if (rank == 0)
173  problem->printMetrics(cout);
174 
175  if (rank == 0)
176  cout << "PASS" << endl;
177 
178  delete [] globalIds;
179  delete problem;
180 #ifdef HAVE_ZOLTAN2_MPI
181  MPI_Finalize();
182 #endif
183 }
184 
int localId_t
Definition: block.cpp:91
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.
int globalId_t
Definition: block.cpp:92
Defines the PartitioningSolution class.
int main(int argc, char *argv[])
void printMetrics(ostream &os) const
Print the array of metrics.
double scalar_t
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
Defines the BasicIdentifierInput class.
Zoltan2::BasicIdentifierInput< myTypes_t > inputAdapter_t