Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/Main/Init.cpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.
7 : : All rights reserved. See the LICENSE file for details.
8 : : \brief Common initialization routines for main() functions for multiple
9 : : exectuables
10 : : \details Common initialization routines for main() functions for multiple
11 : : exectuables. The functions in this file are used by multiple execitables
12 : : to ensure code-reuse and a uniform screen-output.
13 : : */
14 : : // *****************************************************************************
15 : :
16 : : #include <ctime>
17 : : #include <unistd.h>
18 : :
19 : : #include "QuinoaConfig.hpp"
20 : : #include "Exception.hpp"
21 : : #include "Tags.hpp"
22 : : #include "Keywords.hpp"
23 : : #include "Init.hpp"
24 : :
25 : : namespace tk {
26 : :
27 : 1 : static std::string workdir()
28 : : // *****************************************************************************
29 : : // Wrapper for POSIX API's getcwd() from unistd.h
30 : : //! \return A stirng containing the current working directory
31 : : // *****************************************************************************
32 : : {
33 : : char cwd[1024];
34 : :
35 [ + - ]: 1 : if ( getcwd(cwd, sizeof(cwd)) != nullptr )
36 [ + - ]: 1 : return std::string( cwd );
37 : : else
38 [ - - ][ - - ]: 0 : Throw( "Error from POSIX API's getcwd()" );
[ - - ]
39 : : }
40 : :
41 : 1 : std::string curtime()
42 : : // *****************************************************************************
43 : : // Wrapper for the standard C library's gettimeofday() from
44 : : //! \return A stirng containing the current date and time
45 : : // *****************************************************************************
46 : : {
47 : : time_t current_time;
48 : : char* c_time_string;
49 : :
50 : : // Obtain current time as seconds elapsed since the Epoch
51 : 1 : current_time = time( nullptr );
52 : :
53 [ - + ]: 1 : if (current_time == static_cast<time_t>(-1))
54 [ - - ][ - - ]: 0 : Throw( "Failure to compute the current time" );
[ - - ]
55 : :
56 : : // Convert to local time format
57 : 1 : c_time_string = ctime(¤t_time);
58 : :
59 [ - + ]: 1 : if (c_time_string == nullptr)
60 [ - - ][ - - ]: 0 : Throw( "Failure to convert the current time" );
[ - - ]
61 : :
62 : : // Convert to std::string and remove trailing newline
63 [ + - ]: 1 : std::string str( c_time_string );
64 [ + - ][ + - ]: 1 : str.erase( std::remove(str.begin(), str.end(), '\n'), str.end() );
65 : :
66 : 2 : return str;
67 : : }
68 : :
69 : 1 : void echoHeader( const Print& print, HeaderType header )
70 : : // *****************************************************************************
71 : : // Echo program header
72 : : //! \param[in] print Pretty printer
73 : : //! \param[in] header Header type enum indicating which header to print
74 : : // *****************************************************************************
75 : : {
76 [ - + ]: 1 : if ( header == HeaderType::INCITER )
77 : 0 : print.headerInciter();
78 [ - + ]: 1 : else if ( header == HeaderType::RNGTEST )
79 : 0 : print.headerRNGTest();
80 [ + - ]: 1 : else if ( header == HeaderType::UNITTEST )
81 : 1 : print.headerUnitTest();
82 [ - - ]: 0 : else if ( header == HeaderType::MESHCONV )
83 : 0 : print.headerMeshConv();
84 [ - - ]: 0 : else if ( header == HeaderType::WALKER )
85 : 0 : print.headerWalker();
86 [ - - ]: 0 : else if ( header == HeaderType::FILECONV )
87 : 0 : print.headerFileConv();
88 : : else
89 [ - - ][ - - ]: 0 : Throw( "Header not available" );
[ - - ]
90 : 1 : }
91 : :
92 : 1 : void echoBuildEnv( const Print& print, const std::string& executable )
93 : : // *****************************************************************************
94 : : // Echo build environment
95 : : //! \details Echo information read from build_dir/Base/Config.h filled by
96 : : //! CMake based on src/Main/Config.h.in.
97 : : //! \param[in] print Pretty printer
98 : : //! \param[in] executable Name of the executable
99 : : // *****************************************************************************
100 : : {
101 [ + - ][ + - ]: 1 : print.section( "Build environment" );
102 [ + - ][ + - ]: 1 : print.item( "Hostname", build_hostname() );
[ + - ]
103 [ + - ][ + - ]: 1 : print.item( "Executable", executable );
104 [ + - ][ + - ]: 1 : print.item( "Version", quinoa_version() );
[ + - ]
105 [ + - ]: 1 : auto sha1 = git_commit();
106 [ + - ]: 1 : if (sha1.find("NOTFOUND") == std::string::npos)
107 [ + - ][ + - ]: 1 : print.item( "Revision SHA1", sha1 );
108 [ + - ][ + - ]: 1 : print.item( "CMake build type", build_type() );
[ + - ]
109 : :
110 : : #ifdef NDEBUG
111 : : print.item( "Asserts", "off (turn on: CMAKE_BUILD_TYPE=DEBUG)" );
112 : : #else
113 [ + - ][ + - ]: 1 : print.item( "Asserts", "on (turn off: CMAKE_BUILD_TYPE=RELEASE)" );
114 : : #endif
115 : :
116 [ + - ][ + - ]: 1 : print.item( "MPI C++ wrapper", mpi_compiler() );
[ + - ]
117 [ + - ][ + - ]: 1 : print.item( "Underlying C++ compiler", compiler() );
[ + - ]
118 [ + - ][ + - ]: 1 : print.item( "Build date", build_date() );
[ + - ]
119 : 1 : }
120 : :
121 : 1 : void echoRunEnv( const Print& print, int argc, char** argv,
122 : : bool verbose, bool quiescence, bool charestate, bool trace,
123 : : const std::string& screen_log, const std::string& input_log )
124 : : // *****************************************************************************
125 : : // Echo runtime environment
126 : : //! \param[in] print Pretty printer
127 : : //! \param[in] argc Number of command-line arguments to executable
128 : : //! \param[in] argv C-style string array to command-line arguments to executable
129 : : //! \param[in] verbose True for verbose screen-output
130 : : //! \param[in] quiescence True if quiescence detection is enabled
131 : : //! \param[in] charestate True if chare state collection is enabled
132 : : //! \param[in] trace True if call and stack trace output is enabled
133 : : //! \param[in] screen_log Screen output log file name
134 : : //! \param[in] input_log Input log file name
135 : : // *****************************************************************************
136 : : {
137 [ + - ][ + - ]: 1 : print.section( "Run-time environment" );
138 : :
139 [ + - ][ + - ]: 1 : print.item( "Date, time", curtime() );
140 [ + - ][ + - ]: 1 : print.item( "Work directory", workdir() );
141 [ + - ][ + - ]: 1 : print.item( "Executable (relative to work dir)", argv[0] );
142 : :
143 [ + - ][ + - ]: 1 : print.item( "Command line arguments" );
144 [ + - ]: 1 : print << '\'';
145 [ + - ]: 1 : if (argc>1) {
146 [ - + ]: 1 : for (auto i=1; i<argc-1; ++i) {
147 [ - - ][ - - ]: 0 : print << std::string( argv[i] ) + ' ';
[ - - ]
148 : : }
149 [ + - ][ + - ]: 1 : print << std::string( argv[argc-1] );
150 : : }
151 : 1 : print << "'\n";
152 : :
153 [ + - ][ + - ]: 1 : print.item( "Screen output, -" + *kw::verbose::alias(),
154 [ + - ][ + - ]: 1 : verbose ? "verbose" : "quiet" );
155 [ + - ][ + - ]: 1 : print.item( "Screen output log file, -" + *kw::screen::alias(), screen_log );
156 [ + - ][ + - ]: 1 : print.item( "Input log file", input_log );
157 [ + - ][ + - ]: 1 : print.item( "Number of processing elements",
158 [ + - ][ + - ]: 2 : std::to_string( CkNumPes() ) + " (" +
[ + - ]
159 [ + - ][ + - ]: 4 : std::to_string( CkNumNodes() ) + 'x' +
[ + - ]
160 [ + - ]: 4 : std::to_string( CkNumPes()/CkNumNodes() ) + ')' );
161 [ + - ][ + - ]: 1 : print.item( "Quiescence detection, -" + *kw::quiescence::alias(),
162 [ - + ][ + - ]: 1 : quiescence ? "on" : "off" );
163 [ + - ][ + - ]: 1 : print.item( "Chare state output, -" + *kw::charestate::alias(),
164 [ - + ][ + - ]: 1 : charestate ? "on" : "off" );
165 [ + - ][ + - ]: 1 : print.item( "Call and stack trace, -" + *kw::trace::alias(),
166 [ + - ][ + - ]: 1 : trace ? "on" : "off" );
167 : 1 : }
168 : :
169 : : } // tk::
|