MOAB: Mesh Oriented datABase  (version 5.4.1)
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 
00128     virtual ~ZoltanPartitioner();
00129 
00130     ErrorCode balance_mesh( const char* zmethod,
00131                             const char* other_method,
00132                             const bool write_as_sets = true,
00133                             const bool write_as_tags = false );
00134 
00135     virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size,
00136                                                    const int nparts,
00137                                                    const char* zmethod,
00138                                                    const char* other_method,
00139                                                    double imbal_tol,
00140                                                    const int part_dim           = 3,
00141                                                    const bool write_as_sets     = true,
00142                                                    const bool write_as_tags     = false,
00143                                                    const int obj_weight         = 0,
00144                                                    const int edge_weight        = 0,
00145                                                    const bool part_surf         = false,
00146                                                    const bool ghost             = false,
00147                                                    const int projection_type    = 0,
00148                                                    const bool recompute_rcb_box = false,
00149                                                    const bool print_time        = false );
00150 
00151     virtual ErrorCode partition_mesh( const int nparts,
00152                                       const char* method,
00153                                       const int part_dim               = 3,
00154                                       const bool write_as_sets         = true,
00155                                       const bool write_as_tags         = false,
00156                                       const bool partition_tagged_sets = false,
00157                                       const bool partition_tagged_ents = false,
00158                                       const char* aggregating_tag      = NULL,
00159                                       const bool print_time            = false );
00160 
00161     // given a processor assignment returned from Zoltan, use that to infer a partition
00162     // to generate processor assignment for a new MOAB mesh in specified fileset
00163     ErrorCode partition_inferred_mesh( EntityHandle sfileset,
00164                                        size_t num_parts,
00165                                        int part_dim             = 3,
00166                                        const bool write_as_sets = true,
00167                                        int projection_type      = 0 );
00168 
00169     // given a processor assignment returned from Zoltan, write that as a
00170     // processor assignment to MOAB
00171     virtual ErrorCode write_partition( const int nparts,
00172                                        Range& elems,
00173                                        const int* assignment,
00174                                        const bool write_as_sets,
00175                                        const bool write_as_tags );
00176 
00177     // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
00178     ErrorCode repartition( std::vector< double >& x,
00179                            std::vector< double >& y,
00180                            std::vector< double >& z,
00181                            int StartID,
00182                            const char* zmethod,
00183                            Range& localGIDs );
00184 
00185     // partition owned cell in a new number of parts, based on adjacency
00186     // we might have some extra adjacencies expressed in extraAdjCellsId, which could point to a
00187     // cell on a different task
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 
00195 #ifdef MOAB_HAVE_CGM
00196     ErrorCode write_partition( const int nparts,
00197                                DLIList< RefEntity* > entities,
00198                                const int* assignment,
00199                                std::vector< double >& obj_weights,
00200                                const bool part_surf,
00201                                const bool ghost );
00202 
00203     ErrorCode partition_surface( const int nparts,
00204                                  DLIList< RefEntity* > entities,
00205                                  const int* assignment,
00206                                  std::vector< double >& obj_weights );
00207 #endif
00208 
00209     // put closure of entities in the part sets too
00210     ErrorCode include_closure();
00211 
00212     // virtual ErrorCode write_file(const char *filename, const char *out_file);
00213 
00214     void SetOCTPART_Parameters( const char* oct_method );
00215 
00216     void SetPARMETIS_Parameters( const char* parmetis_method );
00217 
00218     void SetHypergraph_Parameters( const char* phg_method );
00219 
00220     void SetHSFC_Parameters();
00221 
00222     void SetRIB_Parameters();
00223 
00224     void SetRCB_Parameters( const bool recompute_rcb_box = false );
00225 
00226   private:
00227     Zoltan* myZZ;
00228 
00229     Range partSets;
00230 
00231     int myNumPts;
00232 
00233     int argcArg;
00234 
00235     char** argvArg;
00236 
00237     int mbGlobalSuccess( int rc );
00238 
00239     void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
00240 
00241     void mbShowError( int val, const char* s );
00242 
00243     // given the dimension, assemble the vertices and store in coords and
00244     // moab_ids
00245     ErrorCode assemble_graph( const int dimension,
00246                               std::vector< double >& coords,
00247                               std::vector< int >& moab_ids,
00248                               std::vector< int >& adjacencies,
00249                               std::vector< int >& length,
00250                               Range& elems,
00251                               bool part_geom            = false,
00252                               const int projection_type = 0 );
00253 
00254 #ifdef MOAB_HAVE_CGM
00255     std::map< int, int > body_vertex_map, surf_vertex_map;
00256 
00257     ErrorCode assemble_graph( const int dimension,
00258                               std::vector< double >& coords,
00259                               std::vector< int >& moab_ids,
00260                               std::vector< int >& adjacencies,
00261                               std::vector< int >& length,
00262                               std::vector< double >& obj_weights,
00263                               std::vector< double >& edge_weights,
00264                               std::vector< int >& parts,
00265                               DLIList< RefEntity* >& entities,
00266                               const double part_geom_mesh_size,
00267                               const int n_part );
00268 
00269     ErrorCode partition_round_robin( const int n_part );
00270 
00271     ErrorCode partition_child_entities( const int dim,
00272                                         const int n_part,
00273                                         const bool partition_surf,
00274                                         const bool ghost = false );
00275 
00276     double estimate_face_mesh_load( RefEntity* face, const double h );
00277     double estimate_face_comm_load( RefEntity* face, const double h );
00278 #endif
00279 
00280     void mbFinalizePoints( int npts, int numExport, ZOLTAN_ID_PTR exportLocalIDs, int* exportProcs, int** assignment );
00281 
00282     int mbInitializePoints( int npts,
00283                             double* pts,
00284                             int* ids,
00285                             int* adjs,
00286                             int* length,
00287                             double* obj_weights  = NULL,
00288                             double* edge_weights = NULL,
00289                             int* parts           = NULL,
00290                             bool part_geom       = false );
00291 
00292 #ifdef MOAB_HAVE_CGM
00293     GeometryQueryTool* gti;
00294 #endif
00295 };
00296 
00297 inline ErrorCode ZoltanPartitioner::partition_mesh( const int nparts,
00298                                                     const char* method,
00299                                                     const int part_dim,
00300                                                     const bool write_as_sets,
00301                                                     const bool write_as_tags,
00302                                                     const bool,
00303                                                     const bool,
00304                                                     const char*,
00305                                                     const bool print_time )
00306 {
00307     return partition_mesh_and_geometry( -1.0, nparts, method, NULL, 1.03, part_dim, write_as_sets, write_as_tags, 0, 0,
00308                                         false, false, 0, false, print_time );
00309 }
00310 
00311 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines