GEOS
initializeEnvironment.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 #ifndef GEOS_COMMON_INITIALIZEENVIRONMENT_HPP_
17 #define GEOS_COMMON_INITIALIZEENVIRONMENT_HPP_
18 
19 // Source includes
20 #include "DataTypes.hpp"
21 #include "MpiWrapper.hpp"
22 
23 // TPL includes
24 #ifdef GEOS_USE_CALIPER
25 
26 #ifdef GEOS_USE_ADIAK
27 #include <adiak.hpp>
28 #endif
29 
30 //Forward declaration of cali::ConfigManager.
31 namespace cali
32 {
33 class ConfigManager;
34 }
35 #endif
36 
37 namespace geos
38 {
39 
44 {
47 
49  bool beginFromRestart = false;
50 
53  bool onlyValidateInput = false;
54 
57 
60 
63 
66 
69 
73 
78 
80  string schemaName;
81 
83  string problemName;
84 
86  string outputDirectory = ".";
87 
89  string timerOutput = "";
90 
93 
96 };
97 
101 void setupLogger();
102 
107 
112 
118 
122 void setupMKL();
123 
127 void setupOpenMP();
128 
134 void setupMPI( int argc, char * argv[] );
135 
141 void finalizeMPI( bool inError = false );
142 
147 void setupCUDA();
148 
154 void setupEnvironment( int argc, char * argv[] );
155 
160 void cleanupEnvironment( bool inError = false );
161 
162 #if defined( GEOS_USE_CALIPER )
163 
169 void setupCaliper( cali::ConfigManager & caliperManager,
170  CommandLineOptions const & commandLineOptions );
171 
172 
173 #endif
174 
182 template< typename T >
183 void pushStatsIntoAdiak( string const & name, T const value )
184 {
185 #if defined( GEOS_USE_CALIPER ) && defined( GEOS_USE_ADIAK ) && !defined(__APPLE__)
186  // Apple clang doesn't like adiak.
187  T const total = MpiWrapper::sum( value );
188  adiak::value( name + " sum", total );
189  adiak::value( name + " mean", double( total ) / MpiWrapper::commSize() );
190  adiak::value( name + " min", MpiWrapper::min( value ) );
191  adiak::value( name + " max", MpiWrapper::max( value ) );
192 #else
193  GEOS_UNUSED_VAR( name );
194  GEOS_UNUSED_VAR( value );
195 #endif
196 }
197 
198 } // namespace geos
199 
200 #endif // GEOS_COMMON_INITIALIZEENVIRONMENT_HPP_
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:361
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
void setupOpenMP()
Setup OpenMP.
void setupLogger()
Initialize the logger.
void setupCUDA()
Setup CUDA.
void cleanupEnvironment(bool inError=false)
Cleanup/finalize the environment.
void finalizeLogger()
Finalize the logger.
void setupEnvironment(int argc, char *argv[])
Setup/init the environment.
void pushStatsIntoAdiak(string const &name, T const value)
Compute the sum, mean, min, and max of value across ranks and push them into Adiak using name.
void finalizeMPI(bool inError=false)
Finalize MPI.
void setupMPI(int argc, char *argv[])
Setup MPI.
void setupLvArray()
Setup the LvArray library. This initializes signal handling and the floating point environment.
void setupMKL()
Setup MKL if in use.
void finalizeCaliper()
Finalize Caliper and Adiak.
int integer
Signed integer type.
Definition: DataTypes.hpp:81
string outputDirectory
The directory to put all output.
string schemaName
The name of the schema.
bool beginFromRestart
True iff restarting from the middle of an existing run.
string restartFileName
The path to the restart file, if specified.
integer overridePartitionNumbers
True if using the partition override.
string timerOutput
The string used to initialize caliper.
string problemName
The name of the problem being run.
string_array inputFileNames
The paths to the input xml files.
integer xPartitionsOverride
The number of partitions in the x direction.
real64 printMemoryUsage
Print memory usage in data repository.
integer traceDataMigration
Trace host-device data migration.
integer yPartitionsOverride
The number of partitions in the y direction.
integer zPartitionsOverride
The number of partitions in the z direction.
static T max(T const &value, MPI_Comm comm=MPI_COMM_GEOS)
Convenience function for a MPI_Allreduce using a MPI_MAX operation.
static T sum(T const &value, MPI_Comm comm=MPI_COMM_GEOS)
Convenience function for a MPI_Allreduce using a MPI_SUM operation.
static T min(T const &value, MPI_Comm comm=MPI_COMM_GEOS)
Convenience function for a MPI_Allreduce using a MPI_MIN operation.