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 multithreads logs #1764

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
78790e6
set multi threads log dir
a-zakir Nov 12, 2023
151dedd
[skip ci] will not work thank u @guilpier-code
a-zakir Nov 16, 2023
6da7fde
fstream-->ostream ptr
a-zakir Nov 16, 2023
d0697c4
[skip ci] move streams creation
a-zakir Nov 16, 2023
b6e4720
dirty
a-zakir Nov 16, 2023
1586ab5
[skip] better
a-zakir Nov 16, 2023
81ef7b0
suggestion by @flomnes
a-zakir Nov 16, 2023
c935389
direct call
a-zakir Nov 17, 2023
b2a612a
delete deprecated method
a-zakir Nov 17, 2023
2775642
[skip ci] set field width for incoming msg
a-zakir Nov 17, 2023
a69f2df
test SiriusCallback
a-zakir Nov 17, 2023
9756b55
Merge branch 'feature/multi-threads-solver-logs' of https://github.co…
a-zakir Nov 17, 2023
5769816
[skip ci] fix
a-zakir Nov 17, 2023
8c615ae
test Sirius callback: ok
a-zakir Nov 17, 2023
c8d8f82
adaptation for COIN solvers
a-zakir Nov 23, 2023
1535d8c
bug
a-zakir Nov 23, 2023
b1dce69
set log files per thread
a-zakir Nov 23, 2023
30853d1
tmp Revert "bug"
a-zakir Nov 23, 2023
9d1db92
Merge branch 'feature/multi-threads-solver-logs' of https://github.co…
a-zakir Nov 23, 2023
df4a671
copy log files
a-zakir Nov 23, 2023
3a24ba1
remove &
a-zakir Nov 23, 2023
14b1150
fix
a-zakir Nov 23, 2023
00926bc
ok
a-zakir Nov 23, 2023
0a44ba7
clean&clear
a-zakir Nov 23, 2023
568e8f0
update log handler
a-zakir Dec 11, 2023
ae4c29f
update log handler (#1793)
a-zakir Dec 14, 2023
9f44c53
Merge branch 'feature/multi-threads-solver-logs' of https://github.co…
a-zakir Dec 15, 2023
f1cb6aa
remove old code & update
a-zakir Dec 15, 2023
e63468c
use numSpace and thread number
a-zakir Dec 19, 2023
becdf7f
update & fix
a-zakir Dec 19, 2023
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
61 changes: 44 additions & 17 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ struct SimplexResult
mpsWriterFactory mps_writer_factory;
};

