Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
ZoltanPartitioner.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 /**
00017  * Zoltan: class to get a mesh from MOAB and write a Zoltan partition set for
00018  * that mesh back into MOAB and to a file
00019  *
00020  */
00021 
00022 #ifndef ZOLTANPARTITIONER_HPP
00023 #define ZOLTANPARTITIONER_HPP
00024 
00025 #include <cstdlib>
00026 #include "moab/PartitionerBase.hpp"
00027 #include "zoltan_cpp.h"
00028 #include <ctime>
00029 
00030 #ifdef MOAB_HAVE_CGM
00031 #include <map>
00032 #include "GeometryQueryTool.hpp"
00033 #include "DLIList.hpp"
00034 class RefEntity;
00035 #endif
00036 
00037 extern "C" {
00038 int mbGetNumberOfAssignedObjects( void* userDefinedData, int* err );
00039 
00040 void mbGetObjectList( void* userDefinedData,
00041                       int numGlobalIds,
00042                       int numLids,
00043                       ZOLTAN_ID_PTR gids,
00044                       ZOLTAN_ID_PTR lids,
00045                       int wgt_dim,
00046                       float* obj_wgts,
00047                       int* err );
00048 
00049 int mbGetObjectSize( void* userDefinedData, int* err );
00050 
00051 void mbGetObject( void* userDefinedData,
00052                   int numGlobalIds,
00053                   int numLids,
00054                   int numObjs,
00055                   ZOLTAN_ID_PTR gids,
00056                   ZOLTAN_ID_PTR lids,
00057                   int numDim,
00058                   double* pts,
00059                   int* err );
00060 
00061 void mbGetNumberOfEdges( void* userDefinedData,
00062                          int numGlobalIds,
00063                          int numLids,
00064                          int numObjs,
00065                          ZOLTAN_ID_PTR gids,
00066                          ZOLTAN_ID_PTR lids,
00067                          int* numEdges,
00068                          int* err );
00069 
00070 void mbGetEdgeList( void* userDefinedData,
00071                     int numGlobalIds,
00072                     int numLids,
00073                     int numObjs,
00074                     ZOLTAN_ID_PTR gids,
00075                     ZOLTAN_ID_PTR lids,
00076                     int* numEdges,
00077                     ZOLTAN_ID_PTR nborGlobalIds,
00078                     int* nborProcs,
00079                     int wgt_dim,
00080                     float* edge_wgts,
00081                     int* err );
00082 
00083 void mbGetPart( void* userDefinedData,
00084                 int numGlobalIds,
00085                 int numLids,
00086                 int numObjs,
00087                 ZOLTAN_ID_PTR gids,
00088                 ZOLTAN_ID_PTR lids,
00089                 int* part,
00090                 int* err );
00091 
00092 void mbShowError( int val, const char* s, int me );
00093 
00094 void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
00095 }
00096 
00097 #include <vector>
00098 
00099 namespace moab
00100 {
00101 
00102 class ParallelComm;
00103 class Interface;
00104 class Range;
00105 }  // namespace moab
00106 
00107 using namespace moab;
00108 
00109 class ZoltanPartitioner : public PartitionerBase< int >
00110 {
00111 
00112   public:
00113     ZoltanPartitioner( Interface* impl = NULL,
00114 #ifdef MOAB_HAVE_MPI
00115                        ParallelComm* parcomm = NULL,
00116 #endif
00117                        const bool use_coords = false,
00118                        int argc              = 0,
00119                        char** argv           = NULL
00120 #ifdef MOAB_HAVE_CGM
00121                        ,
00122                        GeometryQueryTool* gqt = NULL
00123 #endif
00124 
00125     );
00126 
00127     virtual ~ZoltanPartitioner();
00128 
00129     ErrorCode balance_mesh( const char* zmethod,
00130                             const char* other_method,
00131                             const bool write_as_sets = true,
00132                             const bool write_as_tags = false );
00133 
00134     virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size,
00135                                                    const int nparts,
00136                                                    const char* zmethod,
00137                                                    const char* other_method,
00138                                                    double imbal_tol,
00139                                                    const int part_dim           = 3,
00140                                                    const bool write_as_sets     = true,
00141                                                    const bool write_as_tags     = false,
00142                                                    const int obj_weight         = 0,
00143                                                    const int edge_weight        = 0,
00144                                                    const bool part_surf         = false,
00145                                                    const bool ghost             = false,
00146                                                    const int projection_type    = 0,
00147                                                    const bool recompute_rcb_box = false,
00148                                                    const bool print_time        = false );
00149 
00150     virtual ErrorCode partition_mesh( const int nparts,
00151                                       const char* method,
00152                                       const int part_dim               = 3,
00153                                       const bool write_as_sets         = true,
00154                                       const bool write_as_tags         = false,
00155                                       const bool partition_tagged_sets = false,
00156                                       const bool partition_tagged_ents = false,
00157                                       const char* aggregating_tag      = NULL,
00158                                       const bool print_time            = false );
00159 
00160     // given a processor assignment returned from Zoltan, use that to infer a partition
00161     // to generate processor assignment for a new MOAB mesh in specified fileset
00162     ErrorCode partition_inferred_mesh( EntityHandle sfileset,
00163                                        size_t num_parts,
00164                                        int part_dim             = 3,
00165                                        const bool write_as_sets = true,
00166                                        int projection_type      = 0 );
00167 
00168     // given a processor assignment returned from Zoltan, write that as a
00169     // processor assignment to MOAB
00170     virtual ErrorCode write_partition( const int nparts,
00171                                        Range& elems,
00172                                        const int* assignment,
00173                                        const bool write_as_sets,
00174                                        const bool write_as_tags );
00175 
00176     // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
00177     ErrorCode repartition( std::vector< double >& x,
00178                            std::vector< double >& y,
00179                            std::vector< double >& z,
00180                            int StartID,
00181                            const char* zmethod,
00182                            Range& localGIDs );
00183 
00184     // partition owned cell in a new number of parts, based on adjacency
00185     // we might have some extra adjacencies expressed in extraAdjCellsId, which could point to a
00186     // cell on a different task
00187 
00188     ErrorCode partition_owned_cells( Range& owned,
00189                                      std::multimap< int, int >& extraGraphEdges,
00190                                      std::map< int, int > procs,
00191                                      int& numNewPartitions,
00192                                      std::map< int, Range >& distribution,
00193                                      int met,
00194                                      std::vector< char >& ZoltanBuffer );
00195 
00196 #ifdef MOAB_HAVE_CGM
00197     ErrorCode write_partition( const int nparts,
00198                                DLIList< RefEntity* > entities,
00199                                const int* assignment,
00200                                std::vector< double >& obj_weights,
00201                                const bool part_surf,
00202                                const bool ghost );
00203 
00204     ErrorCode partition_surface( const int nparts,
00205                                  DLIList< RefEntity* > entities,
00206                                  const int* assignment,
00207                                  std::vector< double >& obj_weights );
00208 #endif
00209 
00210     // put closure of entities in the part sets too
00211     ErrorCode include_closure();
00212 
00213     // virtual ErrorCode write_file(const char *filename, const char *out_file);
00214 
00215     void SetOCTPART_Parameters( const char* oct_method );
00216 
00217     void SetPARMETIS_Parameters( const char* parmetis_method );
00218 
00219     void SetHypergraph_Parameters( const char* phg_method );
00220 
00221     void SetHSFC_Parameters();
00222 
00223     void SetRIB_Parameters();
00224 
00225     void SetRCB_Parameters( const bool recompute_rcb_box = false );
00226 
00227   private:
00228     Zoltan* myZZ;
00229 
00230     Range partSets;
00231 
00232     int myNumPts;
00233 
00234     int argcArg;
00235 
00236     char** argvArg;
00237 
00238     int mbGlobalSuccess( int rc );
00239 
00240     void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
00241 
00242     void mbShowError( int val, const char* s );
00243 
00244     // given the dimension, assemble the vertices and store in coords and
00245     // moab_ids
00246     ErrorCode assemble_graph( const int dimension,
00247                               std::vector< double >& coords,
00248                               std::vector< int >& moab_ids,
00249                               std::vector< int >& adjacencies,
00250                               std::vector< int >& length,
00251                               Range& elems,
00252                               bool part_geom            = false,
00253                               const int projection_type = 0 );
00254 
00255 #ifdef MOAB_HAVE_CGM
00256     std::map< int, int > body_vertex_map, surf_vertex_map;
00257 
00258     ErrorCode assemble_graph( const int dimension,
00259                               std::vector< double >& coords,
00260                               std::vector< int >& moab_ids,
00261                               std::vector< int >& adjacencies,
00262                               std::vector< int >& length,
00263                               std::vector< double >& obj_weights,
00264                               std::vector< double >& edge_weights,
00265                               std::vector< int >& parts,
00266                               DLIList< RefEntity* >& entities,
00267                               const double part_geom_mesh_size,
00268                               const int n_part );
00269 
00270     ErrorCode partition_round_robin( const int n_part );
00271 
00272     ErrorCode partition_child_entities( const int dim,
00273                                         const int n_part,
00274                                         const bool partition_surf,
00275                                         const bool ghost = false );
00276 
00277     double estimate_face_mesh_load( RefEntity* face, const double h );
00278     double estimate_face_comm_load( RefEntity* face, const double h );
00279 #endif
00280 
00281     void mbFinalizePoints( int npts, int numExport, ZOLTAN_ID_PTR exportLocalIDs, int* exportProcs, int** assignment );
00282 
00283     int mbInitializePoints( int npts,
00284                             double* pts,
00285                             int* ids,
00286                             int* adjs,
00287                             int* length,
00288                             double* obj_weights  = NULL,
00289                             double* edge_weights = NULL,
00290                             int* parts           = NULL,
00291                             bool part_geom       = false );
00292 
00293 #ifdef MOAB_HAVE_CGM
00294     GeometryQueryTool* gti;
00295 #endif
00296 };
00297 
00298 inline ErrorCode ZoltanPartitioner::partition_mesh( const int nparts,
00299                                                     const char* method,
00300                                                     const int part_dim,
00301                                                     const bool write_as_sets,
00302                                                     const bool write_as_tags,
00303                                                     const bool,
00304                                                     const bool,
00305                                                     const char*,
00306                                                     const bool print_time )
00307 {
00308     return partition_mesh_and_geometry( -1.0, nparts, method, NULL, 1.03, part_dim, write_as_sets, write_as_tags, 0, 0,
00309                                         false, false, 0, false, print_time );
00310 }
00311 
00312 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines