MOAB: Mesh Oriented datABase  (version 5.2.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 <stdlib.h>
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, int numGlobalIds, int numLids, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
00041                       int wgt_dim, float* obj_wgts, int* err );
00042 
00043 int mbGetObjectSize( void* userDefinedData, int* err );
00044 
00045 void mbGetObject( void* userDefinedData, int numGlobalIds, int numLids, int numObjs, ZOLTAN_ID_PTR gids,
00046                   ZOLTAN_ID_PTR lids, int numDim, double* pts, int* err );
00047 
00048 void mbGetNumberOfEdges( void* userDefinedData, int numGlobalIds, int numLids, int numObjs, ZOLTAN_ID_PTR gids,
00049                          ZOLTAN_ID_PTR lids, int* numEdges, int* err );
00050 
00051 void mbGetEdgeList( void* userDefinedData, int numGlobalIds, int numLids, int numObjs, ZOLTAN_ID_PTR gids,
00052                     ZOLTAN_ID_PTR lids, int* numEdges, ZOLTAN_ID_PTR nborGlobalIds, int* nborProcs, int wgt_dim,
00053                     float* edge_wgts, int* err );
00054 
00055 void mbGetPart( void* userDefinedData, int numGlobalIds, int numLids, int numObjs, ZOLTAN_ID_PTR gids,
00056                 ZOLTAN_ID_PTR lids, int* part, int* err );
00057 
00058 void mbShowError( int val, const char* s, int me );
00059 
00060 void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
00061 }
00062 
00063 #include <vector>
00064 
00065 namespace moab
00066 {
00067 
00068 class ParallelComm;
00069 class Interface;
00070 class Range;
00071 }  // namespace moab
00072 
00073 using namespace moab;
00074 
00075 class ZoltanPartitioner : public PartitionerBase< int >
00076 {
00077 
00078   public:
00079     ZoltanPartitioner( Interface* impl = NULL, const bool use_coords = false, int argc = 0, char** argv = NULL
00080 #ifdef MOAB_HAVE_CGM
00081                        ,
00082                        GeometryQueryTool* gqt = NULL
00083 #endif
00084     );
00085 
00086     virtual ~ZoltanPartitioner();
00087 
00088     ErrorCode balance_mesh( const char* zmethod, const char* other_method, const bool write_as_sets = true,
00089                             const bool write_as_tags = false );
00090 
00091     virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size, const int nparts,
00092                                                    const char* zmethod, const char* other_method, double imbal_tol,
00093                                                    const int part_dim = 3, const bool write_as_sets = true,
00094                                                    const bool write_as_tags = false, const int obj_weight = 0,
00095                                                    const int edge_weight = 0, const bool part_surf = false,
00096                                                    const bool ghost = false, const int projection_type = 0, const bool recompute_rcb_box = false,
00097                                                    const bool print_time = false );
00098 
00099     virtual ErrorCode partition_mesh( const int nparts, const char* method, const int part_dim = 3,
00100                                       const bool write_as_sets = true, const bool write_as_tags = false,
00101                                       const bool partition_tagged_sets = false,
00102                                       const bool partition_tagged_ents = false, const char* aggregating_tag = NULL,
00103                                       const bool print_time = false );
00104 
00105     // given a processor assignment returned from Zoltan, use that to infer a partition
00106     // to generate processor assignment for a new MOAB mesh in specified fileset
00107     ErrorCode partition_inferred_mesh( EntityHandle sfileset, size_t num_parts, int part_dim = 3,
00108                                        const bool write_as_sets = true, int projection_type = 0 );
00109 
00110     // given a processor assignment returned from Zoltan, write that as a
00111     // processor assignment to MOAB
00112     virtual ErrorCode write_partition( const int nparts, Range& elems, const int* assignment, const bool write_as_sets,
00113                                        const bool write_as_tags );
00114 
00115     // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
00116     ErrorCode repartition( std::vector< double >& x, std::vector< double >& y, std::vector< double >& z, int StartID,
00117                            const char* zmethod, Range& localGIDs );
00118 
00119     // partition owned cell in a new number of parts, based on adjacency
00120     // we might have some extra adjacencies expressed in extraAdjCellsId, which could point to a
00121     // cell on a different task
00122     ErrorCode partition_owned_cells( Range& owned, ParallelComm* pco, std::multimap< int, int >& extraGraphEdges,
00123                                      std::map< int, int > procs, int& numNewPartitions,
00124                                      std::map< int, Range >& distribution, int met );
00125 
00126 #ifdef MOAB_HAVE_CGM
00127     ErrorCode write_partition( const int nparts, DLIList< RefEntity* > entities, const int* assignment,
00128                                std::vector< double >& obj_weights, const bool part_surf, const bool ghost );
00129 
00130     ErrorCode partition_surface( const int nparts, DLIList< RefEntity* > entities, const int* assignment,
00131                                  std::vector< double >& obj_weights );
00132 #endif
00133 
00134     // put closure of entities in the part sets too
00135     ErrorCode include_closure();
00136 
00137     // virtual ErrorCode write_file(const char *filename, const char *out_file);
00138 
00139     void SetOCTPART_Parameters( const char* oct_method );
00140 
00141     void SetPARMETIS_Parameters( const char* parmetis_method );
00142 
00143     void SetHypergraph_Parameters( const char* phg_method );
00144 
00145     void SetHSFC_Parameters();
00146 
00147     void SetRIB_Parameters();
00148 
00149     void SetRCB_Parameters(const bool recompute_rcb_box = false);
00150 
00151   private:
00152     Zoltan* myZZ;
00153 
00154     Range partSets;
00155 
00156     int myNumPts;
00157 
00158     int argcArg;
00159 
00160     char** argvArg;
00161 
00162     int mbGlobalSuccess( int rc );
00163 
00164     void mbPrintGlobalResult( const char* s, int begin, int import, int exp, int change );
00165 
00166     void mbShowError( int val, const char* s );
00167 
00168     // given the dimension, assemble the vertices and store in coords and
00169     // moab_ids
00170     ErrorCode assemble_graph( const int dimension, std::vector< double >& coords, std::vector< int >& moab_ids,
00171                               std::vector< int >& adjacencies, std::vector< int >& length, Range& elems,
00172                               bool part_geom = false, const int projection_type = 0 );
00173 
00174 #ifdef MOAB_HAVE_CGM
00175     std::map< int, int > body_vertex_map, surf_vertex_map;
00176 
00177     ErrorCode assemble_graph( const int dimension, std::vector< double >& coords, std::vector< int >& moab_ids,
00178                               std::vector< int >& adjacencies, std::vector< int >& length,
00179                               std::vector< double >& obj_weights, std::vector< double >& edge_weights,
00180                               std::vector< int >& parts, DLIList< RefEntity* >& entities,
00181                               const double part_geom_mesh_size, const int n_part );
00182 
00183     ErrorCode partition_round_robin( const int n_part );
00184 
00185     ErrorCode partition_child_entities( const int dim, const int n_part, const bool partition_surf,
00186                                         const bool ghost = false );
00187 
00188     double estimate_face_mesh_load( RefEntity* face, const double h );
00189     double estimate_face_comm_load( RefEntity* face, const double h );
00190 #endif
00191 
00192     void mbFinalizePoints( int npts, int numExport, ZOLTAN_ID_PTR exportLocalIDs, int* exportProcs, int** assignment );
00193 
00194     int mbInitializePoints( int npts, double* pts, int* ids, int* adjs, int* length, double* obj_weights = NULL,
00195                             double* edge_weights = NULL, int* parts = NULL, bool part_geom = false );
00196 
00197 #ifdef MOAB_HAVE_CGM
00198     GeometryQueryTool* gti;
00199 #endif
00200 };
00201 
00202 inline ErrorCode ZoltanPartitioner::partition_mesh( const int nparts, const char* method, const int part_dim,
00203                                                     const bool write_as_sets, const bool write_as_tags, const bool,
00204                                                     const bool, const char*, const bool print_time )
00205 {
00206     return partition_mesh_and_geometry( -1.0, nparts, method, NULL, 1.03, part_dim, write_as_sets, write_as_tags, 0, 0,
00207                                         false, false, 0, false, print_time );
00208 }
00209 
00210 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines