TRUST 1.9.8
HPC thermohydraulic platform
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 // Les tags des communications sont differents
43 // pour chaque groupe tant qu'il n'y a pas plus de 32 groupes.
44 // Ainsi, chaque communication de chaque groupe aura un tag different.
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 Le constructeur par copie est interdit !
52 *
53 */
55{
56 Cerr << "Comm_Group::Comm_Group(const Comm_Group &) error" << finl;
58}
59
60/*! @brief La copie est interdite !
61 *
62 */
64{
66 return *this;
67}
68
69/*! @brief Destructeur (pour l'instant, rien a faire)
70 *
71 */
75
76/*! @brief Cette fonction doit etre appelee simultanement par tous les PEs du groupe current_group avec les memes parametres.
77 *
78 * Les processeurs de la pe_list sont les rangs dans current_group() des
79 * processeurs du nouveau groupe. Le maitre du groupe est le premier de la liste,
80 * le rang du processeur courant, s'il est dans le groupe est determine par
81 * son rang dans la liste. Il ne doit pas y avoir de doublon.
82 * Cette fonction est appelee par les methodes init_group des classes derivees.
83 *
84 */
85void Comm_Group::init_group(const ArrOfInt& pe_list)
86{
87 // Tous les processeurs du groupe courant doivent arriver ici
88 const Comm_Group& current = PE_Groups::current_group();
89 current.barrier(0);
90
91 nproc_ = pe_list.size_array();
92 if (nproc_ == 0)
93 {
94 Cerr << "Comm_Group::set_group_properties : empty process list" << finl;
96 }
97 rank_ = -1;
98 const Comm_Group& groupe_trio = PE_Groups::groupe_TRUST();
99 local_ranks_.resize_array(groupe_trio.nproc());
100 local_ranks_ = -1;
101 world_ranks_.resize_array(nproc_);
102
103 for (int i = 0; i < nproc_; i++)
104 {
105 // rank du pe dans current_group()
106 const int pe = pe_list[i], me = Process::me();
107 const bool in_group = std::find(pe_list.begin(), pe_list.end(), me) != pe_list.end();
108
109 if (check_enabled() && nproc_ > 1 && in_group)
110 {
111 if(Process::me() == pe_list[0])
112 {
113 for(int j=1; j < nproc_; j++)
114 envoyer(pe_list[i], Process::me(), pe_list[j], 1);
115 }
116 else
117 {
118 int rcv;
119 recevoir(rcv, pe_list[0], Process::me(), 1);
120 if (rcv != pe_list[i])
121 {
122 Cerr << "Comm_Group::init_group : processes have different pe_lists" << finl;
124 }
125 }
126 }
127 if (pe < 0 || pe >= current.nproc_)
128 {
129 Cerr << "Comm_Group::set_group_properties : process "
130 << pe << " is not in current_group()" << finl;
132 }
133 // rank du pe dans le groupe_TRUST
134 const int world_rank = current.world_ranks_[pe];
135
136 if (local_ranks_[world_rank] >= 0)
137 {
138 Cerr << "Comm_Group::set_group_properties : duplicate pe in pe_list" << finl;
140 }
141
142 world_ranks_[i] = world_rank;
143 local_ranks_[world_rank] = i;
144 if (pe == current.rank_)
145 rank_ = i;
146 }
147}
148
149/*! @brief Initialise le groupe_TRUST().
150 *
151 * Cette methode est appelee par init_group_trio() des classes derivees
152 *
153 */
154void Comm_Group::init_group_trio(int nproc_tot, int arank)
155{
156 assert(arank >= 0 && arank < nproc_tot);
157 rank_ = arank;
158 nproc_ = nproc_tot;
159 local_ranks_.resize_array(nproc_);
160 world_ranks_.resize_array(nproc_);
161 for (int i = 0; i < nproc_; i++)
162 {
163 local_ranks_[i] = i;
164 world_ranks_[i] = i;
165 }
166}
167
168/*! @brief Initialize all the information relative to world sizes and ranks for node communicator
169 *
170 * This method is called by derived classes when initializing communicator on node
171 *
172 */
173void Comm_Group::init_group_node(int nproc, int loc_rank, int glob_rank)
174{
175 rank_ = loc_rank;
176 nproc_ = nproc;
177
178 const Comm_Group& groupe_trio = PE_Groups::groupe_TRUST();
179 local_ranks_.resize_array(groupe_trio.nproc());
180 local_ranks_ = -1;
181 groupe_trio.all_gather(&loc_rank, local_ranks_.addr(), (int)sizeof(int));
182
183 world_ranks_.resize_array(nproc_);
184 world_ranks_ = glob_rank;
185 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
186 all_gather(&glob_rank, world_ranks_.data(), (int)sizeof(int));
187}
188
190{
191 if (flag)
192 check_enabled_ = 1;
193 else
194 check_enabled_ = 0;
195}
: Cette classe decrit un groupe de processeurs sur lesquels
Definition Comm_Group.h:40
static int check_enabled()
Definition Comm_Group.h:159
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
Renvoie le nombre de processeurs dans le groupe *this.
Definition Comm_Group.h:190
const Comm_Group & operator=(const Comm_Group &)
La copie est interdite !
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)
Cette fonction doit etre appelee simultanement par tous les PEs du groupe current_group avec les meme...
~Comm_Group() override
Destructeur (pour l'instant, rien a faire).
void init_group_trio(int nproc, int rank)
Initialise le groupe_TRUST().
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static const Comm_Group & current_group()
renvoie une reference au groupe de processeurs actif courant
Definition PE_Groups.h:65
static const Comm_Group & groupe_TRUST()
Renvoie une reference au groupe de tous les processeurs TRUST.
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
Iterator_ end()
Definition TRUSTArray.h:112
_SIZE_ size_array() const
Iterator_ begin()
Definition TRUSTArray.h:111