1 // Copyright (C) 2007-2023 CEA, EDF
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.
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"
31 class MEDCouplingUMesh;
34 namespace MEDPARTITIONER
37 class JointExchangeData;
40 * \brief Communication helper in parallel mode
42 class MEDPARTITIONER_EXPORT ParaDomainSelector
45 ParaDomainSelector(bool mesure_memory=false);
46 ~ParaDomainSelector();
49 int rank() const { return _rank; }
50 //number of processors
51 int nbProcs() const { return _world_size; }
52 //true if is running on different hosts
53 bool isOnDifferentHosts() const;
54 //true if the domain with domainIndex is to be loaded on this proc
55 bool isMyDomain(int domainIndex) const;
56 //processor id where the domain with domainIndex resides
57 int getProcessorID(int domainIndex) const;
58 //Set nb of required domains. (Used to sort joints via jointId())
59 void setNbDomains(int nb) { _nb_result_domains = nb; }
60 //identifier for a joint
61 int jointId( int local_domain, int distant_domain ) const;
63 mcIdType getNbTotalCells() { return _cell_shift_by_domain.back(); }
64 mcIdType getNbTotalNodes() { return _node_shift_by_domain.back(); };
65 mcIdType getNbTotalFaces() { return _face_shift_by_domain.back(); };
67 //Collect nb of entities on procs
68 void gatherNbOf(const std::vector<MEDCoupling::MEDCouplingUMesh*>& domain_meshes);
70 //distribution of the graph vertices among the processors
71 mcIdType* getProcVtxdist() const;
73 //nb of nodes on processors with lower rank
74 mcIdType getProcNodeShift() const;
75 //nb of cells in domains with lower index
76 mcIdType getDomainCellShift(int domainIndex) const;
77 //nb of nodes in domains with lower index
78 mcIdType getDomainNodeShift(int domainIndex) const;
80 //Gather graphs from all processors into one
81 std::unique_ptr<Graph> gatherGraph(const Graph* graph) const;
83 //Set nb of cell/cell pairs in a joint between domains
84 void setNbCellPairs( mcIdType nb_cell_pairs, int dist_domain, int loc_domain );
85 //Gather size of each proc/proc joint
86 void gatherNbCellPairs();
87 //nb of cell/cell pairs in a joint between domains on different procs
88 mcIdType getNbCellPairs( int dist_domain, int loc_domain ) const;
90 //get the first global id of sub-entity for the joint
91 mcIdType getFisrtGlobalIdOfSubentity( int loc_domain, int dist_domain ) const;
92 //Send-receive local ids of joint faces
93 int* exchangeSubentityIds( int loc_domain, int dist_domain,
94 const std::vector<int>& loc_ids_here ) const;
95 //time passed from construction in seconds
96 double getPassedTime() const;
98 //Evaluate current memory usage and return the maximal one in KB
99 int evaluateMemory() const;
101 void sendMesh(const MEDCoupling::MEDCouplingUMesh& mesh, int target) const;
102 void recvMesh(MEDCoupling::MEDCouplingUMesh*& mesh, int source) const;
105 int _world_size; //nb of processors
106 int _nb_result_domains; //required nb of domains
108 std::vector< mcIdType > _nb_cell_pairs_by_joint;
109 std::vector< mcIdType > _nb_vert_of_procs; //graph vertices
110 std::vector< mcIdType > _cell_shift_by_domain;
111 std::vector< mcIdType > _node_shift_by_domain;
112 std::vector< mcIdType > _face_shift_by_domain;
116 mutable int _init_memory;
117 mutable int _max_memory;