Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage logs in multithreads run #1793

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/solver/utils/ortools_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ void OrtoolsLogHandler::init()
{
#ifdef __linux__
if (log_file_per_thread_.empty()
|| (file_pointer = fopen(log_file_per_thread_.string().c_str(), "a+")) == nullptr)
|| (file_pointer_ = fopen(log_file_per_thread_.string().c_str(), "a+")) == nullptr)
#elif _WIN32
if (log_file_per_thread_.empty()
|| (file_pointer = _fsopen(log_file_per_thread_.string().c_str(), "a+", _SH_DENYNO))
|| (file_pointer_ = _fsopen(log_file_per_thread_.string().c_str(), "a+", _SH_DENYNO))
== nullptr)
#endif
{
Expand All @@ -76,7 +76,7 @@ void OrtoolsLogHandler::init()
}
else
{
setvbuf(file_pointer, nullptr, _IONBF, 0);
setvbuf(file_pointer_, nullptr, _IONBF, 0);
}
}
else
Expand All @@ -87,10 +87,10 @@ void OrtoolsLogHandler::init()

OrtoolsLogHandler::~OrtoolsLogHandler()
{
if (file_pointer)
if (file_pointer_)
{
fclose(file_pointer);
file_pointer = nullptr;
fclose(file_pointer_);
file_pointer_ = nullptr;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/solver/utils/ortools_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class OrtoolsLogHandler : public LogHandlerInterface

FILE* where_to_write()
{
return file_pointer;
return file_pointer_;
}

void copy_log(Solver::IResultWriter& writer) const;
Expand All @@ -90,11 +90,12 @@ class OrtoolsLogHandler : public LogHandlerInterface
void init();

std::ofstream log_writer_;
FILE* file_pointer = nullptr;
FILE* file_pointer_ = nullptr;
std::string solver_name_;
std::filesystem::path log_directory_ = ".";
std::filesystem::path log_file_per_thread_ = "";
};

class Nomenclature
{
public:
Expand Down
Loading