Skip to content

Commit

Permalink
solver logs: one file per proc (#733)
Browse files Browse the repository at this point in the history
* solver logs: one file per proc

* fix xpress search dir

* fix xpress loads if custom install

* test for Windows

* delete unwanted message

* change licence dir

* clear

* print Xpress logs
  • Loading branch information
a-zakir authored Dec 19, 2023
1 parent 0d841b9 commit 1a738b3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
7 changes: 3 additions & 4 deletions src/cpp/benders/benders_core/BendersBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,9 @@ LogData BendersBase::bendersDataToLogData(
data.number_of_subproblem_resolved +
cumulative_number_of_subproblem_resolved_before_resume};
}
void BendersBase::set_log_file(const std::filesystem::path &log_file) {
_log_name = log_file;

solver_log_manager_ = SolverLogManager(log_name());
void BendersBase::set_solver_log_file(const std::filesystem::path &log_file) {
solver_log_file_ = log_file;
solver_log_manager_ = SolverLogManager(solver_log_file_);
}

/*!
Expand Down
8 changes: 5 additions & 3 deletions src/cpp/benders/benders_core/include/BendersBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class BendersBase {
virtual ~BendersBase() = default;
BendersBase(BendersBaseOptions options, Logger logger, Writer writer);
virtual void launch() = 0;
void set_log_file(const std::filesystem::path &log_name);
[[nodiscard]] std::filesystem::path log_name() const { return _log_name; }
void set_solver_log_file(const std::filesystem::path &log_file);
[[nodiscard]] std::filesystem::path solver_log_file() const {
return solver_log_file_;
}
double execution_time() const;
virtual std::string BendersName() const = 0;

Expand Down Expand Up @@ -159,7 +161,7 @@ class BendersBase {
private:
BendersBaseOptions _options;
unsigned int _totalNbProblems = 0;
std::filesystem::path _log_name = "";
std::filesystem::path solver_log_file_ = "";
BendersRelevantIterationsData relevantIterationData_ = {
std::make_shared<WorkerMasterData>(), nullptr};
WorkerMasterPtr _master;
Expand Down
8 changes: 6 additions & 2 deletions src/cpp/benders/factories/BendersFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ int RunBenders(char** argv, const std::filesystem::path& options_file,
std::ostringstream oss_l = start_message(options, benders->BendersName());
oss_l << std::endl;
logger->display_message(oss_l.str());

benders->set_log_file(log_reports_name);

auto solver_log = std::filesystem::path(options.OUTPUTROOT) /
(std::string("solver_log_proc_") +
std::to_string(world.rank()) + ".txt");

benders->set_solver_log_file(solver_log);

writer->write_log_level(options.LOG_LEVEL);
writer->write_master_name(options.MASTER_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/multisolver_interface/SolverXpress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const std::map<int, std::string> TYPETONAME = {{1, "rows"}, {2, "columns"}};

SolverXpress::SolverXpress(SolverLogManager &log_manager) : SolverXpress() {
if (log_manager.log_file_path != "") {
_log_stream.open(_log_file, std::ofstream::out | std::ofstream::app);
_log_file = log_manager.log_file_path;
_log_stream.open(_log_file, std::ofstream::out | std::ofstream::app);
add_stream(_log_stream);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/multisolver_interface/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ std::vector<std::string> XpressDynamicLibraryPotentialPaths() {
#if defined(_MSC_VER) // Windows
potential_paths.push_back((prefix / "bin" / "xprs.dll").string());
#elif defined(__APPLE__) // OS X
potential_paths.push_back((prefix / "/lib/libxprs.dylib").string());
potential_paths.push_back((prefix / "lib" / "libxprs.dylib").string());
#elif defined(__GNUC__) // Linux
potential_paths.push_back((prefix / "/lib/libxprs.so").string());
potential_paths.push_back((prefix / "lib" / "libxprs.so").string());
#else
std::cerr << "OS Not recognized by xpress/environment.cc."
<< " You won't be able to use Xpress.";
Expand Down Expand Up @@ -294,7 +294,7 @@ bool LoadXpressDynamicLibrary(std::string& xpresspath) {
for (const std::string& path : canonical_paths) {
if (xpress_library.TryToLoad(path)) {
std::cout << "Info: "
<< "Found the Xpress library in " << path << ".";
<< "Found the Xpress library in " << path << ".\n";
xpress_lib_path.clear();
std::filesystem::path p(path);
p.remove_filename();
Expand Down Expand Up @@ -323,11 +323,11 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) {
std::string xpresspath;
bool status = LoadXpressDynamicLibrary(xpresspath);
if (!status) {
std::cout << "Warning: " << status << "\n";
return false;
}

std::string xpress_from_env = GetXpressVarFromEnvironmentVariables("XPRESS");
std::string xpress_from_env =
GetXpressVarFromEnvironmentVariables("XPRESSDIR");
if (xpress_from_env == "") {
if (verbose) {
std::cout << "Warning: Environment variable XPRESS undefined.\n";
Expand All @@ -336,7 +336,7 @@ bool initXpressEnv(bool verbose, int xpress_oem_license_key) {
return false;
}
} else {
xpresspath = xpress_from_env;
xpresspath = (std::filesystem::path(xpress_from_env) / "bin").string();
}

int code;
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp/benders/benders_sequential_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BendersSequentialDouble : public BendersSequential {
void InitializeProblems() override {
MatchProblemToId();

auto solver_log_manager = SolverLogManager(log_name());
auto solver_log_manager = SolverLogManager(solver_log_file());
reset_master(new WorkerMaster(master_variable_map, get_master_path(),
get_solver_name(), get_log_level(),
_data.nsubproblem, solver_log_manager,
Expand Down

0 comments on commit 1a738b3

Please sign in to comment.