TrioCFD 1.9.9_beta
TrioCFD documentation
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 includes mpi.h but it is easier to create a workshop
24// where one can change the MPI implementation by going through this intermediate file
25
26#include <comm_incl.h>
27
28/*! @brief : Class Comm_Group_MPI, derived from the abstract class Comm_Group.
29 *
30 * This class represents a communication group based on MPI.
31 *
32 * Object construction: see init_group_trio() for groupe_TRUST
33 * and init_group() for the others.
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; // Blocking send
65 void recv(int pe, void *buffer, int size, int tag) const override; // Blocking receive
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 // See set_must_mpi_initialize() and init_group_trio()
106 static bool must_mpi_initialize_;
107 // The global trio_u group is associated with this communicator
108 // (different from MPI_COMM_WORLD for coupling for example)
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_; // The size of data sent/received for the current send_recv_start
115
116 MPI_Group mpi_group_;// Handle on the MPI group
117 MPI_Comm mpi_comm_; // Handle on the MPI communicator
118
119 int must_finalize_; // Should it be done in the destructor?
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
Blocking reception of a 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
Calls MPI_Abort and returns.
void send(int pe, const void *buffer, int size, int tag) const override
Blocking send.
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
Waits until all communications started by send_recv_start are finished.
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
Starts sending and receiving buffers.
Comm_Group_MPI()
Default constructor.
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
: This class describes a group of processors on which
Definition Comm_Group.h:37
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.
void init_group_trio(int nproc, int rank)
Initializes groupe_TRUST().
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
Definition Process.cpp:133