GEOSX
Logger.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_COMMON_LOGGER_HPP
20 #define GEOSX_COMMON_LOGGER_HPP
21 
22 // Source incldes
23 #include "common/GeosxConfig.hpp"
24 #include "LvArray/src/Macros.hpp"
25 
26 // System includes
27 #if defined(GEOSX_USE_MPI)
28  #include <mpi.h>
29 #endif
30 
35 #define GEOSX_LOG( ... ) LVARRAY_LOG( __VA_ARGS__ )
36 
41 #define GEOSX_LOG_VAR( ... ) LVARRAY_LOG_VAR( __VA_ARGS__ )
42 
48 #define GEOSX_LOG_RANK_0_IF( EXP, msg ) \
49  do { \
50  if( ::geosx::logger::internal::rank == 0 && EXP ) \
51  { \
52  std::ostringstream oss; \
53  oss << msg; \
54  std::cout << oss.str() << std::endl; \
55  } \
56  } while( false )
57 
62 #define GEOSX_LOG_RANK_0( msg ) GEOSX_LOG_RANK_0_IF( true, msg )
63 
69 #if defined(__CUDA_ARCH__)
70 #define GEOSX_LOG_RANK_IF( EXP, msg )
71 #else
72 #define GEOSX_LOG_RANK_IF( EXP, msg ) \
73  do { \
74  if( EXP ) \
75  { \
76  std::ostringstream oss; \
77  oss << "Rank " << ::geosx::logger::internal::rankString << ": " << msg; \
78  *logger::internal::rankStream << oss.str() << std::endl; \
79  } \
80  } while( false )
81 #endif
82 
87 #define GEOSX_LOG_RANK( msg ) GEOSX_LOG_RANK_IF( true, msg )
88 
93 #define GEOSX_LOG_RANK_VAR( var ) GEOSX_LOG_RANK( #var " = " << var )
94 
100 #if defined(__CUDA_ARCH__)
101 #define GEOSX_ERROR_IF( EXP, msg ) LVARRAY_ERROR_IF( EXP, msg )
102 #else
103 #define GEOSX_ERROR_IF( EXP, msg ) LVARRAY_ERROR_IF( EXP, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
104 #endif
105 
110 #define GEOSX_ERROR( msg ) GEOSX_ERROR_IF( true, msg )
111 
117 #define GEOSX_ASSERT_MSG( EXP, msg ) LVARRAY_ASSERT_MSG( EXP, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
118 
123 #define GEOSX_ASSERT( EXP ) GEOSX_ASSERT_MSG( EXP, "" )
124 
130 #define GEOSX_WARNING_IF( EXP, msg ) LVARRAY_WARNING_IF( EXP, msg )
131 
136 #define GEOSX_WARNING( msg ) LVARRAY_WARNING( msg )
137 
143 #define GEOSX_INFO_IF( EXP, msg ) LVARRAY_INFO_IF( EXP, msg )
144 
149 #define GEOSX_INFO( msg ) LVARRAY_INFO( msg )
150 
157 #define GEOSX_ERROR_IF_EQ_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_EQ_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
158 
164 #define GEOSX_ERROR_IF_EQ( lhs, rhs ) GEOSX_ERROR_IF_EQ_MSG( lhs, rhs, "" )
165 
172 #define GEOSX_ERROR_IF_NE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_NE_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
173 
179 #define GEOSX_ERROR_IF_NE( lhs, rhs ) GEOSX_ERROR_IF_NE_MSG( lhs, rhs, "" )
180 
187 #define GEOSX_ERROR_IF_GT_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_GT_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
188 
194 #define GEOSX_ERROR_IF_GT( lhs, rhs ) GEOSX_ERROR_IF_GT_MSG( lhs, rhs, "" )
195 
202 #define GEOSX_ERROR_IF_GE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
203 
209 #define GEOSX_ERROR_IF_GE( lhs, rhs ) GEOSX_ERROR_IF_GE_MSG( lhs, rhs, "" )
210 
217 #define GEOSX_ERROR_IF_LT_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_LT_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
218 
224 #define GEOSX_ERROR_IF_LT( lhs, rhs ) GEOSX_ERROR_IF_LT_MSG( lhs, rhs, "" )
225 
232 #define GEOSX_ERROR_IF_LE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_LE_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
233 
239 #define GEOSX_ERROR_IF_LE( lhs, rhs ) GEOSX_ERROR_IF_LE_MSG( lhs, rhs, "" )
240 
247 #define GEOSX_ASSERT_EQ_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_EQ_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
248 
254 #define GEOSX_ASSERT_EQ( lhs, rhs ) GEOSX_ASSERT_EQ_MSG( lhs, rhs, "" )
255 
262 #define GEOSX_ASSERT_NE_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_NE_MSG( lhs, rhs, msg )
263 
269 #define GEOSX_ASSERT_NE( lhs, rhs ) LVARRAY_ASSERT_NE( lhs, rhs )
270 
277 #define GEOSX_ASSERT_GT_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_GT_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
278 
284 #define GEOSX_ASSERT_GT( lhs, rhs ) GEOSX_ASSERT_GT_MSG( lhs, rhs, "" )
285 
292 #define GEOSX_ASSERT_GE_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_GE_MSG( lhs, rhs, "***** Rank " << ::geosx::logger::internal::rankString << ": " << msg )
293 
299 #define GEOSX_ASSERT_GE( lhs, rhs ) GEOSX_ASSERT_GE_MSG( lhs, rhs, "" )
300 
306 #define GEOSX_LOG_LEVEL_FN( minLevel, fn ) \
307  do { \
308  if( this->getLogLevel() >= minLevel ) \
309  { \
310  fn; \
311  } \
312  } while( false )
313 
319 #define GEOSX_LOG_LEVEL( minLevel, msg ) GEOSX_INFO_IF( this->getLogLevel() >= minLevel, msg );
320 
326 #define GEOSX_LOG_LEVEL_RANK_0( minLevel, msg ) GEOSX_LOG_RANK_0_IF( this->getLogLevel() >= minLevel, msg )
327 
333 #define GEOSX_LOG_LEVEL_BY_RANK( minLevel, msg ) GEOSX_LOG_RANK_IF( this->getLogLevel() >= minLevel, msg )
334 
335 
336 namespace geosx
337 {
338 
339 namespace logger
340 {
341 
342 namespace internal
343 {
344 
345 extern int rank;
346 
347 extern std::string rankString;
348 
349 extern int n_ranks;
350 
351 extern std::ostream * rankStream;
352 
353 #if defined(GEOSX_USE_MPI)
354 extern MPI_Comm comm;
355 #endif
356 } // namespace internal
357 
358 #if defined(GEOSX_USE_MPI)
359 
364 void InitializeLogger( MPI_Comm comm, const std::string & rank_output_dir="" );
365 #endif
366 
371 void InitializeLogger( const std::string & rank_output_dir="" );
372 
376 void FinalizeLogger();
377 
378 } // namespace logger
379 
380 } // namespace geosx
381 
382 #endif /* GEOSX_COMMON_LOGGER_HPP */
Contains a bunch of macro definitions.
std::string string
String type.
Definition: DataTypes.hpp:131