IOSS 2.0

Ioss_SerializeIO.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef IOSS_Ioss_SerializeIO_h
33 #define IOSS_Ioss_SerializeIO_h
34
35 #include <Ioss_CodeTypes.h>
36
37 namespace Ioss {
38 class DatabaseIO;
39 } // namespace Ioss
40
41 namespace Ioss {
42
43 /**
44 * @brief Class <code>SerializeIO</code> is a sentry class which performs serialization
45 * for mesh database I/O.
46 *
47 * This sentry guards serialization of parallel I/O routines. At construction, it
48 * blocks the processes via an MPI barrier, releasing them to execute in groups specified
49 * by <code>s_groupSize</code>. At destruction, it continues to block via MPI barriers
50 * until all the processor have been released by the constructor.
51 *
52 * In the case where the constructor is called, and the sentry is already active and owned
53 * by the processes group, the constructor and destrutor simply fall through since the
54 * serialization is already in place at a higher level.
55 *
56 * The MPI
57 *
58 */
59 class SerializeIO
60 {
61 public:
62 /**
63 * Creates a new <code>SerializeIO</code> instance.
64 *
65 * @param database_io a <code>DatabaseIO</code> variable ...
66 */
67 explicit SerializeIO(const DatabaseIO *database_io, int manual_owner_processor = -1);
68 SerializeIO(const SerializeIO &from) = delete;
69 SerializeIO &operator=(const SerializeIO &from) = delete;
70 ~SerializeIO();
71
72 inline static int getOwner() { return s_owner; }
73
74 inline static int getRank() { return s_rank; }
75
76 inline static int getSize() { return s_size; }
77
78 inline static int getGroupRank() { return s_groupRank; }
79
80 inline static int getGroupSize() { return s_groupSize; }
81
82 static void setGroupFactor(int factor);
83
84 inline static bool isEnabled() { return s_groupFactor != 0; }
85
86 inline static bool inBarrier() { return s_owner != -1; }
87
88 inline static bool inMyGroup() { return s_owner == s_groupRank; }
89
90 private:
91 const DatabaseIO *m_databaseIO; ///< Database I/O pointer
92 #if defined(IOSS_THREADSAFE)
93 static std::mutex m_;
94 #endif
95 bool m_activeFallThru; ///< No barries since my group is running
96 int m_manualOwner; ///< Manually specified owner
97
98 static int s_groupFactor; ///< Grouping factor
99 static int s_size; ///< Number of processors
100 static int s_rank; ///< My processor rank
101 static int s_groupSize; ///< Number of groups
102 static int s_groupRank; ///< My group rank
103 static int s_owner; ///< Group currently running
104 };
105
106 } // namespace Ioss
107
108 #endif // IOSS_Ioss_SerializeIO_h
Ioss_CodeTypes.h
Ioss::SerializeIO::m_manualOwner
int m_manualOwner
Manually specified owner.
Definition: Ioss_SerializeIO.h:96
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
Ioss::SerializeIO::m_databaseIO
const DatabaseIO * m_databaseIO
Database I/O pointer.
Definition: Ioss_SerializeIO.h:91
Ioss::SerializeIO::s_rank
static int s_rank
My processor rank.
Definition: Ioss_SerializeIO.h:100
Ioss::SerializeIO::s_size
static int s_size
Number of processors.
Definition: Ioss_SerializeIO.h:99
Ioss::SerializeIO::s_owner
static int s_owner
Group currently running.
Definition: Ioss_SerializeIO.h:103
Ioss::SerializeIO::s_groupFactor
static int s_groupFactor
Grouping factor.
Definition: Ioss_SerializeIO.h:98
Ioss::SerializeIO
Class SerializeIO is a sentry class which performs serialization for mesh database I/O...
Definition: Ioss_SerializeIO.h:59
Ioss::SerializeIO::~SerializeIO
~SerializeIO()
Definition: Ioss_SerializeIO.C:115
Ioss::SerializeIO::inMyGroup
static bool inMyGroup()
Definition: Ioss_SerializeIO.h:88
Ioss::SerializeIO::m_activeFallThru
bool m_activeFallThru
No barries since my group is running.
Definition: Ioss_SerializeIO.h:95
Ioss::SerializeIO::s_groupRank
static int s_groupRank
My group rank.
Definition: Ioss_SerializeIO.h:102
Ioss::SerializeIO::getGroupSize
static int getGroupSize()
Definition: Ioss_SerializeIO.h:80
Ioss::SerializeIO::setGroupFactor
static void setGroupFactor(int factor)
Definition: Ioss_SerializeIO.C:153
Ioss::SerializeIO::isEnabled
static bool isEnabled()
Definition: Ioss_SerializeIO.h:84
Ioss::SerializeIO::operator=
SerializeIO & operator=(const SerializeIO &from)=delete
Ioss::SerializeIO::getGroupRank
static int getGroupRank()
Definition: Ioss_SerializeIO.h:78
Ioss::SerializeIO::s_groupSize
static int s_groupSize
Number of groups.
Definition: Ioss_SerializeIO.h:101
Ioss::SerializeIO::getOwner
static int getOwner()
Definition: Ioss_SerializeIO.h:72
Ioss::SerializeIO::inBarrier
static bool inBarrier()
Definition: Ioss_SerializeIO.h:86
Ioss::SerializeIO::SerializeIO
SerializeIO(const DatabaseIO *database_io, int manual_owner_processor=-1)
Definition: Ioss_SerializeIO.C:58
Ioss::SerializeIO::getRank
static int getRank()
Definition: Ioss_SerializeIO.h:74
Ioss::SerializeIO::getSize
static int getSize()
Definition: Ioss_SerializeIO.h:76