TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
IJKArray_with_ghost.h
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#ifndef IJKArray_with_ghost_included
17#define IJKArray_with_ghost_included
18
19#include <IJK_communications.h>
20#include <communications.h>
21#include <Domaine_IJK.h>
22#include <Perf_counters.h>
23#include <TRUST_Vector.h>
24#include <TRUSTVect.h>
25#include <Perf_counters.h>
26
27/*! @brief This is an array with [] operator.
28 *
29 * Allocate array with resize(n, ghost). tab[i] is valid for "-ghost <= i < n + ghost"
30 *
31 */
32template<typename _TYPE_, typename _TYPE_ARRAY_>
34{
35protected:
36 unsigned taille_memoire() const override { throw; }
37
38 int duplique() const override
39 {
41 if (!xxx) Process::exit("Not enough memory !");
42 return xxx->numero();
43 }
44
45 Sortie& printOn(Sortie& os) const override { return os; }
46
47 Entree& readOn(Entree& is) override { return is; }
48
49public:
51 void resize(int n, int new_ghost)
52 {
53 tab_.resize_array(n + 2 * new_ghost);
54 ghost_ = new_ghost;
55 }
56 _TYPE_ operator[](int i) const { return tab_[i + ghost_]; }
57 _TYPE_& operator[](int i) { return tab_[i + ghost_]; }
58 const _TYPE_ARRAY_& data() const { return tab_; }
59 int size() const { return tab_.size_array() - 2 * ghost_; }
60 int ghost() const { return ghost_; }
61 inline void echange_espace_virtuel(int pe_min, int pe_max);
62
63protected:
64 _TYPE_ARRAY_ tab_;
65 int ghost_;
66};
67
68using ArrOfFloat_with_ghost = IJKArray_with_ghost<float,ArrOfFloat>;
69using ArrOfDouble_with_ghost = IJKArray_with_ghost<double,ArrOfDouble>;
70
71template<typename _TYPE_, typename _TYPE_ARRAY_>
73{
74 statistics().begin_count(STD_COUNTERS::virtual_swap);
75 // envoi a pe_max et reception de pe_min
76 const int n = tab_.size_array() - ghost_ * 2;
77 _TYPE_ *pdata = tab_.addr();
78 ::envoyer_recevoir(pdata + n, ghost_ * sizeof(_TYPE_), pe_max, pdata, ghost_ * sizeof(_TYPE_), pe_min);
79 // l'autre
80 ::envoyer_recevoir(pdata + ghost_, ghost_ * sizeof(_TYPE_), pe_min, pdata + n + ghost_, ghost_ * sizeof(_TYPE_), pe_max);
81 statistics().end_count(STD_COUNTERS::virtual_swap);
82}
83
84
85#endif /* IJKArray_with_ghost_included */
This is an array with [] operator.
_TYPE_ & operator[](int i)
void resize(int n, int new_ghost)
Entree & readOn(Entree &is) override
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
const _TYPE_ARRAY_ & data() const
Sortie & printOn(Sortie &os) const override
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
unsigned taille_memoire() const override
void echange_espace_virtuel(int pe_min, int pe_max)
_TYPE_ operator[](int i) const
int duplique() const override
friend class Entree
Definition Objet_U.h:76
int numero() const
Renvoie l'indice de l'objet dans Memoire::data.
Definition Objet_U.cpp:268
friend class Sortie
Definition Objet_U.h:75
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455