Back to index

salome-med  6.5.0
MEDPARTITIONER_ParaDomainSelector.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __MEDPARTITIONER_PARADOMAINSELECTOR_HXX__
00021 #define __MEDPARTITIONER_PARADOMAINSELECTOR_HXX__
00022 
00023 #include "MEDPARTITIONER.hxx"
00024 
00025 #include <memory>
00026 #include <vector>
00027 
00028 namespace ParaMEDMEM
00029 {
00030   class MEDCouplingUMesh;
00031 }
00032 
00033 namespace MEDPARTITIONER
00034 {
00035   class Graph;
00036   class JointExchangeData;
00037 
00041   class MEDPARTITIONER_EXPORT ParaDomainSelector
00042   {
00043   public:
00044     ParaDomainSelector(bool mesure_memory=false);
00045     ~ParaDomainSelector();
00046 
00047     //processor rank
00048     int rank() const { return _rank; }
00049     //number of processors
00050     int nbProcs() const { return _world_size; }
00051     //true if is running on different hosts
00052     bool isOnDifferentHosts() const;
00053     //true if the domain with domainIndex is to be loaded on this proc
00054     bool isMyDomain(int domainIndex) const;
00055     //processor id where the domain with domainIndex resides
00056     int getProcessorID(int domainIndex) const;
00057     //Set nb of required domains. (Used to sort joints via jointId())
00058     void setNbDomains(int nb) { _nb_result_domains = nb; }
00059     //identifier for a joint
00060     int jointId( int local_domain, int distant_domain ) const;
00061   
00062     int getNbTotalCells() { return _cell_shift_by_domain.back(); }
00063     int getNbTotalNodes() { return _node_shift_by_domain.back(); };
00064     int getNbTotalFaces() { return _face_shift_by_domain.back(); };
00065 
00066     //Collect nb of entities on procs
00067     void gatherNbOf(const std::vector<ParaMEDMEM::MEDCouplingUMesh*>& domain_meshes);
00068   
00069     //distribution of the graph vertices among the processors
00070     int* getProcVtxdist() const;
00071 
00072     //nb of nodes on processors with lower rank
00073     int getProcNodeShift() const;
00074     //nb of cells in domains with lower index
00075     int getDomainCellShift(int domainIndex) const;
00076     //nb of nodes in domains with lower index
00077     int getDomainNodeShift(int domainIndex) const;
00078 
00079     //Gather graphs from all processors into one
00080     std::auto_ptr<Graph> gatherGraph(const Graph* graph) const;
00081 
00082     //Set nb of cell/cell pairs in a joint between domains
00083     void setNbCellPairs( int nb_cell_pairs, int dist_domain, int loc_domain );
00084     //Gather size of each proc/proc joint
00085     void gatherNbCellPairs();
00086     //nb of cell/cell pairs in a joint between domains on different procs
00087     int getNbCellPairs( int dist_domain, int loc_domain ) const;
00088 
00089     //get the first global id of sub-entity for the joint
00090     int getFisrtGlobalIdOfSubentity( int loc_domain, int dist_domain ) const;
00091     //Send-receive local ids of joint faces
00092     int* exchangeSubentityIds( int loc_domain, int dist_domain,
00093                                const std::vector<int>& loc_ids_here ) const;
00094     //time passed from construction in seconds
00095     double getPassedTime() const;
00096 
00097     //Evaluate current memory usage and return the maximal one in KB
00098     int evaluateMemory() const;
00099 
00100     void sendMesh(const ParaMEDMEM::MEDCouplingUMesh& mesh, int target) const;
00101     void recvMesh(ParaMEDMEM::MEDCouplingUMesh*& mesh, int source) const;
00102   private:
00103     int _rank; //my rank
00104     int _world_size; //nb of processors
00105     int _nb_result_domains; //required nb of domains
00106 
00107     std::vector< int > _nb_cell_pairs_by_joint;
00108     std::vector< int > _nb_vert_of_procs; //graph vertices
00109     std::vector< int > _cell_shift_by_domain;
00110     std::vector< int > _node_shift_by_domain;
00111     std::vector< int > _face_shift_by_domain;
00112 
00113     double _init_time;
00114     bool _mesure_memory;
00115     mutable int _init_memory;
00116     mutable int _max_memory;
00117   };
00118 }
00119 #endif