cpuLoad.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::cpuLoad
26 
27 Description
28  Class to maintain a field of the CPU load per cell.
29 
30  The optionalCpuLoad is a base-class for cpuLoad to simplify the
31  implementation of optional CPU time caching. This is achieved via the
32  optionalCpuLoad::New function which returns a optionalCpuLoad with dummy
33  functions if loadBalancing is false otherwise it creates or looks-up and
34  returns a cpuLoad with the given name.
35 
36  Used for loadBalancing.
37 
38 SourceFiles
39  cpuLoad.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef cpuLoad_H
44 #define cpuLoad_H
45 
46 #include "volFields.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class optionalCpuLoad Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class optionalCpuLoad
58 {
59  // Private Member Data
60 
61  //- Dummy optionalCpuLoad
62  // returned by optionalCpuLoad::New if loadBalancing = false
63  static optionalCpuLoad optionalCpuLoad_;
64 
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct from mesh, name and switch
72  {}
73 
74  //- Disallow default bitwise copy construction
75  optionalCpuLoad(const optionalCpuLoad&) = delete;
76 
77 
78  // Selectors
79 
80  static optionalCpuLoad& New
81  (
82  const fvMesh& mesh,
83  const word& name,
84  const bool loadBalancing
85  );
86 
87 
88  //- Destructor
89  virtual ~optionalCpuLoad()
90  {}
91 
92 
93  // Member Functions
94 
95  //- Dummy reset function
96  virtual void reset()
97  {}
98 
99  //- Dummy cpuTimeIncrement function
100  virtual void cpuTimeIncrement(const label celli)
101  {}
102 
103 
104  // Member Operators
105 
106  //- Disallow default bitwise assignment
107  void operator=(const optionalCpuLoad&) = delete;
108 };
109 
110 
111 /*---------------------------------------------------------------------------*\
112  Class cpuLoad Declaration
113 \*---------------------------------------------------------------------------*/
115 class cpuLoad
116 :
117  public optionalCpuLoad,
119 {
120  // Private Data
121 
122  cpuTime cpuTime_;
123 
124 
125 public:
126 
127  // Declare name of the class and its debug switch
128  TypeName("cpuLoad");
129 
130 
131  // Constructors
132 
133  //- Construct from mesh, name and switch
134  cpuLoad
135  (
136  const fvMesh& mesh,
137  const word& name
138  );
139 
140  //- Disallow default bitwise copy construction
141  cpuLoad(const cpuLoad&) = delete;
142 
143 
144  //- Destructor
145  virtual ~cpuLoad();
146 
147 
148  // Member Functions
149 
150  //- Reset the CPU time
151  virtual void reset();
152 
153  //- Cache the CPU time increment for celli
154  virtual void cpuTimeIncrement(const label celli);
155 
156 
157  // Member Operators
158 
159  //- Disallow default bitwise assignment
160  void operator=(const cpuLoad&) = delete;
161 };
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 } // End namespace Foam
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
optionalCpuLoad()
Construct from mesh, name and switch.
Definition: cpuLoad.H:70
virtual void cpuTimeIncrement(const label celli)
Dummy cpuTimeIncrement function.
Definition: cpuLoad.H:99
virtual ~optionalCpuLoad()
Destructor.
Definition: cpuLoad.H:88
fvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
Class to maintain a field of the CPU load per cell.
Definition: cpuLoad.H:114
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:70
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static optionalCpuLoad & New(const fvMesh &mesh, const word &name, const bool loadBalancing)
Definition: cpuLoad.C:64
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void reset()
Dummy reset function.
Definition: cpuLoad.H:95
void operator=(const optionalCpuLoad &)=delete
Disallow default bitwise assignment.
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:54
Namespace for OpenFOAM.