TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
MD_Vector_std.h
1/****************************************************************************
2* Copyright (c) 2024, 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 MD_Vector_std_included
17#define MD_Vector_std_included
18
19#include <MD_Vector_mono.h>
20#include <Schema_Comm_Vecteurs.h>
21#include <Schema_Comm.h>
22#include <Echange_EV_Options.h>
23#include <Static_Int_Lists.h>
24#include <communications.h>
25#include <TRUSTArrays.h>
26#include <TRUSTVect.h>
27#include <ArrOfBit.h>
28
29/*! @brief This is the simplest descriptor, used for arrays of values at vertices, elements, faces, edges, boundary faces, etc.
30 *
31 * ..
32 * It supports the notion of "shared" items (mesh vertices shared among multiple processors)
33 * and "distant" and "virtual" items (vertices, elements in the ghost layer).
34 *
35 * @sa MD_Vector_composite (descriptor composed of a union of several descriptors, for P1Bulle
36 * for example)
37 *
38 */
40{
41 Declare_instanciable(MD_Vector_std);
42
43public:
44 MD_Vector_std(int n); // Simple ctor for SIDES
45 MD_Vector_std(int nb_items_tot, int nb_items_reels, const ArrOfInt& pe_voisins,
46 const ArrsOfInt& items_to_send, const ArrsOfInt& items_to_recv, const ArrsOfInt& blocs_to_recv);
47
48 inline void initialize_comm(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, DoubleVect& v) const override { initialize_comm_template<double>(opt,sc,v); }
49 inline void prepare_send_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, DoubleVect& v) const override { prepare_send_data_template<double>(opt,sc,v); }
50 inline void process_recv_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, DoubleVect& v) const override { process_recv_data_template<double>(opt,sc,v); }
51
52 inline void initialize_comm(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, FloatVect& v) const override { initialize_comm_template<float>(opt,sc,v); }
53 inline void prepare_send_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, FloatVect& v) const override { prepare_send_data_template<float>(opt,sc,v); }
54 inline void process_recv_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, FloatVect& v) const override { process_recv_data_template<float>(opt,sc,v); }
55
56 inline void initialize_comm(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, IntVect& v) const override { initialize_comm_template<int>(opt,sc,v); }
57 inline void prepare_send_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, IntVect& v) const override { prepare_send_data_template<int>(opt,sc,v); }
58 inline void process_recv_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, IntVect& v) const override { process_recv_data_template<int>(opt,sc,v); }
59
60#if INT_is_64_ == 2
61 inline void initialize_comm(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, TIDVect& v) const override { initialize_comm_template<trustIdType>(opt,sc,v); }
62 inline void prepare_send_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, TIDVect& v) const override { prepare_send_data_template<trustIdType>(opt,sc,v); }
63 inline void process_recv_data(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& sc, TIDVect& v) const override { process_recv_data_template<trustIdType>(opt,sc,v); }
64#endif
65
66 inline const ArrOfInt& pe_voisins() const { return pe_voisins_; }
67 inline const Static_Int_Lists& items_to_send() const { return items_to_send_; }
68 inline const Static_Int_Lists& items_to_recv() const { return items_to_recv_; }
69 inline const Static_Int_Lists& blocs_to_recv() const { return blocs_to_recv_; }
70
71 void append_from_other_std(const MD_Vector_std& src, int offset, int multiplier) override;
72 void fill_md_vect_renum(const IntVect& renum, MD_Vector& md_vect) const override;
73
74 bool use_blocks() const override { return true; }
75
76protected:
77
78 // Indices of neighbouring processors with whom I exchange data (same size as the following VECTs)
79 ArrOfInt pe_voisins_;
80 // Indices of individual items to send to each neighbour (one list per neighbouring processor)
81 // The lists contain both the shared items to send and the "distant" items that will be
82 // stored in the virtual spaces. The first items in this list correspond to "items_to_recv_"
83 // on the neighbouring processor, the following items to "blocs_to_recv_".
84 Static_Int_Lists items_to_send_;
85 // Among the items to send, how many on each processor will be received in "items_to_recv_"? (the following are received in blocs_to_recv_)
87 // Indices of individual items to receive from each neighbour (in principle, these are the shared items received, rarely contiguous in the arrays)
88 Static_Int_Lists items_to_recv_;
89 // Blocks of items to receive
90 // Each list contains start_bloc1, end_bloc1, start_bloc2, end_bloc2, etc... note that end_bloc is the index of the last element + 1
91 // In principle these are the virtual items, which are often contiguous in the arrays.
92 Static_Int_Lists blocs_to_recv_;
93 // To speed up buffer size computation, total number of items mentioned in blocs_to_recv_ for each processor (equal to the sum of end_bloc-start_bloc)
95
96private:
97 template <typename _TYPE_>
98 void initialize_comm_template(const Echange_EV_Options& opt, Schema_Comm_Vecteurs&, TRUSTVect<_TYPE_>&) const;
99
100 template <typename _TYPE_>
101 void prepare_send_data_template(const Echange_EV_Options& opt, Schema_Comm_Vecteurs&, TRUSTVect<_TYPE_>&) const;
102
103 template <typename _TYPE_>
104 void process_recv_data_template(const Echange_EV_Options& opt, Schema_Comm_Vecteurs&, TRUSTVect<_TYPE_>&) const;
105};
106
107#include <MD_Vector_std_tools.tpp>
108
109template<typename _TYPE_>
110void MD_Vector_std::initialize_comm_template(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& comm_, TRUSTVect<_TYPE_>& v) const
111{
112 const int reverse = (opt.get_op() != Echange_EV_Options::SYNC);
113 const int have_items_to_recv = (items_to_recv_.get_data().size_array() > 0);
114 const int have_blocs_to_recv = (blocs_to_recv_.get_data().size_array() > 0);
115 const int nprocs = pe_voisins_.size_array();
116 for (int i = 0; i < nprocs; i++)
117 {
118 const int pe = pe_voisins_[i];
119 int sz1 = items_to_send_.get_list_size(i), sz2 = 0;
120
121 if (have_items_to_recv) sz2 = items_to_recv_.get_list_size(i);
122 if (have_blocs_to_recv) sz2 += blocs_items_count_[i];
123 if (reverse)
124 {
125 // Reverse scheme: read from items to recv, write to items to send
126 int tmp = sz1;
127 sz1 = sz2;
128 sz2 = tmp;
129 }
130 comm_.add_send_area_template < _TYPE_ > (pe, sz1 * v.line_size());
131 comm_.add_recv_area_template < _TYPE_ > (pe, sz2 * v.line_size());
132 }
133}
134
135/*! @brief This is the first part of the echange_espace_virtuel() process.
136 *
137 * We take the data that has to be sent to other processors in "vect" and put it in appropriate send buffers in "buffers". The data taken depends on "opt".
138 * Preconditon: The buffers must have been initialized to the appropriate size and neighbour processors.
139 *
140 */
141template<typename _TYPE_>
142void MD_Vector_std::prepare_send_data_template(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& buffers, TRUSTVect<_TYPE_>& vect) const
143{
144 const int line_size = vect.line_size();
145 switch(opt.get_op())
146 {
148 read_from_vect_items(line_size, pe_voisins_, items_to_send_, vect, buffers);
149 break;
153 if (items_to_recv_.get_data().size_array() > 0)
154 read_from_vect_items(line_size, pe_voisins_, items_to_recv_, vect, buffers);
155 if (blocs_to_recv_.get_data().size_array() > 0)
156 read_from_vect_blocs(line_size, pe_voisins_, blocs_to_recv_, blocs_items_count_, vect, buffers);
157 break;
158 default:
159 Cerr << "Error in MD_Vector_std.tpp prepare_send_data_template : operation not implemented" << finl;
161 }
162}
163
164template<typename _TYPE_>
165void MD_Vector_std::process_recv_data_template(const Echange_EV_Options& opt, Schema_Comm_Vecteurs& buffers, TRUSTVect<_TYPE_>& vect) const
166{
167 const int line_size = vect.line_size();
168 switch(opt.get_op())
169 {
171 if (items_to_recv_.get_data().size_array() > 0)
172 write_to_vect_items(line_size, pe_voisins_, items_to_recv_, vect, buffers);
173 if (blocs_to_recv_.get_data().size_array() > 0)
174 write_to_vect_blocs(line_size, pe_voisins_, blocs_to_recv_, blocs_items_count_, vect, buffers);
175 break;
177 add_to_vect_items(line_size, pe_voisins_, items_to_send_, vect, buffers);
178 break;
180 max_to_vect_items(line_size, pe_voisins_, items_to_send_, vect, buffers);
181 break;
183 mincol1_to_vect_items(line_size, pe_voisins_, items_to_send_, vect, buffers);
184 break;
185 default:
186 Cerr << "Error in MD_Vector_std.tpp process_recv_data_template : operation not implemented" << finl;
188 }
189}
190
191#endif /* MD_Vector_std_included */
Operation get_op() const
Generic class for all mono-block MD_Vectors (i.e. non compoosite).
This is the simplest descriptor, used for arrays of values at vertices, elements, faces,...
void prepare_send_data(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, DoubleVect &v) const override
Static_Int_Lists items_to_send_
void process_recv_data(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, DoubleVect &v) const override
ArrOfInt blocs_items_count_
void initialize_comm(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, DoubleVect &v) const override
const Static_Int_Lists & items_to_recv() const
ArrOfInt pe_voisins_
void fill_md_vect_renum(const IntVect &renum, MD_Vector &md_vect) const override
void process_recv_data(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, FloatVect &v) const override
void initialize_comm(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, FloatVect &v) const override
const ArrOfInt & pe_voisins() const
Static_Int_Lists items_to_recv_
MD_Vector_std(int n)
Stupid ctor.
const Static_Int_Lists & items_to_send() const
bool use_blocks() const override
void prepare_send_data(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, IntVect &v) const override
void prepare_send_data(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, FloatVect &v) const override
void initialize_comm(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, IntVect &v) const override
void process_recv_data(const Echange_EV_Options &opt, Schema_Comm_Vecteurs &sc, IntVect &v) const override
const Static_Int_Lists & blocs_to_recv() const
void append_from_other_std(const MD_Vector_std &src, int offset, int multiplier) override
Static_Int_Lists blocs_to_recv_
ArrOfInt nb_items_to_items_
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
void add_send_area_template(int pe, int size)
void add_recv_area_template(int pe, int size)
int_t get_list_size(int_t i_liste) const
Returns the number of elements in list i.
const ArrOfInt_t & get_data() const
_SIZE_ size_array() const
int line_size() const
Definition TRUSTVect.tpp:67