TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Comm_Group_MPI.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 Comm_Group_MPI_included
17#define Comm_Group_MPI_included
18
19#include <Comm_Group_Noparallel.h>
20#include <TRUST_Ref.h>
21
22class Comm_Group;
23//GF comm_incl inclu mpi.h mais il est plus facile de faire un atelier
24// ou l on change le mpi si on passe par ce fichier intermediaire
25
26#include <comm_incl.h>
27
28/*! @brief : Classe Comm_Group_MPI, derivee de la classe abstraite Comm_Group.
29 *
30 * Cette classe represente un groupe de communication qui repose sur MPI.
31 *
32 * Construction de l'objet : voir init_group_trio() pour le groupe_TRUST
33 * et init_group() pour les autres.
34 *
35 */
37{
38 Declare_instanciable_sans_constructeur_ni_destructeur(Comm_Group_MPI);
39public:
41 ~Comm_Group_MPI() override;
42 void abort() const override;
43
44 void mp_collective_op(const double *x, double *resu, int n, Collective_Op op) const override;
45 void mp_collective_op(const double *x, double *resu, const Collective_Op *op, int n) const override;
46 void mp_collective_op(const float *x, float *resu, int n, Collective_Op op) const override;
47 void mp_collective_op(const float *x, float *resu, const Collective_Op *op, int n) const override;
48 void mp_collective_op(const int *x, int *resu, int n, Collective_Op op) const override;
49 void mp_collective_op(const int *x, int *resu, const Collective_Op *op, int n) const override;
50#if INT_is_64_ == 2
51 void mp_collective_op(const trustIdType *x, trustIdType *resu, int n, Collective_Op op) const override;
52 void mp_collective_op(const trustIdType *x, trustIdType *resu, const Collective_Op *op, int n) const override;
53#endif
54
55 void barrier(int tag) const override;
56 void send_recv_start(const ArrOfInt& send_list,
57 const ArrOfInt& send_size,
58 const char * const * const send_buffers,
59 const ArrOfInt& recv_list,
60 const ArrOfInt& recv_size,
61 char * const * const recv_buffers,
62 TypeHint typehint = CHAR) const override;
63 void send_recv_finish() const override;
64 void send(int pe, const void *buffer, int size, int tag) const override; // Envoi bloquant
65 void recv(int pe, void *buffer, int size, int tag) const override; // Reception bloquante
66 void broadcast(void *buffer, int size, int pe_source) const override;
67 void all_to_all(const void *src_buffer, void *dest_buffer, int data_size) const override;
68 void all_gather(const void *src_buffer, void *dest_buffer, int data_size) const override;
69 void gather(const void *src_buffer, void *dest_buffer, int data_size, int root) const override;
70 void all_gatherv(const void *src_buffer, void *dest_buffer, int send_size, const int* recv_size, const int* displs) const override;
71
72#ifdef MPI_
73 void init_group_trio();
74 void init_comm_on_numa_node();
75 void init_comm_on_node_master();
76 void free();
77 void free_all();
78 void all_to_allv(const void *src_buffer, int *send_data_size, int *send_data_offset,
79 void *dest_buffer, int *recv_data_size, int *recv_data_offset) const;
80 static void set_trio_u_world(MPI_Comm world);
81 static MPI_Comm get_trio_u_world();
82 static void set_must_mpi_initialize(bool flag);
83
84 void ptop_send_recv(const void * send_buf, int send_buf_size, int send_proc,
85 void * recv_buf, int recv_buf_size, int recv_proc) const;
86
87 void set_must_finalize(int flag) { must_finalize_=flag; }
88 MPI_Comm get_mpi_comm() const { return mpi_comm_; }
89protected:
90 void init_group(const ArrOfInt& pe_list) override;
91 void internal_collective(const int *x, int *resu, int nx, const Collective_Op *op, int nop, int level) const;
92#if INT_is_64_ == 2
93 void internal_collective(const trustIdType *x, trustIdType *resu, int nx, const Collective_Op *op, int nop, int level) const;
94#endif
95 void internal_collective(const double *x, double *resu, int nx, const Collective_Op *op, int nop, int level) const;
96 void internal_collective(const float *x, float *resu, int nx, const Collective_Op *op, int nop, int level) const;
97
98private:
99 // TYP_IDX = 1: int, 2: long, 3: double, 4 :float
100 // [ABN] Can not use a MPI datatype directly because in OpenMPI for example this type is too complex to be used as a template parameter.
101 template <typename _TYPE_, int TYP_IDX>
102 void mp_collective_op_template(const _TYPE_ *x, _TYPE_ *resu, int n, Comm_Group::Collective_Op op) const;
103 trustIdType mppartial_sum_impl(trustIdType x) const;
104
105 // Voir set_must_mpi_initialize() et init_group_trio()
106 static bool must_mpi_initialize_;
107 // Le groupe trio_u global est associe a ce communicateur
108 // (different de MPI_COMM_WORLD pour du couplage par exemple)
109 static MPI_Comm trio_u_world_;
110 static MPI_Status * mpi_status_;
111 static MPI_Request * mpi_requests_;
112 static int mpi_nrequests_;
113 static int mpi_maxrequests_;
114 static int current_msg_size_; // La taille des donnees envoyees/recues pour le send_recv_start courant
115
116 MPI_Group mpi_group_;// Handle sur le groupe mpi
117 MPI_Comm mpi_comm_; // Handle sur le communicateur mpi
118
119 int must_finalize_; // Faut-il le faire dans le destructeur ?
120 OBS_PTR(Comm_Group) groupe_pere_;
121#endif
122};
123
124#endif
void recv(int pe, void *buffer, int size, int tag) const override
Reception blocante d'un message.
void all_to_all(const void *src_buffer, void *dest_buffer, int data_size) const override
void all_gather(const void *src_buffer, void *dest_buffer, int data_size) const override
void abort() const override
appel a MPI_Abort et rend la main
void send(int pe, const void *buffer, int size, int tag) const override
Envoi blocant.
void broadcast(void *buffer, int size, int pe_source) const override
void all_gatherv(const void *src_buffer, void *dest_buffer, int send_size, const int *recv_size, const int *displs) const override
~Comm_Group_MPI() override
void send_recv_finish() const override
Attend que l'ensemble des communications lancees par send_recv_start soient finie.
void send_recv_start(const ArrOfInt &send_list, const ArrOfInt &send_size, const char *const *const send_buffers, const ArrOfInt &recv_list, const ArrOfInt &recv_size, char *const *const recv_buffers, TypeHint typehint=CHAR) const override
Demarre l'envoi et la reception des buffers.
Comm_Group_MPI()
Constructeur par defaut.
void gather(const void *src_buffer, void *dest_buffer, int data_size, int root) const override
void mp_collective_op(const double *x, double *resu, int n, Collective_Op op) const override
: Cette classe decrit un groupe de processeurs sur lesquels
Definition Comm_Group.h:40
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...
void init_group_trio(int nproc, int rank)
Initialise le groupe_TRUST().
static void barrier()
Synchronise tous les processeurs du groupe courant (attend que tous les processeurs soient arrives a ...
Definition Process.cpp:136