Mesh Oriented datABase  (version 5.5.1)
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 
115  virtual ~ZoltanPartitioner();
116 
117  ErrorCode balance_mesh( const char* zmethod,
118  const char* other_method,
119  const bool write_as_sets = true,
120  const bool write_as_tags = false );
121 
122  virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size,
123  const int nparts,
124  const char* zmethod,
125  const char* other_method,
126  double imbal_tol,
127  const int part_dim = 3,
128  const bool write_as_sets = true,
129  const bool write_as_tags = false,
130  const int obj_weight = 0,
131  const int edge_weight = 0,
132  const int projection_type = 0,
133  const bool recompute_rcb_box = false,
134  const bool print_time = false );
135 
136  virtual ErrorCode partition_mesh( const int nparts,
137  const char* method,
138  const int part_dim = 3,
139  const bool write_as_sets = true,
140  const bool write_as_tags = false,
141  const bool partition_tagged_sets = false,
142  const bool partition_tagged_ents = false,
143  const char* aggregating_tag = NULL,
144  const bool print_time = false );
145 
146  // given a processor assignment returned from Zoltan, use that to infer a partition
147  // to generate processor assignment for a new MOAB mesh in specified fileset
148  ErrorCode partition_inferred_mesh( EntityHandle sfileset,
149  size_t num_parts,
150  int part_dim = 3,
151  const bool write_as_sets = true,
152  int projection_type = 0 );
153 
154  // given a processor assignment returned from Zoltan, write that as a
155  // processor assignment to MOAB
156  virtual ErrorCode write_partition( const int nparts,
157  Range& elems,
158  const int* assignment,
159  const bool write_as_sets,
160  const bool write_as_tags );
161 
162  // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
163  ErrorCode repartition( std::vector< double >& x,
164  std::vector< double >& y,
165  std::vector< double >& z,
166  int StartID,
167  const char* zmethod,
168  Range& localGIDs );
169 
170  ErrorCode repartition_to_procs( std::vector< double >& x,
171  std::vector< double >& y,
172  std::vector< double >& z,
173  std::vector< int >& gids,
174  const char* zmethod,
175  std::vector< int >& dest );
176 
177  // partition owned cell in a new number of parts, based on adjacency
178  // we might have some extra adjacencies expressed in extraAdjCellsId, which could point to a
179  // cell on a different task
180  ErrorCode partition_owned_cells( Range& owned,
181  std::multimap< int, int >& extraGraphEdges,
182  std::map< int, int > procs,
183  int& numNewPartitions,
184  std::map< int, Range >& distribution,
185  int met );
186 
187  // put closure of entities in the part sets too
188  ErrorCode include_closure();
189 
190  // virtual ErrorCode write_file(const char *filename, const char *out_file);
191 
192  void SetOCTPART_Parameters( const char* oct_method );
193 
194  void SetPARMETIS_Parameters( const char* parmetis_method );
195 
196  void SetHypergraph_Parameters( const char* phg_method );
197 
198  void SetHSFC_Parameters();
199 
200  void SetRIB_Parameters();
201 
202  void SetRCB_Parameters( const bool recompute_rcb_box = false );
203 
204  private:
205  Zoltan* myZZ;
206 
208 
209  int myNumPts;
210 
211  int argcArg;
212 
213  char** argvArg;
214 
215  int mbGlobalSuccess( int rc );
216 
217  void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
218 
219  void mbShowError( int val, const char* s );
220 
221  // given the dimension, assemble the vertices and store in coords and
222  // moab_ids
223  ErrorCode assemble_graph( const int dimension,
224  std::vector< double >& coords,
225  std::vector< int >& moab_ids,
226  std::vector< int >& adjacencies,
227  std::vector< int >& length,
228  Range& elems,
229  bool part_geom = false,
230  const int projection_type = 0 );
231 
232  void mbFinalizePoints( int npts, int numExport, ZOLTAN_ID_PTR exportLocalIDs, int* exportProcs, int** assignment );
233 
234  int mbInitializePoints( int npts,
235  double* pts,
236  int* ids,
237  int* adjs,
238  int* length,
239  double* obj_weights = NULL,
240  double* edge_weights = NULL,
241  int* parts = NULL,
242  bool part_geom = false );
243 
244 };
245 
247  const char* method,
248  const int part_dim,
249  const bool write_as_sets,
250  const bool write_as_tags,
251  const bool,
252  const bool,
253  const char*,
254  const bool print_time )
255 {
256  return partition_mesh_and_geometry( -1.0, nparts, method, NULL, 1.03, part_dim, write_as_sets, write_as_tags, 0, 0,
257  0, false, print_time );
258 }
259 
260 #endif