Skip to content

Commit

Permalink
Bugfix: CUDAEnsemble would always output both step/exit files.
Browse files Browse the repository at this point in the history
If output directory specified, even if no logging config.
  • Loading branch information
Robadob committed Oct 29, 2021
1 parent 20c7e74 commit 99d306c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
15 changes: 14 additions & 1 deletion include/flamegpu/sim/SimLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class SimLogger {
* @param log_export_queue The queue of logs to exported to disk
* @param log_export_queue_mutex This mutex must be locked to access log_export_queue
* @param log_export_queue_cdn The condition is notified every time a log has been added to the queue
* @param _export_step If true step logs will be exported
* @param _export_exit If true exit logs will be exported
*/
SimLogger(const std::vector<RunLog> &run_logs,
const RunPlanVector &run_plans,
const std::string &out_directory,
const std::string &out_format,
std::queue<unsigned int> &log_export_queue,
std::mutex &log_export_queue_mutex,
std::condition_variable &log_export_queue_cdn);
std::condition_variable &log_export_queue_cdn,
bool _export_step,
bool _export_exit);
/**
* The thread which the logger is executing on, created by the constructor
*/
Expand Down Expand Up @@ -73,6 +77,15 @@ class SimLogger {
* The condition is notified every time a log has been added to the queue
*/
std::condition_variable &log_export_queue_cdn;
/**
* If true step log files will be exported
*/

bool export_step;
/**
* If true exit log files will be exported
*/
bool export_exit;
};

} // namespace flamegpu
Expand Down
2 changes: 1 addition & 1 deletion src/flamegpu/gpu/CUDAEnsemble.cu
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void CUDAEnsemble::simulate(const RunPlanVector &plans) {
// Init log worker
SimLogger *log_worker = nullptr;
if (!config.out_directory.empty() && !config.out_format.empty()) {
log_worker = new SimLogger(run_logs, plans, config.out_directory, config.out_format, log_export_queue, log_export_queue_mutex, log_export_queue_cdn);
log_worker = new SimLogger(run_logs, plans, config.out_directory, config.out_format, log_export_queue, log_export_queue_mutex, log_export_queue_cdn, step_log_config.get(), exit_log_config.get());
} else if (!config.out_directory.empty() ^ !config.out_format.empty()) {
fprintf(stderr, "Warning: Only 1 of out_directory and out_format is set, both must be set for logging to commence to file.\n");
}
Expand Down
25 changes: 16 additions & 9 deletions src/flamegpu/sim/SimLogger.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ SimLogger::SimLogger(const std::vector<RunLog> &_run_logs,
const std::string &_out_format,
std::queue<unsigned int> &_log_export_queue,
std::mutex &_log_export_queue_mutex,
std::condition_variable &_log_export_queue_cdn)
std::condition_variable &_log_export_queue_cdn,
bool _export_step,
bool _export_exit)
: run_logs(_run_logs)
, run_plans(_run_plans)
, out_directory(_out_directory)
, out_format(_out_format)
, log_export_queue(_log_export_queue)
, log_export_queue_mutex(_log_export_queue_mutex)
, log_export_queue_cdn(_log_export_queue_cdn) {
, log_export_queue_cdn(_log_export_queue_cdn)
, export_step(_export_step)
, export_exit(_export_exit) {
this->thread = std::thread(&SimLogger::start, this);
// Attempt to name the thread
#ifdef _MSC_VER
Expand Down Expand Up @@ -78,13 +82,16 @@ void SimLogger::start() {
break;
}
// Log items
const path exit_path = p_out_directory/path(run_plans[target_log].getOutputSubdirectory())/path("exit." + out_format);
const auto exit_logger = io::LoggerFactory::createLogger(exit_path.generic_string(), false, false);
exit_logger->log(run_logs[target_log], true, false, true);
const path step_path = p_out_directory/path(run_plans[target_log].getOutputSubdirectory())/path(std::to_string(target_log)+"."+out_format);
const auto step_logger = io::LoggerFactory::createLogger(step_path.generic_string(), false, false);
step_logger->log(run_logs[target_log], true, true, false);

if (export_exit) {
const path exit_path = p_out_directory / path(run_plans[target_log].getOutputSubdirectory()) / path("exit." + out_format);
const auto exit_logger = io::LoggerFactory::createLogger(exit_path.generic_string(), false, false);
exit_logger->log(run_logs[target_log], true, false, true);
}
if (export_step) {
const path step_path = p_out_directory/path(run_plans[target_log].getOutputSubdirectory())/path(std::to_string(target_log)+"."+out_format);
const auto step_logger = io::LoggerFactory::createLogger(step_path.generic_string(), false, false);
step_logger->log(run_logs[target_log], true, true, false);
}
// Continue
++logs_processed;
lock.lock();
Expand Down

0 comments on commit 99d306c

Please sign in to comment.