Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
ZoltanPartitioner.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 /**
17  * Zoltan: class to get a mesh from MOAB and write a Zoltan partition set for
18  * that mesh back into MOAB and to a file
19  *
20  */
21 
22 #ifndef ZOLTANPARTITIONER_HPP
23 #define ZOLTANPARTITIONER_HPP
24 
25 #include <cstdlib>
26 #include "moab/PartitionerBase.hpp"
27 #include "zoltan_cpp.h"
28 #include <ctime>
29 
30 extern "C" {
31 int mbGetNumberOfAssignedObjects( void* userDefinedData, int* err );
32 
33 void mbGetObjectList( void* userDefinedData,
34  int numGlobalIds,
35  int numLids,
36  ZOLTAN_ID_PTR gids,
37  ZOLTAN_ID_PTR lids,
38  int wgt_dim,
39  float* obj_wgts,
40  int* err );
41 
42 int mbGetObjectSize( void* userDefinedData, int* err );
43 
44 void mbGetObject( void* userDefinedData,
45  int numGlobalIds,
46  int numLids,
47  int numObjs,
48  ZOLTAN_ID_PTR gids,
49  ZOLTAN_ID_PTR lids,
50  int numDim,
51  double* pts,
52  int* err );
53 
54 void mbGetNumberOfEdges( void* userDefinedData,
55  int numGlobalIds,
56  int numLids,
57  int numObjs,
58  ZOLTAN_ID_PTR gids,
59  ZOLTAN_ID_PTR lids,
60  int* numEdges,
61  int* err );
62 
63 void mbGetEdgeList( void* userDefinedData,
64  int numGlobalIds,
65  int numLids,
66  int numObjs,
67  ZOLTAN_ID_PTR gids,
68  ZOLTAN_ID_PTR lids,
69  int* numEdges,
70  ZOLTAN_ID_PTR nborGlobalIds,
71  int* nborProcs,
72  int wgt_dim,
73  float* edge_wgts,
74  int* err );
75 
76 void mbGetPart( void* userDefinedData,
77  int numGlobalIds,
78  int numLids,
79  int numObjs,
80  ZOLTAN_ID_PTR gids,
81  ZOLTAN_ID_PTR lids,
82  int* part,
83  int* err );
84 
85 void mbShowError( int val, const char* s, int me );
86 
87 void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
88 }
89 
90 #include <vector>
91 
92 namespace moab
93 {
94 
95 class ParallelComm;
96 class Interface;
97 class Range;
98 } // namespace moab
99 
100 using namespace moab;
101 
102 class ZoltanPartitioner : public PartitionerBase< int >
103 {
104 
105  public:
106  ZoltanPartitioner( Interface* impl = NULL,
107 #ifdef MOAB_HAVE_MPI
108  ParallelComm* parcomm = NULL,
109 #endif
110  const bool use_coords = false,
111  int argc = 0,
112  char** argv = NULL );
113 
114  virtual ~ZoltanPartitioner();
115 
116  ErrorCode balance_mesh( const char* zmethod,
117  const char* other_method,
118  const bool write_as_sets = true,
119  const bool write_as_tags = false );
120 
121  virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size,
122  const int nparts,
123  const char* zmethod,
124  const char* other_method,
125  double imbal_tol,
126  const int part_dim = 3,
127  const bool write_as_sets = true,
128  const bool write_as_tags = false,
129  const int obj_weight = 0,
130  const int edge_weight = 0,
131  const int projection_type = 0,
132  const bool recompute_rcb_box = false,
133  const bool print_time = false );
134 
135  virtual ErrorCode partition_mesh( const int nparts,
136  const char* method,
137  const int part_dim = 3,
138  const bool write_as_sets = true,
139  const bool write_as_tags = false,
140  const bool partition_tagged_sets = false,
141  const bool partition_tagged_ents = false,
142  const char* aggregating_tag = NULL,
143  const bool print_time = false );
144 
145  // given a processor assignment returned from Zoltan, use that to infer a partition
146  // to generate processor assignment for a new MOAB mesh in specified fileset
147  ErrorCode partition_inferred_mesh( EntityHandle sfileset,
148  size_t num_parts,
149  int part_dim = 3,
150  const bool write_as_sets = true,
151  int projection_type = 0 );
152 
153  // given a processor assignment returned from Zoltan, write that as a
154  // processor assignment to MOAB
155  virtual ErrorCode write_partition( const int nparts,
156  Range& elems,
157  const int* assignment,
158  const bool write_as_sets,
159  const bool write_as_tags );
160 
161  // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
162  ErrorCode repartition( std::vector< double >& x,
163  std::vector< double >& y,
164  std::vector< double >& z,
165  int StartID,
166  const char* zmethod,
167  Range& localGIDs );
168 
169  ErrorCode repartition_to_procs( std::vector< double >& x,
170  std::vector< double >& y,
171  std::vector< double >& z,
172  std::vector< int >& gids,
173  const char* zmethod,
174  std::vector< int >& dest );
175 
176  // partition owned cell in a new number of parts, based on adjacency
177  // we might have some extra adjacencies expressed in extraAdjCellsId, which could point to a
178  // cell on a different task
179  ErrorCode partition_owned_cells( Range& owned,
180  std::multimap< int, int >& extraGraphEdges,
181  std::map< int, int > procs,
182  int& numNewPartitions,
183  std::map< int, Range >& distribution,
184  int met );
185 
186  // put closure of entities in the part sets too
187  ErrorCode include_closure();
188 
189  // virtual ErrorCode write_file(const char *filename, const char *out_file);
190 
191  void SetOCTPART_Parameters( const char* oct_method );
192 
193  void SetPARMETIS_Parameters( const char* parmetis_method );
194 
195  void SetHypergraph_Parameters( const char* phg_method );
196 
197  void SetHSFC_Parameters();
198 
199  void SetRIB_Parameters();
200 
201  void SetRCB_Parameters( const bool recompute_rcb_box = false );
202 
203  private:
204  Zoltan* myZZ;
205 
207 
208  int myNumPts;
209 
210  int argcArg;
211 
212  char** argvArg;
213 
214  int mbGlobalSuccess( int rc );
215 
216  void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
217 
218  void mbShowError( int val, const char* s );
219 
220  // given the dimension, assemble the vertices and store in coords and
221  // moab_ids
222  ErrorCode assemble_graph( const int dimension,
223  std::vector< double >& coords,
224  std::vector< int >& moab_ids,
225  std::vector< int >& adjacencies,
226  std::vector< int >& length,
227  Range& elems,
228  bool part_geom = false,
229  const int projection_type = 0 );
230 
231  void mbFinalizePoints( int npts, int numExport, ZOLTAN_ID_PTR exportLocalIDs, int* exportProcs, int** assignment );
232 
233  int mbInitializePoints( int npts,
234  double* pts,
235  int* ids,
236  int* adjs,
237  int* length,
238  double* obj_weights = NULL,
239  double* edge_weights = NULL,
240  int* parts = NULL,
241  bool part_geom = false );
242 };
243 
245  const char* method,
246  const int part_dim,
247  const bool write_as_sets,
248  const bool write_as_tags,
249  const bool,
250  const bool,
251  const char*,
252  const bool print_time )
253 {
254  return partition_mesh_and_geometry( -1.0, nparts, method, NULL, 1.03, part_dim, write_as_sets, write_as_tags, 0, 0,
255  0, false, print_time );
256 }
257 
258 #endif