Salome HOME
[bos #38048] [EDF] (2023-T3) PARAMEDMEM Ergonomy.
[tools/medcoupling.git] / src / ParaMEDMEM / ProcessorGroup.hxx
1 // Copyright (C) 2007-2024  CEA, EDF
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 __PROCESSORGROUP_HXX__
21 #define __PROCESSORGROUP_HXX__
22
23 #include "CommInterface.hxx"
24
25 #include <set>
26
27 namespace MEDCoupling
28 {
29   /*!
30    * Abstract class defining a group of processors (computation nodes) in a parallel run of a code.
31    *
32    * See the non-abstract child \ref MPIProcessorGroup-det "MPIProcessorGroup"
33    */
34   class ProcessorGroup
35   {
36   public:
37   
38     ProcessorGroup(const CommInterface& interface):_comm_interface(interface) { }
39     ProcessorGroup(const CommInterface& interface, std::set<int> proc_ids):
40       _comm_interface(interface),_proc_ids(proc_ids) { }
41     ProcessorGroup (const ProcessorGroup& proc_group, std::set<int> proc_ids):
42       _comm_interface(proc_group.getCommInterface()),_proc_ids(proc_ids) { }
43     ProcessorGroup (const ProcessorGroup& other):
44       _comm_interface(other.getCommInterface()),_proc_ids(other._proc_ids) { }
45     ProcessorGroup (const CommInterface& interface, int start, int end);
46     ProcessorGroup(const CommInterface& interface,std::map<std::string,std::set<int>> proc_ids_by_name,const std::string& simCodeTag):
47       _comm_interface(interface),_proc_ids_by_name(proc_ids_by_name),_proc_ids(proc_ids_by_name.at(simCodeTag)) { }
48     virtual ~ProcessorGroup() { }
49     virtual ProcessorGroup *deepCopy() const = 0;
50     virtual ProcessorGroup* fuse (const ProcessorGroup&) const = 0;
51     virtual void intersect (ProcessorGroup&) = 0;
52     bool contains(int rank) const { return _proc_ids.find(rank)!=_proc_ids.end(); }
53     virtual bool containsMyRank() const = 0;
54     int size() const  { return (int)_proc_ids.size(); }
55     const CommInterface& getCommInterface()const { return _comm_interface; }
56     virtual int myRank() const = 0;
57     virtual int translateRank(const ProcessorGroup*, int) const = 0;
58     virtual ProcessorGroup* createComplementProcGroup() const = 0;
59     virtual ProcessorGroup* createProcGroup() const = 0;
60     virtual const std::set<int>& getProcIDs()const  { return _proc_ids; }
61     virtual const std::set<int>& getProcIDsByName( const std::string& simCodeTag ) const { return _proc_ids_by_name.at(simCodeTag); }
62   protected:
63     const CommInterface _comm_interface;
64     std::map<std::string,std::set<int>> _proc_ids_by_name;
65     std::set<int> _proc_ids;
66   };
67 }
68
69 #endif