Skip to content

Commit

Permalink
log when 5 percent and add flushing
Browse files Browse the repository at this point in the history
  • Loading branch information
Young Geun Kim committed Dec 15, 2024
1 parent 75c7774 commit bec78bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion inst/include/bvharforecaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class McmcOutforecastRun {
std::string log_name = fmt::format("Chain {} / Window {}", chain + 1, window + 1);
auto logger = SPDLOG_SINK_MT(log_name);
logger->set_pattern("[%n] [Thread " + std::to_string(omp_get_thread_num()) + "] %v");
int logging_freq = num_iter / 10; // 10 percent
int logging_freq = num_iter / 20; // 5 percent
if (logging_freq == 0) {
logging_freq = 1;
}
Expand All @@ -610,6 +610,7 @@ class McmcOutforecastRun {
logger->info("{} / {} (Warmup)", i + 1, num_iter);
}
}
logger->flush();
for (int i = num_burn; i < num_iter; ++i) {
if (bvharinterrupt::is_interrupted()) {
RecordType reg_record = model[window][chain]->template returnStructRecords<RecordType>(0, thin, sparse);
Expand All @@ -624,6 +625,7 @@ class McmcOutforecastRun {
RecordType reg_record = model[window][chain]->template returnStructRecords<RecordType>(0, thin, sparse);
updateForecaster(reg_record, window, chain);
model[window][chain].reset();
logger->flush();
spdlog::drop(log_name);
}
void forecastWindow(int window, int chain) {
Expand Down
4 changes: 3 additions & 1 deletion inst/include/bvharmcmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ class McmcRun : public McmcInterface {
std::string log_name = fmt::format("Chain {}", chain + 1);
auto logger = SPDLOG_SINK_MT(log_name);
logger->set_pattern("[%n] [Thread " + std::to_string(omp_get_thread_num()) + "] %v");
int logging_freq = num_iter / 10; // 10 percent
int logging_freq = num_iter / 20; // 5 percent
if (logging_freq == 0) {
logging_freq = 1;
}
Expand All @@ -1078,6 +1078,7 @@ class McmcRun : public McmcInterface {
logger->info("{} / {} (Warmup)", i + 1, num_iter);
}
}
logger->flush();
for (int i = num_burn; i < num_iter; ++i) {
if (bvharinterrupt::is_interrupted()) {
logger->warn("User interrupt in {} / {}", i + 1, num_iter);
Expand All @@ -1100,6 +1101,7 @@ class McmcRun : public McmcInterface {
{
res[chain] = mcmc_ptr[chain]->returnRecords(0, thin);
}
logger->flush();
spdlog::drop(log_name);
}

Expand Down

0 comments on commit bec78bb

Please sign in to comment.