1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDPARTITIONER_PARADOMAINSELECTOR_HXX__
21 #define __MEDPARTITIONER_PARADOMAINSELECTOR_HXX__
23 #include "MEDPARTITIONER.hxx"
30 class MEDCouplingUMesh;
33 namespace MEDPARTITIONER
36 class JointExchangeData;
39 * \brief Communication helper in parallel mode
41 class MEDPARTITIONER_EXPORT ParaDomainSelector
44 ParaDomainSelector(bool mesure_memory=false);
45 ~ParaDomainSelector();
48 int rank() const { return _rank; }
49 //number of processors
50 int nbProcs() const { return _world_size; }
51 //true if is running on different hosts
52 bool isOnDifferentHosts() const;
53 //true if the domain with domainIndex is to be loaded on this proc
54 bool isMyDomain(int domainIndex) const;
55 //processor id where the domain with domainIndex resides
56 int getProcessorID(int domainIndex) const;
57 //Set nb of required domains. (Used to sort joints via jointId())
58 void setNbDomains(int nb) { _nb_result_domains = nb; }
59 //identifier for a joint
60 int jointId( int local_domain, int distant_domain ) const;
62 int getNbTotalCells() { return _cell_shift_by_domain.back(); }
63 int getNbTotalNodes() { return _node_shift_by_domain.back(); };
64 int getNbTotalFaces() { return _face_shift_by_domain.back(); };
66 //Collect nb of entities on procs
67 void gatherNbOf(const std::vector<ParaMEDMEM::MEDCouplingUMesh*>& domain_meshes);
69 //distribution of the graph vertices among the processors
70 int* getProcVtxdist() const;
72 //nb of nodes on processors with lower rank
73 int getProcNodeShift() const;
74 //nb of cells in domains with lower index
75 int getDomainCellShift(int domainIndex) const;
76 //nb of nodes in domains with lower index
77 int getDomainNodeShift(int domainIndex) const;
79 //Gather graphs from all processors into one
80 std::auto_ptr<Graph> gatherGraph(const Graph* graph) const;
82 //Set nb of cell/cell pairs in a joint between domains
83 void setNbCellPairs( int nb_cell_pairs, int dist_domain, int loc_domain );
84 //Gather size of each proc/proc joint
85 void gatherNbCellPairs();
86 //nb of cell/cell pairs in a joint between domains on different procs
87 int getNbCellPairs( int dist_domain, int loc_domain ) const;
89 //get the first global id of sub-entity for the joint
90 int getFisrtGlobalIdOfSubentity( int loc_domain, int dist_domain ) const;
91 //Send-receive local ids of joint faces
92 int* exchangeSubentityIds( int loc_domain, int dist_domain,
93 const std::vector<int>& loc_ids_here ) const;
94 //time passed from construction in seconds
95 double getPassedTime() const;
97 //Evaluate current memory usage and return the maximal one in KB
98 int evaluateMemory() const;
100 void sendMesh(const ParaMEDMEM::MEDCouplingUMesh& mesh, int target) const;
101 void recvMesh(ParaMEDMEM::MEDCouplingUMesh*& mesh, int source) const;
104 int _world_size; //nb of processors
105 int _nb_result_domains; //required nb of domains
107 std::vector< int > _nb_cell_pairs_by_joint;
108 std::vector< int > _nb_vert_of_procs; //graph vertices
109 std::vector< int > _cell_shift_by_domain;
110 std::vector< int > _node_shift_by_domain;
111 std::vector< int > _face_shift_by_domain;
115 mutable int _init_memory;
116 mutable int _max_memory;