TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
communications.h
1/****************************************************************************
2* Copyright (c) 2026, 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#ifndef communications_included
17#define communications_included
18
19#include <communications_array.h>
20#include <TRUSTTabs_forward.h>
21#include <type_traits>
22#include <vector>
23
24#ifdef MPI_
25#if INT_is_64_ == 1
26#define MPI_ENTIER MPI_LONG
27#else
28#define MPI_ENTIER MPI_INT
29#endif /* INT_is_64_ */
30#endif /* MPI_ */
31
32// Pour Objet_U ... on buffer !!
33bool envoyer(const Objet_U& t, int source, int cible, int canal);
34bool envoyer(const Objet_U& t, int cible, int canal);
35bool recevoir(Objet_U& t, int source, int cible, int canal);
36bool recevoir(Objet_U& t, int source, int canal);
37bool envoyer_broadcast(Objet_U& t, int source);
38
39void assert_parallel(const Objet_U& obj);
40bool is_parallel_object(const Objet_U& obj);
41bool is_parallel_object(const double x);
42bool is_parallel_object(const int x);
43#if INT_is_64_ == 2
44bool is_parallel_object(const trustIdType x);
45#endif
46
47bool envoyer_all_to_all(const TRUST_Vector<TRUSTTab<double>>& src, TRUST_Vector<TRUSTTab<double>>& dest);
48bool envoyer_all_to_all(const TRUST_Vector<TRUSTArray<int>>& src, TRUST_Vector<TRUSTArray<int>>& dest);
49#if INT_is_64_ == 2
50bool envoyer_all_to_all(const TRUST_Vector<TRUSTArray<trustIdType>>& src, TRUST_Vector<TRUSTArray<trustIdType>>& dest);
51#endif
52bool envoyer_all_to_all(std::vector<long long>& src, std::vector<long long>& dest);
53void envoyer_all_to_all(const DoubleTab& src, DoubleTab& dest);
54void envoyer_all_gather(const DoubleTab& src, DoubleTab& dest);
55void envoyer_gather(const IntTab& src, IntTab& dest, int root);
56void envoyer_gather(const DoubleTab& src, DoubleTab& dest, int root);
57void envoyer_all_gather(const IntTab& src, IntTab& dest);
58void envoyer_all_gatherv(const DoubleTab& src, DoubleTab& dest, const IntTab& recv_size);
59
60bool reverse_send_recv_pe_list(const ArrOfInt& src_list, ArrOfInt& dest_list);
61bool comm_check_enabled();
62
63/* ******************************************************************************************************** *
64 * FUNCTION TEMPLATE IMPLEMENTATIONS with SFINAE to avoid substitution failure because now IT IS AN ERROR ! *
65 * ******************************************************************************************************** */
66
67// Pour les types simples, on passe par envoyer_array_ qui n'utilise pas un buffer mais envoie directement les valeurs. Plus rapide.
68// TYPES SIMPLES (std::is_arithmetic) => PAS Objet_U => SFINAE
69template<typename _TYPE_> std::enable_if_t<std::is_arithmetic<_TYPE_>::value,bool >
70inline envoyer(const _TYPE_ t, int source, int cible, int canal)
71{
72 return envoyer_array<_TYPE_>(&t, 1, source, cible, canal);
73}
74
75#ifndef INT_is_64_
76inline bool envoyer(const long t, int source, int cible, int canal) { return envoyer_array<long>(&t, 1, source, cible, canal); }
77#endif
78
79template<typename _TYPE_> std::enable_if_t<std::is_arithmetic<_TYPE_>::value,bool >
80inline envoyer(const _TYPE_ t, int cible, int canal)
81{
82 return envoyer_array<_TYPE_>(&t, 1, Process::me(), cible, canal);
83}
84
85#ifndef INT_is_64_
86inline bool envoyer(const long t, int cible, int canal) { return envoyer_array<long>(&t, 1, Process::me(), cible, canal); }
87#endif
88
89template<typename _TYPE_> std::enable_if_t<std::is_arithmetic<_TYPE_>::value,bool >
90inline recevoir(_TYPE_& t, int source, int cible, int canal)
91{
92 return recevoir_array<_TYPE_>(&t, 1, source, cible, canal);
93}
94
95#ifndef INT_is_64_
96inline bool recevoir(long& t, int source, int cible, int canal) { return recevoir_array<long>(&t, 1, source, cible, canal); }
97#endif
98
99template<typename _TYPE_> std::enable_if_t<std::is_arithmetic<_TYPE_>::value,bool >
100inline recevoir(_TYPE_& t, int source, int canal)
101{
102 return recevoir_array<_TYPE_>(&t, 1, source, Process::me(), canal);
103}
104
105#ifndef INT_is_64_
106inline bool recevoir(long& t, int source, int canal) { return recevoir_array<long>(&t, 1, source, Process::me(), canal); }
107#endif
108
109template<typename _TYPE_> std::enable_if_t<std::is_arithmetic<_TYPE_>::value,bool >
110inline envoyer_broadcast(_TYPE_& t, int source)
111{
112 return envoyer_broadcast_array<_TYPE_>(&t, 1, source);
113}
114
115#ifndef INT_is_64_
116inline bool envoyer_broadcast(long& t, int source) { return envoyer_broadcast_array<long>(&t, 1, source); }
117#endif
118
119/*! @brief en mode comm_check_enabled(), verifie que le parametre a la meme valeur sur tous les processeurs
120 *
121 */
122template<typename _TYPE_> std::enable_if_t<(std::is_arithmetic<_TYPE_>::value),void >
123inline assert_parallel(const _TYPE_ x)
124{
126 return;
127 if (!is_parallel_object(x))
128 {
129 Cerr << "Fatal error in template<typename _TYPE_>assert_parallel(const _TYPE_ x). See log files" << finl;
130 Process::Journal() << "Error in template<typename _TYPE_>assert_parallel(const _TYPE_ x)" << "This processor has this value: " << x << finl;
133 }
134}
135
136/*! @brief On suppose que les tableaux en entree et en sortie sont de taille nproc() .
137 *
138 * On envoie src[0] au proc 0, src[1] au proc 1, etc... la valeur recue du processeur 0 et mise dans dest[0], processeur 1 dans dest[1], etc...
139 * Il est autorise d'appeler la fonction avec le meme tableau src et dest.
140 *
141 */
142template<typename _TYPE_>
143inline bool envoyer_all_to_all(const TRUSTArray<_TYPE_>& src, TRUSTArray<_TYPE_>& dest)
144{
146 assert(src.size_array() == grp.nproc());
147 assert(dest.size_array() == grp.nproc());
148 if (src.data() == dest.data())
149 {
151 tmp.resize_array(grp.nproc(), RESIZE_OPTIONS::NOCOPY_NOINIT);
152 grp.all_to_all(src.data(), tmp.data(), sizeof(_TYPE_));
153 dest.inject_array(tmp);
154 }
155 else
156 grp.all_to_all(src.data(), dest.data(), sizeof(_TYPE_));
157 return true;
158}
159
160#endif /* communications_included */
: Cette classe decrit un groupe de processeurs sur lesquels
Definition Comm_Group.h:40
static int check_enabled()
Definition Comm_Group.h:159
int nproc() const
Renvoie le nombre de processeurs dans le groupe *this.
Definition Comm_Group.h:190
virtual void all_to_all(const void *src_buffer, void *dest_buffer, int data_size) const =0
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
static const Comm_Group & current_group()
renvoie une reference au groupe de processeurs actif courant
Definition PE_Groups.h:65
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
Definition Process.cpp:588
static void barrier()
Synchronise tous les processeurs du groupe courant (attend que tous les processeurs soient arrives a ...
Definition Process.cpp:136
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
Represents a an array of int/int64/double/... values.
Definition TRUSTArray.h:81
_SIZE_ size_array() const
TRUSTArray & inject_array(const TRUSTArray &source, _SIZE_ nb_elements=-1, _SIZE_ first_element_dest=0, _SIZE_ first_element_source=0)
_TYPE_ * data()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
: Tableau a n entrees pour n<= 4.
Definition TRUSTTab.h:31
classe TRUST_Vector