static SimplexResult OPT_TryToCallSimplex(
const OptimizationOptions& options,
PROBLEME_HEBDO* problemeHebdo,
Optimization::PROBLEME_SIMPLEXE_NOMME& Probleme,
const int NumIntervalle,
const int optimizationNumber,
const OptPeriodStringGenerator& optPeriodStringGenerator,
bool PremierPassage,
IResultWriter& writer)
static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options,
PROBLEME_HEBDO* problemeHebdo,
Optimization::PROBLEME_SIMPLEXE_NOMME& Probleme,
const int NumIntervalle,
const int optimizationNumber,
const OptPeriodStringGenerator& optPeriodStringGenerator,
bool PremierPassage,
IResultWriter& writer,
OrtoolsLogHandler& ortools_logger)
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
{
const auto& ProblemeAResoudre = problemeHebdo->ProblemeAResoudre;
auto ProbSpx
Expand Down Expand Up @@ -225,7 +225,8 @@ static SimplexResult OPT_TryToCallSimplex(
{
solver = ORTOOLS_ConvertIfNeeded(options.solverName, &Probleme, solver);
}
const std::string filename = createMPSfilename(optPeriodStringGenerator, optimizationNumber);

const std::string filename = createMPSfilename(optPeriodStringGenerator, optimizationNumber);

mpsWriterFactory mps_writer_factory(problemeHebdo->ExportMPS,
problemeHebdo->exportMPSOnError,
Expand All @@ -241,6 +242,13 @@ static SimplexResult OPT_TryToCallSimplex(
if (options.useOrtools)
{
const bool keepBasis = (optimizationNumber == PREMIERE_OPTIMISATION);
// std::ofstream log_writer; // one per thread

// std::vector<std::ostream*> log_streams;
if (Probleme.SolverLogs())
{
setOrtoolsSolverLogs(solver, ortools_logger);
}
solver = ORTOOLS_Simplexe(&Probleme, solver, keepBasis);
if (solver != nullptr)
{
Expand Down Expand Up @@ -308,16 +316,30 @@ bool OPT_AppelDuSimplexe(const OptimizationOptions& options,
problemeHebdo->solverLogs);

bool PremierPassage = true;

struct SimplexResult simplexResult =
OPT_TryToCallSimplex(options, problemeHebdo, Probleme, NumIntervalle, optimizationNumber,
optPeriodStringGenerator, PremierPassage, writer);
// tmp
OrtoolsLogHandler ortools_logger;
struct SimplexResult simplexResult = OPT_TryToCallSimplex(options,
problemeHebdo,
Probleme,
NumIntervalle,
optimizationNumber,
optPeriodStringGenerator,
PremierPassage,
writer,
ortools_logger);

if (!simplexResult.success)
{
PremierPassage = false;
simplexResult = OPT_TryToCallSimplex(options, problemeHebdo, Probleme, NumIntervalle, optimizationNumber,
optPeriodStringGenerator, PremierPassage, writer);
simplexResult = OPT_TryToCallSimplex(options,
problemeHebdo,
Probleme,
NumIntervalle,
optimizationNumber,
optPeriodStringGenerator,
PremierPassage,
writer,
ortools_logger);
}

long long solveTime = simplexResult.solveTime;
Expand Down Expand Up @@ -372,8 +394,13 @@ bool OPT_AppelDuSimplexe(const OptimizationOptions& options,

Probleme.SetUseNamedProblems(true);

auto MPproblem = std::shared_ptr<MPSolver>(ProblemSimplexeNommeConverter(options.solverName, &Probleme).Convert());
auto MPproblem = std::shared_ptr<MPSolver>(
ProblemSimplexeNommeConverter(options.solverName, &Probleme).Convert());

if (Probleme.SolverLogs())
{
setOrtoolsSolverLogs(MPproblem.get(), ortools_logger);
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
}
auto analyzer = makeUnfeasiblePbAnalyzer();
analyzer->run(MPproblem.get());
analyzer->printReport();
Expand Down
26 changes: 19 additions & 7 deletions src/solver/utils/ortools_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <antares/exception/AssertionError.hpp>
#include <antares/Enum.hpp>
#include <filesystem>
#include <thread>

using namespace operations_research;

Expand Down Expand Up @@ -31,10 +32,25 @@ namespace Antares
{
namespace Optimization
{
void setOrtoolsSolverLogs(MPSolver* solver, OrtoolsLogHandler& ortools_logger)
{
solver->EnableOutput(&ortools_logger);
}

OrtoolsLogHandler::OrtoolsLogHandler()
{
std::filesystem::path log_file = logs.logfile().c_str();
auto log_directory = log_file.parent_path();
auto myid = std::this_thread::get_id();
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
std::stringstream ss;
ss << myid;
auto log_file_per_thread = log_directory / (std::string("thread_") + ss.str() + ".log");
log_writer_.open(log_file_per_thread, std::ofstream::out | std::ofstream::app);
}
ProblemSimplexeNommeConverter::ProblemSimplexeNommeConverter(
const std::string& solverName,
const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* problemeSimplexe)
: solverName_(solverName), problemeSimplexe_(problemeSimplexe)
const std::string& solverName,
const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* problemeSimplexe) :
solverName_(solverName), problemeSimplexe_(problemeSimplexe)
{
if (problemeSimplexe_->UseNamedProblems())
{
Expand All @@ -55,10 +71,6 @@ MPSolver* ProblemSimplexeNommeConverter::Convert()
CopyRows(solver);

CopyMatrix(solver);
if (problemeSimplexe_->SolverLogs())
{
solver->EnableOutput();
}

return solver;
}
Expand Down
21 changes: 21 additions & 0 deletions src/solver/utils/ortools_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <map>
#include <string>
#include <fstream>

#include <antares/writer/i_writer.h>

Expand Down Expand Up @@ -48,6 +49,26 @@ namespace Antares
namespace Optimization
{

class OrtoolsLogHandler : public LogHandlerInterface
{
public:
// tmp test with std::cout
explicit OrtoolsLogHandler();
void message(const char* msg) override
{
log_writer_ << msg << std::endl;
}

private:
// TODO won't work in ci, needs ortools update
// see https://github.com/rte-france/or-tools/pull/112

// // TODO
std::ofstream log_writer_;
// log_writer.open(log_file_per_thread, std::ofstream::out | std::ofstream::app);
// log_streams.push_back(&log_writer);
};
void setOrtoolsSolverLogs(MPSolver* solver, OrtoolsLogHandler &ortools_logger);
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
class Nomenclature
{
public:
Expand Down
Loading