Skip to content

Commit

Permalink
#431 Move definition of filename for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhetmaniuk authored and lifflander committed Feb 5, 2020
1 parent 5fe1089 commit a901203
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
8 changes: 7 additions & 1 deletion src/vt/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,13 @@ bool Runtime::initialize(bool const force_now) {
auto lbNames = vrt::collection::balance::lb_names_;
auto mapLB = vrt::collection::balance::LBType::StatsMapLB;
if (ArgType::vt_lb_name == lbNames[mapLB]) {
vrt::collection::balance::ProcStats::readRestartInfo();
auto const node = theContext->getNode();
const std::string &base_file = ArgType::vt_lb_stats_file_in;
const std::string &dir = ArgType::vt_lb_stats_dir_in;
auto const file = fmt::format("{}.{}.out", base_file, node);
const auto file_name =
static_cast<std::string>(fmt::format("{}/{}", dir, file));
vrt::collection::balance::ProcStats::readRestartInfo(file_name);
}
}
#endif
Expand Down
20 changes: 6 additions & 14 deletions src/vt/vrt/collection/balance/proc_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ StatsRestartReader::~StatsRestartReader() {
}

/*static*/
void StatsRestartReader::readStats() {
void StatsRestartReader::readStats(const std::string &fileName) {

// Read the input files
std::deque< std::set<ElementIDType> > elements_history;
inputStatsFile(elements_history);
inputStatsFile(fileName, elements_history);
if (elements_history.empty()) {
vtWarn("No element history provided");
return;
Expand All @@ -122,19 +122,11 @@ void StatsRestartReader::readStats() {

/*static*/
void StatsRestartReader::inputStatsFile(
const std::string &fileName,
std::deque< std::set<ElementIDType> > &element_history
)
{
using ArgType = vt::arguments::ArgConfig;
auto const node = theContext()->getNode();
const std::string &base_file = ArgType::vt_lb_stats_file_in;
const std::string &dir = ArgType::vt_lb_stats_dir_in;
auto const file = fmt::format("{}.{}.out", base_file, node);
auto const file_name = fmt::format("{}/{}", dir, file);

vt_print(lb, "inputStatFile: file={}, iter={}\n", file_name, 0);

std::FILE *pFile = std::fopen(file_name.c_str(), "r");
std::FILE *pFile = std::fopen(fileName.c_str(), "r");
if (pFile == nullptr) {
vtAssert(pFile, "File opening failed");
}
Expand Down Expand Up @@ -314,11 +306,11 @@ void StatsRestartReader::scatterMsgs(VecMsg *msg) {
std::copy(&recvVec[header], &recvVec[0]+recvVec.size(), myList.begin());
}

/*static*/ void ProcStats::readRestartInfo() {
/*static*/ void ProcStats::readRestartInfo(const std::string &fileName) {
if (ProcStats::proc_reader_ == nullptr) {
ProcStats::proc_reader_ = new StatsRestartReader;
}
ProcStats::proc_reader_->readStats();
ProcStats::proc_reader_->readStats(fileName);
}

/*static*/ void ProcStats::clearStats() {
Expand Down
5 changes: 3 additions & 2 deletions src/vt/vrt/collection/balance/proc_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
#include "vt/vrt/collection/balance/stats_msg.h"
#include "vt/timing/timing.h"

#include <vector>
#include <string>
#include <unordered_map>
#include <vector>

namespace vt { namespace vrt { namespace collection { namespace lb {

Expand Down Expand Up @@ -82,7 +83,7 @@ struct ProcStats {

static void outputStatsFile();

static void readRestartInfo();
static void readRestartInfo(const std::string &fileName);

private:
static void createStatsFile();
Expand Down
4 changes: 3 additions & 1 deletion src/vt/vrt/collection/balance/proc_stats.util.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

#include <deque>
#include <map>
#include <string>
#include <vector>

#include "vt/config.h"
Expand All @@ -72,10 +73,11 @@ struct StatsRestartReader {

~StatsRestartReader();

static void readStats();
static void readStats(const std::string &fileName);

private:
static void inputStatsFile(
const std::string &fileName,
std::deque<std::set<ElementIDType> > &element_history
);

Expand Down

0 comments on commit a901203

Please sign in to comment.