-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathtestMemoryStats.cpp
More file actions
210 lines (181 loc) · 6.68 KB
/
testMemoryStats.cpp
File metadata and controls
210 lines (181 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2024 TotalEnergies
* Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2023-2024 Chevron
* Copyright (c) 2019- GEOS/GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#include "mainInterface/ProblemManager.hpp"
#include "mainInterface/initialization.hpp"
#include "mainInterface/GeosxState.hpp"
#include "fileIO/Outputs/MemoryStatsOutput.hpp"
#include "codingUtilities/Parsing.hpp"
#include "common/format/table/TableFormatter.hpp"
#include <gtest/gtest.h>
using namespace geos;
static const string basicXml =
R"xml(
<Problem>
<Mesh>
<InternalMesh name="mesh1"
elementTypes="{ C3D8 }"
xCoords="{ 0, 3 }" yCoords="{ 0, 1 }" zCoords="{ 0, 1 }"
nx="{ 4 }" ny="{ 1 }" nz="{ 1 }"
cellBlockNames="{ cb1 }"/>
</Mesh>
<ElementRegions>
<CellElementRegion name="Region2"
cellBlocks="{ * }"
materialList="{ shale }"/>
</ElementRegions>
<Outputs>
<MemoryStats name="memoryOutput"
writeCSV="1"/>
</Outputs>
</Problem>
)xml";
static const string basicSimXml =
R"xml(
<Problem>
<!-- <Solvers>
<SolidMechanicsLagrangianFEM name="lagsolve"
cflFactor="0.25"
discretization="FE1"
targetRegions="{ Region2 }"/>
</Solvers>-->
<Mesh>
<InternalMesh name="mesh1"
elementTypes="{ C3D8 }"
xCoords="{ 0, 3 }" yCoords="{ 0, 1 }" zCoords="{ 0, 1 }"
nx="{ 4 }" ny="{ 1 }" nz="{ 1 }"
cellBlockNames="{ cb1 }"/>
</Mesh>
<!-- <Events
maxTime="1.0e-3">
<PeriodicEvent name="solverApplications"
forceDt="1.0e-3"
target="/Solvers/lagsolve"/>
<PeriodicEvent name="outputs"
target="/Outputs/siloOutput"/>
</Events>
<NumericalMethods>
<FiniteElements>
<FiniteElementSpace name="FE1"
order="1"/>
</FiniteElements>
</NumericalMethods>-->
<ElementRegions>
<CellElementRegion name="Region2"
cellBlocks="{ * }"
materialList="{ shale }"/>
</ElementRegions>
<!-- <Constitutive>
<ElasticIsotropic name="shale"
defaultDensity="2700"
defaultBulkModulus="5.5556e9"
defaultShearModulus="4.16667e9"/>
</Constitutive>
<FieldSpecifications>
<FieldSpecification name="v0"
component="0"
fieldName="velocity"
functionName="timeFunction"
objectPath="nodeManager"
scale="1.0"
setNames="{ xneg }"/>
<FieldSpecification name="xconstraint"
objectPath="nodeManager"
fieldName="velocity"
component="0"
scale="0.0"
setNames="{ xpos }"/>
<FieldSpecification name="yconstraint"
objectPath="nodeManager"
fieldName="velocity"
component="1"
scale="0.0"
setNames="{ yneg, ypos }"/>
<FieldSpecification name="zconstraint"
objectPath="nodeManager"
fieldName="velocity"
component="2"
scale="0.0"
setNames="{ zneg, zpos }"/>
</FieldSpecifications>
<Functions>
<TableFunction name="timeFunction"
inputVarNames="{ time }"
coordinates="{ 0.0, 1.0e-6, 2.0e-6, 1.0e9 }"
values="{ 0.0, 1.0, 1.0, 1.0 }"/>
</Functions>-->
<Outputs>
<MemoryStats name="memoryOutput"
writeCSV="1"/>
</Outputs>
<!-- <Geometry>
<Box name="perf"
xMin="{ 0, 0, 0 }"
xMax="{ 1, 1, 1 }"/>
</Geometry> -->
</Problem>
)xml";
static const string memOutputPath = "/Outputs/memoryOutput";
static const string memOutputFileName = "MemoryStats_umpireStats.csv";
CommandLineOptions g_commandLineOptions;
// Test if a CSV has been effectively output because of MemoryStatsOutput task execution.
// (This test could be extended to check more memory pools depending on the platform, but may need
// to run a simulation)
TEST( testXML, testMemoryCSVOutput )
{
// setup
GeosxState state( std::make_unique< CommandLineOptions >( g_commandLineOptions ) );
ProblemManager & problem = state.getProblemManager();
problem.parseInputString( basicXml );
problem.problemSetup();
// do a MemoryStats test output with a dummy entry
integer const dummyCycle = 123456;
string const dummyCycleStr = std::to_string( dummyCycle );
MemoryStatsOutput & memOutput = problem.getGroupByPath< MemoryStatsOutput >( memOutputPath );
memOutput.execute( 0.0, 0.0, dummyCycle, 0, 0.0, problem.getDomainPartition() );
// read the CSV output (parseFile() will throw if no CSV is generated)
std::vector< string > csvLines;
{
std::ifstream is( memOutputFileName );
EXPECT_TRUE( is.good() );
string line;
while( std::getline( is, line ) )
{
csvLines.emplace_back( line );
}
}
auto const findCSVMemoryEntry = [=]( string_view cycleStr, string_view memSpaceName ) -> bool {
for( string const & csvLine : csvLines )
{
std::vector< string > const lineEntries = stringutilities::tokenize( csvLine,
TableCSVFormatter::m_separator,
false );
EXPECT_GT( lineEntries.size(), 3 );
if( lineEntries[0] == cycleStr && lineEntries[2] == memSpaceName )
{ // we found the line coresponding to the given cycle & memory-space
return true;
}
}
return false;
};
EXPECT_TRUE( findCSVMemoryEntry( dummyCycleStr, "HOST" ) );
}
int main( int argc, char * * argv )
{
::testing::InitGoogleTest( &argc, argv );
g_commandLineOptions = *geos::basicSetup( argc, argv );
int const result = RUN_ALL_TESTS();
geos::basicCleanup( false );
return result;
}