Skip to content

Commit 20511e6

Browse files
authored
Merge pull request #1091 from PhilipDeegan/no_logs
high rank run produce less logs by default
2 parents a1bf9c5 + 1a3f0ae commit 20511e6

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

pyphare/pyphare/pharein/simulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ def wrapper(simulation_object, **kwargs):
730730
kwargs["dry_run"] = kwargs.get(
731731
"dry_run", os.environ.get("PHARE_DRY_RUN", "0") == "1"
732732
)
733-
kwargs["write_reports"] = kwargs.get( # on by default except for tests
734-
"write_reports", os.environ.get("PHARE_TESTING", "0") != "1"
735-
)
733+
734+
# is per rank, not per node (yet)
735+
kwargs["write_reports"] = kwargs.get("write_reports", False)
736736

737737
return func(simulation_object, **kwargs)
738738

pyphare/pyphare/simulator/simulator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,13 @@ def _log_to_file(self):
298298
Support keys:
299299
RANK_FILES - logfile per rank
300300
DATETIME_FILES - logfile with starting datetime timestamp per rank
301-
NONE - no logging files, display to cout
301+
CLI - no logging files, display to cout
302+
NULL - no logging files, no cout
302303
"""
303-
304-
if "PHARE_LOG" not in os.environ:
305-
os.environ["PHARE_LOG"] = "RANK_FILES"
306304
from pyphare.cpp import cpp_lib
307305

308-
if os.environ["PHARE_LOG"] != "NONE" and cpp_lib().mpi_rank() == 0:
306+
logging = os.environ["PHARE_LOG"] = os.environ.get("PHARE_LOG", "RANK_FILES")
307+
need_log_dir = logging != "CLI" and logging != "NULL"
308+
if need_log_dir and cpp_lib().mpi_rank() == 0:
309309
Path(".log").mkdir(exist_ok=True)
310+
cpp_lib().mpi_barrier()

res/cmake/def.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests
163163
set_property(TEST ${binary} PROPERTY ENVIRONMENT "PYTHONPATH=${PHARE_PYTHONPATH}")
164164
# ASAN detects leaks by default, even in system/third party libraries
165165
set_property(TEST ${binary} APPEND PROPERTY ENVIRONMENT "ASAN_OPTIONS=detect_leaks=0")
166-
set_property(TEST ${binary} APPEND PROPERTY ENVIRONMENT PHARE_TESTING=1 )
167166
endfunction(set_exe_paths_)
168167

169168
function(add_phare_test_ binary directory)

src/core/logger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace PHARE
1212
constexpr static std::uint8_t LOG_LEVEL = PHARE_LOG_LEVEL;
1313
}
1414

15-
#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO)
15+
#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO) || defined(PHARE_FORCE_LOG_LINE)
1616
#define PHARE_LOG_LINE_STR(str) \
1717
std::cout << __FILE__ << ":" << __LINE__ << " - " << str << std::endl;
1818
#define PHARE_LOG_LINE_SS(s) PHARE_LOG_LINE_STR((std::stringstream{} << s).str());

src/simulator/simulator.hpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,32 +123,37 @@ class Simulator : public ISimulator
123123
private:
124124
auto find_model(std::string name);
125125

126-
auto static log_file_name()
126+
std::unique_ptr<std::ofstream> static log_file()
127127
{
128-
// ".log" directory is not created here, but in python if PHARE_LOG != "NONE"
128+
// ".log" directory is not created here, but in simulator.py
129129
if (auto log = core::get_env("PHARE_LOG"))
130130
{
131131
if (log == "RANK_FILES")
132-
return ".log/" + std::to_string(core::mpi::rank()) + ".out";
132+
return std::make_unique<std::ofstream>(".log/" + std::to_string(core::mpi::rank())
133+
+ ".out");
133134

134135

135136
if (log == "DATETIME_FILES")
136137
{
137138
auto date_time = core::mpi::date_time();
138139
auto rank = std::to_string(core::mpi::rank());
139140
auto size = std::to_string(core::mpi::size());
140-
return ".log/" + date_time + "_" + rank + "_of_" + size + ".out";
141+
return std::make_unique<std::ofstream>(".log/" + date_time + "_" + rank + "_of_"
142+
+ size + ".out");
141143
}
142144

143-
if (log != "NONE")
145+
if (log == "NULL")
146+
return std::make_unique<std::ofstream>("/dev/null");
147+
148+
if (log != "CLI")
144149
throw std::runtime_error(
145-
"PHARE_LOG invalid type, valid keys are RANK_FILES/DATETIME_FILES/NONE");
150+
"PHARE_LOG invalid type, valid keys are RANK_FILES/DATETIME_FILES/CLI/NULL");
146151
}
147152

148-
return std::string{""}; // unused
153+
return nullptr;
149154
}
150155

151-
std::ofstream log_out{log_file_name()};
156+
std::unique_ptr<std::ofstream> log_out{log_file()};
152157
std::streambuf* coutbuf = nullptr;
153158
std::shared_ptr<PHARE::amr::Hierarchy> hierarchy_;
154159
std::unique_ptr<Integrator> integrator_;
@@ -196,13 +201,13 @@ class Simulator : public ISimulator
196201

197202
namespace
198203
{
199-
inline auto logging(std::ofstream& log_out)
204+
inline auto logging(std::unique_ptr<std::ofstream>& log_out)
200205
{
201206
std::streambuf* buf = nullptr;
202-
if (auto log = core::get_env("PHARE_LOG"); log != "NONE")
207+
if (log_out)
203208
{
204209
buf = std::cout.rdbuf();
205-
std::cout.rdbuf(log_out.rdbuf());
210+
std::cout.rdbuf(log_out->rdbuf());
206211
}
207212
return buf;
208213
}

0 commit comments

Comments
 (0)