TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
EcrFicPartage.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 EcrFicPartage_included
17#define EcrFicPartage_included
18
19#include <SFichier.h>
20#include <OBuffer.h>
21#include <Nom.h>
22
23/*! @brief Writing to a shared file. This class implements the operators and virtual methods of the SFichier class as follows:
24 *
25 * A file physically located on the disk of the machine hosting the master task of
26 * the Trio-U application (the process with rank 0 in the "all" group).
27 * Each process writes its data one after the other, in ascending order of rank in the "all" group.
28 * Synchronization is achieved through a semaphore system.
29 * This type of file is notably used for the creation of a single post-processing file.
30 *
31 */
32
33class OBuffer;
34
35// Each PE writes to the same() file
36class EcrFicPartage : public SFichier
37{
38 Declare_instanciable_sans_constructeur_ni_destructeur(EcrFicPartage);
39public:
41 EcrFicPartage(const char* name,IOS_OPEN_MODE mode=ios::out);
42 int ouvrir(const char* name,IOS_OPEN_MODE mode=ios::out) override;
43 ~EcrFicPartage() override;
44 void close();
45 Sortie& lockfile() override;
46 Sortie& unlockfile() override;
47 Sortie& syncfile() override;
48 void precision(int) override;
49 int get_precision() override;
50
51 Sortie& flush() override;
52 void set_bin(bool bin) override;
53 void set_64b(bool is64) override;
54
55 Sortie& operator <<(const char* ob) override;
56 Sortie& operator <<(const Objet_U& ob) override;
57 Sortie& operator <<(const std::string& ob) override;
58 Sortie& operator <<(const Separateur& ) override;
59
60 Sortie& operator <<(const int ob) override;
61 Sortie& operator <<(const unsigned ob) override;
62 Sortie& operator <<(const long ob) override;
63 Sortie& operator <<(const long long ob) override;
64 Sortie& operator <<(const unsigned long ob) override;
65 Sortie& operator <<(const float ob) override;
66 Sortie& operator <<(const double ob) override;
67
68 int put(const unsigned* ob, std::streamsize n, std::streamsize pas) override;
69 int put(const int* ob, std::streamsize n, std::streamsize pas) override;
70 int put(const long* ob, std::streamsize n, std::streamsize pas) override;
71 int put(const long long* ob, std::streamsize n, std::streamsize pas) override;
72 int put(const float* ob, std::streamsize n, std::streamsize pas) override;
73 int put(const double* ob, std::streamsize n, std::streamsize pas) override;
74
75protected:
77
78private:
79 OBuffer& get_obuffer();
80 OBuffer * obuffer_ptr_ = nullptr; // Pointer: avoids including OBuffer.h
81
82 template <typename _TYPE_>
83 int put_template(const _TYPE_* ob, std::streamsize n, std::streamsize pas)
84 {
85 get_obuffer().put(ob,n,pas);
86 return 1;
87 }
88
89 template <typename _TYPE_>
90 Sortie& operator_template(const _TYPE_& ob)
91 {
92 get_obuffer() << ob;
93 return *this;
94 }
95};
96
97#endif /* EcrFicPartage_included */
int put(const unsigned *ob, std::streamsize n, std::streamsize pas) override
int get_precision() override
~EcrFicPartage() override
Closes the file.
Sortie & unlockfile() override
Releases the critical resource for the next process.
Sortie & lockfile() override
Allows the calling process to block waiting for the common resource shared by all processes,...
Sortie & flush() override
void set_bin(bool bin) override
Sortie & operator<<(const char *ob) override
Writes a character string.
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
Sortie & syncfile() override
Triggers writing to disk of the data accumulated on the different processors since the last call to s...
void precision(int) override
void set_64b(bool is64) override
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
friend class Sortie
Definition Objet_U.h:70
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
SFichier(const char *name, IOS_OPEN_MODE mode=ios::out)
Definition SFichier.h:32
Separator for output streams.
Definition Separateur.h:29
Base class for output streams.
Definition Sortie.h:52
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
Definition Sortie.cpp:101