Skip to content

Commit 1a3f0ae

Browse files
committed
QOL high rank run changes
1 parent 238185f commit 1a3f0ae

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
@@ -294,12 +294,13 @@ def _log_to_file(self):
294294
Support keys:
295295
RANK_FILES - logfile per rank
296296
DATETIME_FILES - logfile with starting datetime timestamp per rank
297-
NONE - no logging files, display to cout
297+
CLI - no logging files, display to cout
298+
NULL - no logging files, no cout
298299
"""
299-
300-
if "PHARE_LOG" not in os.environ:
301-
os.environ["PHARE_LOG"] = "RANK_FILES"
302300
from pyphare.cpp import cpp_lib
303301

304-
if os.environ["PHARE_LOG"] != "NONE" and cpp_lib().mpi_rank() == 0:
302+
logging = os.environ["PHARE_LOG"] = os.environ.get("PHARE_LOG", "RANK_FILES")
303+
need_log_dir = logging != "CLI" and logging != "NULL"
304+
if need_log_dir and cpp_lib().mpi_rank() == 0:
305305
Path(".log").mkdir(exist_ok=True)
306+
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
@@ -121,32 +121,37 @@ class Simulator : public ISimulator
121121
private:
122122
auto find_model(std::string name);
123123

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

132133

133134
if (log == "DATETIME_FILES")
134135
{
135136
auto date_time = core::mpi::date_time();
136137
auto rank = std::to_string(core::mpi::rank());
137138
auto size = std::to_string(core::mpi::size());
138-
return ".log/" + date_time + "_" + rank + "_of_" + size + ".out";
139+
return std::make_unique<std::ofstream>(".log/" + date_time + "_" + rank + "_of_"
140+
+ size + ".out");
139141
}
140142

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

146-
return std::string{""}; // unused
151+
return nullptr;
147152
}
148153

149-
std::ofstream log_out{log_file_name()};
154+
std::unique_ptr<std::ofstream> log_out{log_file()};
150155
std::streambuf* coutbuf = nullptr;
151156
std::shared_ptr<PHARE::amr::Hierarchy> hierarchy_;
152157
std::unique_ptr<Integrator> integrator_;
@@ -194,13 +199,13 @@ class Simulator : public ISimulator
194199

195200
namespace
196201
{
197-
inline auto logging(std::ofstream& log_out)
202+
inline auto logging(std::unique_ptr<std::ofstream>& log_out)
198203
{
199204
std::streambuf* buf = nullptr;
200-
if (auto log = core::get_env("PHARE_LOG"); log != "NONE")
205+
if (log_out)
201206
{
202207
buf = std::cout.rdbuf();
203-
std::cout.rdbuf(log_out.rdbuf());
208+
std::cout.rdbuf(log_out->rdbuf());
204209
}
205210
return buf;
206211
}

0 commit comments

Comments
 (0)