Salome HOME
7db3c60824980ef88e08cf37a73fd03c9ac2a056
[modules/med.git] / src / MEDPartitioner / MEDPARTITIONER_ParaDomainSelector.hxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __MEDPARTITIONER_PARADOMAINSELECTOR_HXX__
21 #define __MEDPARTITIONER_PARADOMAINSELECTOR_HXX__
22
23 #include "MEDPARTITIONER.hxx"
24
25 #include <memory>
26 #include <vector>
27
28 namespace ParaMEDMEM
29 {
30   class MEDCouplingUMesh;
31 }
32
33 namespace MEDPARTITIONER
34 {
35   class Graph;
36   class JointExchangeData;
37
38   /*!
39    * \brief Communication helper in parallel mode
40    */
41   class MEDPARTITIONER_EXPORT ParaDomainSelector
42   {
43   public:
44     ParaDomainSelector(bool mesure_memory=false);
45     ~ParaDomainSelector();
46
47     //processor rank
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;
61   
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(); };
65
66     //Collect nb of entities on procs
67     void gatherNbOf(const std::vector<ParaMEDMEM::MEDCouplingUMesh*>& domain_meshes);
68   
69     //distribution of the graph vertices among the processors
70     int* getProcVtxdist() const;
71
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;
78
79     //Gather graphs from all processors into one
80     std::auto_ptr<Graph> gatherGraph(const Graph* graph) const;
81
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;
88
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;
96
97     //Evaluate current memory usage and return the maximal one in KB
98     int evaluateMemory() const;
99
100     void sendMesh(const ParaMEDMEM::MEDCouplingUMesh& mesh, int target) const;
101     void recvMesh(ParaMEDMEM::MEDCouplingUMesh*& mesh, int source) const;
102   private:
103     int _rank; //my rank
104     int _world_size; //nb of processors
105     int _nb_result_domains; //required nb of domains
106
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;
112
113     double _init_time;
114     bool _mesure_memory;
115     mutable int _init_memory;
116     mutable int _max_memory;
117   };
118 }
119 #endif