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 : 208 : 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 [ + - ]: 208 : if ( getcwd(cwd, sizeof(cwd)) != nullptr )
36 [ + - ]: 208 : return std::string( cwd );
37 : : else
38 [ - - ][ - - ]: 0 : Throw( "Error from POSIX API's getcwd()" );
[ - - ]
39 : : }
40 : :
41 : 208 : 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 : 208 : current_time = time( nullptr );
52 : :
53 [ - + ]: 208 : 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 : 208 : c_time_string = ctime(¤t_time);
58 : :
59 [ - + ]: 208 : 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 [ + - ]: 208 : std::string str( c_time_string );
64 [ + - ][ + - ]: 208 : str.erase( std::remove(str.begin(), str.end(), '\n'), str.end() );
65 : :
66 : 416 : return str;
67 : : }
68 : :
69 : 208 : 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 [ + + ]: 208 : if ( header == HeaderType::INCITER )
77 : 189 : print.headerInciter();
78 [ + + ]: 19 : else if ( header == HeaderType::UNITTEST )
79 : 1 : print.headerUnitTest();
80 [ + - ]: 18 : else if ( header == HeaderType::MESHCONV )
81 : 18 : print.headerMeshConv();
82 : : else
83 [ - - ][ - - ]: 0 : Throw( "Header not available" );
[ - - ]
84 : 208 : }
85 : :
86 : 208 : void echoBuildEnv( const Print& print, const std::string& executable )
87 : : // *****************************************************************************
88 : : // Echo build environment
89 : : //! \details Echo information read from build_dir/Base/Config.h filled by
90 : : //! CMake based on src/Main/Config.h.in.
91 : : //! \param[in] print Pretty printer
92 : : //! \param[in] executable Name of the executable
93 : : // *****************************************************************************
94 : : {
95 [ + - ][ + - ]: 208 : print.section( "Build environment" );
96 [ + - ][ + - ]: 208 : print.item( "Hostname", build_hostname() );
[ + - ]
97 [ + - ][ + - ]: 208 : print.item( "Executable", executable );
98 : : //print.item( "Version", quinoa_version() ); // needs manual upkeep
99 [ + - ]: 208 : auto sha1 = git_commit();
100 [ - + ]: 208 : if (sha1.find("NOTFOUND") == std::string::npos)
101 [ - - ][ - - ]: 0 : print.item( "Revision SHA1", sha1 );
102 [ + - ][ + - ]: 208 : print.item( "CMake build type", build_type() );
[ + - ]
103 : :
104 : : #ifdef NDEBUG
105 : : print.item( "Asserts", "off (turn on: CMAKE_BUILD_TYPE=DEBUG)" );
106 : : #else
107 [ + - ][ + - ]: 208 : print.item( "Asserts", "on (turn off: CMAKE_BUILD_TYPE=RELEASE)" );
108 : : #endif
109 : :
110 [ + - ][ + - ]: 208 : print.item( "MPI C++ wrapper", mpi_compiler() );
[ + - ]
111 [ + - ][ + - ]: 208 : print.item( "Underlying C++ compiler", compiler() );
[ + - ]
112 [ + - ][ + - ]: 208 : print.item( "Build date", build_date() );
[ + - ]
113 : 208 : }
114 : :
115 : 208 : void echoRunEnv( const Print& print, int argc, char** argv,
116 : : bool verbose, bool quiescence, bool charestate, bool trace,
117 : : const std::string& screen_log, const std::string& input_log )
118 : : // *****************************************************************************
119 : : // Echo runtime environment
120 : : //! \param[in] print Pretty printer
121 : : //! \param[in] argc Number of command-line arguments to executable
122 : : //! \param[in] argv C-style string array to command-line arguments to executable
123 : : //! \param[in] verbose True for verbose screen-output
124 : : //! \param[in] quiescence True if quiescence detection is enabled
125 : : //! \param[in] charestate True if chare state collection is enabled
126 : : //! \param[in] trace True if call and stack trace output is enabled
127 : : //! \param[in] screen_log Screen output log file name
128 : : //! \param[in] input_log Input log file name
129 : : // *****************************************************************************
130 : : {
131 [ + - ][ + - ]: 208 : print.section( "Run-time environment" );
132 : :
133 [ + - ][ + - ]: 208 : print.item( "Date, time", curtime() );
134 [ + - ][ + - ]: 208 : print.item( "Work directory", workdir() );
135 [ + - ][ + - ]: 208 : print.item( "Executable (relative to work dir)", argv[0] );
136 : :
137 [ + - ][ + - ]: 208 : print.item( "Command line arguments" );
138 [ + - ]: 208 : print << '\'';
139 [ + - ]: 208 : if (argc>1) {
140 [ + + ]: 1446 : for (auto i=1; i<argc-1; ++i) {
141 [ + - ][ + - ]: 1238 : print << std::string( argv[i] ) + ' ';
[ + - ]
142 : : }
143 [ + - ][ + - ]: 208 : print << std::string( argv[argc-1] );
144 : : }
145 : 208 : print << "'\n";
146 : :
147 [ + - ][ + - ]: 208 : print.item( "Screen output, -" + *kw::verbose::alias(),
148 [ + - ][ + - ]: 208 : verbose ? "verbose" : "quiet" );
149 [ + - ][ + - ]: 208 : print.item( "Screen output log file, -" + *kw::screen::alias(), screen_log );
150 [ + - ][ + - ]: 208 : print.item( "Input log file", input_log );
151 [ + - ][ + - ]: 208 : print.item( "Number of processing elements",
152 [ + - ][ + - ]: 416 : std::to_string( CkNumPes() ) + " (" +
[ + - ]
153 [ + - ][ + - ]: 832 : std::to_string( CkNumNodes() ) + 'x' +
[ + - ]
154 [ + - ]: 832 : std::to_string( CkNumPes()/CkNumNodes() ) + ')' );
155 [ + - ][ + - ]: 208 : print.item( "Quiescence detection, -" + *kw::quiescence::alias(),
156 [ + + ][ + - ]: 208 : quiescence ? "on" : "off" );
157 [ + - ][ + - ]: 208 : print.item( "Chare state output, -" + *kw::charestate::alias(),
158 [ + + ][ + - ]: 208 : charestate ? "on" : "off" );
159 [ + - ][ + - ]: 208 : print.item( "Call and stack trace, -" + *kw::trace::alias(),
160 [ + - ][ + - ]: 208 : trace ? "on" : "off" );
161 : 208 : }
162 : :
163 : : } // tk::
|