TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Comm_Group.cpp
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <communications.h>
17#include <Comm_Group.h>
18#include <TRUST_Ref.h>
19#include <PE_Groups.h>
20
21Implemente_base_sans_constructeur_ni_destructeur(Comm_Group,"Comm_Group",Objet_U);
22
23int Comm_Group::check_enabled_ = 0;
24int Comm_Group::static_group_number_ = 0;
25
27{
29 return os;
30}
31
33{
35 return is;
36}
37
39{
40 static const int group_increment = 32;
41
42 // Communication tags are different
43 // for each group as long as there are no more than 32 groups.
44 // Thus, each communication of each group will have a different tag.
45 group_number_ = static_group_number_;
46 group_tag_increment_ = group_increment;
47 static_group_number_++;
48 group_communication_tag_ = group_number_ % group_increment;
49}
50
51/*! @brief Copy constructor is forbidden!
52 *
53 */
55{
56 Cerr << "Comm_Group::Comm_Group(const Comm_Group &) error" << finl;
58}
59
60/*! @brief Assignment is forbidden!
61 *
62 */
64{
66 return *this;
67}
68
69/*! @brief Destructor (nothing to do for now).
70 *
71 */
75
76/*! @brief This function must be called simultaneously by all PEs of the current_group with the same parameters.
77 *
78 * The processors in pe_list are the ranks within current_group() of the processors of the new group.
79 * The master of the group is the first in the list. The rank of the current processor, if it is in
80 * the group, is determined by its position in the list. There must be no duplicates.
81 * This function is called by the init_group methods of derived classes.
82 *
83 */
84void Comm_Group::init_group(const ArrOfInt& pe_list)
85{
86 // All processors in the current group must arrive here
87 const Comm_Group& current = PE_Groups::current_group();
88 current.barrier(0);
89
90 nproc_ = pe_list.size_array();
91 if (nproc_ == 0)
92 {
93 Cerr << "Comm_Group::set_group_properties : empty process list" << finl;
95 }
96 rank_ = -1;
97 const Comm_Group& groupe_trio = PE_Groups::groupe_TRUST();
98 local_ranks_.resize_array(groupe_trio.nproc());
99 local_ranks_ = -1;
100 world_ranks_.resize_array(nproc_);
101
102 for (int i = 0; i < nproc_; i++)
103 {
104 // rank of the pe in current_group()
105 const int pe = pe_list[i], me = Process::me();
106 const bool in_group = std::find(pe_list.begin(), pe_list.end(), me) != pe_list.end();
107
108 if (check_enabled() && nproc_ > 1 && in_group)
109 {
110 if(Process::me() == pe_list[0])
111 {
112 for(int j=1; j < nproc_; j++)
113 envoyer(pe_list[i], Process::me(), pe_list[j], 1);
114 }
115 else
116 {
117 int rcv;
118 recevoir(rcv, pe_list[0], Process::me(), 1);
119 if (rcv != pe_list[i])
120 {
121 Cerr << "Comm_Group::init_group : processes have different pe_lists" << finl;
123 }
124 }
125 }
126 if (pe < 0 || pe >= current.nproc_)
127 {
128 Cerr << "Comm_Group::set_group_properties : process "
129 << pe << " is not in current_group()" << finl;
131 }
132 // rank of the pe in groupe_TRUST
133 const int world_rank = current.world_ranks_[pe];
134
135 if (local_ranks_[world_rank] >= 0)
136 {
137 Cerr << "Comm_Group::set_group_properties : duplicate pe in pe_list" << finl;
139 }
140
141 world_ranks_[i] = world_rank;
142 local_ranks_[world_rank] = i;
143 if (pe == current.rank_)
144 rank_ = i;
145 }
146}
147
148/*! @brief Initializes groupe_TRUST().
149 *
150 * This method is called by init_group_trio() of derived classes.
151 *
152 */
153void Comm_Group::init_group_trio(int nproc_tot, int arank)
154{
155 assert(arank >= 0 && arank < nproc_tot);
156 rank_ = arank;
157 nproc_ = nproc_tot;
158 local_ranks_.resize_array(nproc_);
159 world_ranks_.resize_array(nproc_);
160 for (int i = 0; i < nproc_; i++)
161 {
162 local_ranks_[i] = i;
163 world_ranks_[i] = i;
164 }
165}
166
167/*! @brief Initialize all the information relative to world sizes and ranks for node communicator
168 *
169 * This method is called by derived classes when initializing communicator on node
170 *
171 */
172void Comm_Group::init_group_node(int nproc, int loc_rank, int glob_rank)
173{
174 rank_ = loc_rank;
175 nproc_ = nproc;
176
177 const Comm_Group& groupe_trio = PE_Groups::groupe_TRUST();
178 local_ranks_.resize_array(groupe_trio.nproc());
179 local_ranks_ = -1;
180 groupe_trio.all_gather(&loc_rank, local_ranks_.addr(), (int)sizeof(int));
181
182 world_ranks_.resize_array(nproc_);
183 world_ranks_ = glob_rank;
184 if(nproc_ > 1) // the master of my node is of parallel type but only contains one proc, so can't perform MPI communications with it
185 all_gather(&glob_rank, world_ranks_.data(), (int)sizeof(int));
186}
187
189{
190 if (flag)
191 check_enabled_ = 1;
192 else
193 check_enabled_ = 0;
194}
: This class describes a group of processors on which
Definition Comm_Group.h:37
static int check_enabled()
Definition Comm_Group.h:154
virtual void all_gather(const void *src_buffer, void *dest_buffer, int data_size) const =0
static void set_check_enabled(int flag)
int nproc() const
Returns the number of processors in the group *this.
Definition Comm_Group.h:185
const Comm_Group & operator=(const Comm_Group &)
Assignment is forbidden!
virtual void barrier(int tag) const =0
void init_group_node(int nproc, int loc_rank, int glob_rank)
Initialize all the information relative to world sizes and ranks for node communicator.
virtual void init_group(const ArrOfInt &pe_list)
This function must be called simultaneously by all PEs of the current_group with the same parameters.
~Comm_Group() override
Destructor (nothing to do for now).
void init_group_trio(int nproc, int rank)
Initializes groupe_TRUST().
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static const Comm_Group & current_group()
Returns a reference to the current active processor group.
Definition PE_Groups.h:64
static const Comm_Group & groupe_TRUST()
Returns a reference to the group containing all TRUST processors.
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
Iterator_ end()
Definition TRUSTArray.h:112
_SIZE_ size_array() const
Iterator_ begin()
Definition TRUSTArray.h:111