Skip to content

Commit

Permalink
Remove manually allocated memory (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin authored Aug 30, 2024
1 parent c8ffce8 commit b472829
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 130 deletions.
12 changes: 6 additions & 6 deletions src/libs/antares/study/area/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ uint64_t Area::memoryUsage() const
ret += wind.memoryUsage();

// Hydro
ret += PreproHydroMemoryUsage(hydro.prepro);
ret += PreproHydroMemoryUsage(hydro.prepro.get());
if (hydro.series)
{
ret += hydro.series->memoryUsage();
Expand Down Expand Up @@ -223,27 +223,27 @@ void Area::createMissingTimeSeries()
{
if (!hydro.series)
{
hydro.series = new DataSeriesHydro();
hydro.series = std::make_unique<DataSeriesHydro>();
}
}

void Area::createMissingPrepros()
{
if (!load.prepro)
{
load.prepro = new Data::Load::Prepro();
load.prepro = std::make_unique<Data::Load::Prepro>();
}
if (!solar.prepro)
{
solar.prepro = new Data::Solar::Prepro();
solar.prepro = std::make_unique<Data::Solar::Prepro>();
}
if (!wind.prepro)
{
wind.prepro = new Data::Wind::Prepro();
wind.prepro = std::make_unique<Data::Wind::Prepro>();
}
if (!hydro.prepro)
{
hydro.prepro = new PreproHydro();
hydro.prepro = std::make_unique<PreproHydro>();
}
thermal.list.ensureDataPrepro();
}
Expand Down
21 changes: 10 additions & 11 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,11 +934,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
ret = area.hydro.prepro->validate(area.id) && ret;
}

auto* hydroSeries = area.hydro.series;
if (!options.loadOnlyNeeded || !area.hydro.prepro) // Series
{
buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series";
ret = hydroSeries->loadGenerationTS(area.id, buffer, studyVersion) && ret;
ret = area.hydro.series->loadGenerationTS(area.id, buffer, studyVersion) && ret;
}

if (studyVersion < StudyVersion(9, 1))
Expand All @@ -953,12 +952,12 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
else
{
buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series";
ret = hydroSeries->LoadMaxPower(area.id, buffer) && ret;
ret = area.hydro.series->LoadMaxPower(area.id, buffer) && ret;
}

hydroSeries->resizeTSinDeratedMode(study.parameters.derated,
studyVersion,
study.usedByTheSolver);
area.hydro.series->resizeTSinDeratedMode(study.parameters.derated,
studyVersion,
study.usedByTheSolver);
}

// Wind
Expand Down Expand Up @@ -1320,7 +1319,7 @@ void AreaListEnsureDataLoadPrepro(AreaList* l)
{
if (!area.load.prepro)
{
area.load.prepro = new Antares::Data::Load::Prepro();
area.load.prepro = std::make_unique<Antares::Data::Load::Prepro>();
}
});
}
Expand All @@ -1335,7 +1334,7 @@ void AreaListEnsureDataSolarPrepro(AreaList* l)
{
if (!area.solar.prepro)
{
area.solar.prepro = new Antares::Data::Solar::Prepro();
area.solar.prepro = std::make_unique<Antares::Data::Solar::Prepro>();
}
});
}
Expand All @@ -1350,7 +1349,7 @@ void AreaListEnsureDataWindPrepro(AreaList* l)
{
if (!area.wind.prepro)
{
area.wind.prepro = new Antares::Data::Wind::Prepro();
area.wind.prepro = std::make_unique<Antares::Data::Wind::Prepro>();
}
});
}
Expand All @@ -1365,7 +1364,7 @@ void AreaListEnsureDataHydroTimeSeries(AreaList* l)
{
if (!area.hydro.series)
{
area.hydro.series = new DataSeriesHydro();
area.hydro.series = std::make_unique<DataSeriesHydro>();
}
});
}
Expand All @@ -1380,7 +1379,7 @@ void AreaListEnsureDataHydroPrepro(AreaList* l)
{
if (!area.hydro.prepro)
{
area.hydro.prepro = new PreproHydro();
area.hydro.prepro = std::make_unique<PreproHydro>();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class PartHydro
*/
PartHydro();
//! Destructor
~PartHydro();
~PartHydro() = default;

/*!
** \brief Reset internal data
Expand Down Expand Up @@ -211,10 +211,10 @@ class PartHydro
HydroAllocation allocation;

//! Data for the pre-processor
PreproHydro* prepro;
std::unique_ptr<PreproHydro> prepro;

//! Data for time-series
DataSeriesHydro* series;
std::unique_ptr<DataSeriesHydro> series;
// TODO : following time series could be hosted by the series data member above (of type
// DataSeriesHydro),
// which contains other time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Container final: private Yuni::NonCopyable<Container>
*/
Container();
//! Destructor
~Container();
~Container() = default;
//@}

/*!
Expand All @@ -67,9 +67,8 @@ class Container final: private Yuni::NonCopyable<Container>
*/
uint64_t memoryUsage() const;

public:
//! Data for the pre-processor
Data::Load::Prepro* prepro;
std::unique_ptr<Data::Load::Prepro> prepro;

TimeSeriesNumbers tsNumbers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Container
*/
Container();
//! Destructor
~Container();
~Container() = default;
//@}

/*!
Expand All @@ -64,9 +64,8 @@ class Container
*/
uint64_t memoryUsage() const;

public:
//! Data for the pre-processor
Data::Solar::Prepro* prepro;
std::unique_ptr<Data::Solar::Prepro> prepro;

TimeSeriesNumbers tsNumbers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Container
*/
Container();
//! Destructor
~Container();
~Container() = default;
//@}

/*!
Expand All @@ -64,9 +64,8 @@ class Container
*/
uint64_t memoryUsage() const;

public:
//! Data for the pre-processor
Data::Wind::Prepro* prepro;
std::unique_ptr<Data::Wind::Prepro> prepro;

TimeSeriesNumbers tsNumbers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,7 @@ class Progression final
public:
Meter();

virtual ~Meter()
{
if (logsContainer)
{
delete[] logsContainer;
}
}

void allocateLogsContainer(uint nb);
virtual ~Meter() = default;

/*!
** \brief Prepare enough space to allow @n simultaneous tasks
Expand All @@ -188,16 +180,12 @@ class Progression final
virtual bool onInterval(uint) override;

public:
//
Progression::Part::Map parts;
Part::ListRef inUse;
std::mutex mutex;
uint nbParallelYears;

// Because writing something to the logs might be expensive, we have to
// reduce the time spent in locking the mutex.
// We will use a temp vector of string to delay the writing into the logs
Yuni::CString<256, false>* logsContainer;
std::vector<Yuni::CString<256, false>> logsContainer;

}; // class Meter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ namespace Antares
namespace Solver
{
inline Progression::Meter::Meter():
nbParallelYears(0),
logsContainer(nullptr)
nbParallelYears(0)
{
}

inline void Progression::Meter::allocateLogsContainer(uint nb)
{
logsContainer = new Yuni::CString<256, false>[nb];
}

inline void Progression::Meter::taskCount(uint n)
{
(void)n;
Expand All @@ -49,7 +43,7 @@ inline void Progression::add(Section section, int nbTicks)
inline void Progression::setNumberOfParallelYears(uint nb)
{
pProgressMeter.nbParallelYears = nb;
pProgressMeter.allocateLogsContainer(nb);
pProgressMeter.logsContainer.resize(nb);
}

inline Progression::Part& Progression::begin(uint year, Progression::Section section)
Expand Down
7 changes: 0 additions & 7 deletions src/libs/antares/study/parts/hydro/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,10 @@ PartHydro::PartHydro():
leewayLowerBound(1.),
leewayUpperBound(1.),
pumpingEfficiency(1.),
prepro(nullptr),
series(nullptr)
{
}

PartHydro::~PartHydro()
{
delete prepro;
delete series;
}

void PartHydro::reset()
{
intraDailyModulation = 24;
Expand Down
7 changes: 0 additions & 7 deletions src/libs/antares/study/parts/load/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ using namespace Yuni;
namespace Antares::Data::Load
{
Container::Container():
prepro(nullptr),
series(tsNumbers)
{
}

Container::~Container()
{
delete prepro;
prepro = nullptr;
}

bool Container::forceReload(bool reload) const
{
bool ret = true;
Expand Down
6 changes: 0 additions & 6 deletions src/libs/antares/study/parts/solar/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ using namespace Yuni;
namespace Antares::Data::Solar
{
Container::Container():
prepro(nullptr),
series(tsNumbers)
{
}

Container::~Container()
{
delete prepro;
}

bool Container::forceReload(bool reload) const
{
bool ret = true;
Expand Down
6 changes: 0 additions & 6 deletions src/libs/antares/study/parts/wind/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ using namespace Yuni;
namespace Antares::Data::Wind
{
Container::Container():
prepro(nullptr),
series(tsNumbers)
{
}

Container::~Container()
{
delete prepro;
}

bool Container::forceReload(bool reload) const
{
bool ret = true;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/antares/study/study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,22 +979,22 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName)

void Study::destroyAllLoadTSGeneratorData()
{
areas.each([](Data::Area& area) { FreeAndNil(area.load.prepro); });
areas.each([](Data::Area& area) { area.load.prepro.reset(); });
}

void Study::destroyAllSolarTSGeneratorData()
{
areas.each([](Data::Area& area) { FreeAndNil(area.solar.prepro); });
areas.each([](Data::Area& area) { area.solar.prepro.reset(); });
}

void Study::destroyAllHydroTSGeneratorData()
{
areas.each([](Data::Area& area) { FreeAndNil(area.hydro.prepro); });
areas.each([](Data::Area& area) { area.hydro.prepro.reset(); });
}

void Study::destroyAllWindTSGeneratorData()
{
areas.each([](Data::Area& area) { FreeAndNil(area.wind.prepro); });
areas.each([](Data::Area& area) { area.wind.prepro.reset(); });
}

void Study::ensureDataAreLoadedForAllBindingConstraints()
Expand Down
4 changes: 1 addition & 3 deletions src/solver/ts-generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ void ResizeGeneratedTimeSeries(Data::AreaList& areas, Data::Parameters& params)
// Hydro
if (params.timeSeriesToGenerate & Data::timeSeriesHydro)
{
Data::DataSeriesHydro* const series = area.hydro.series;
const uint nbSeries = params.nbTimeSeriesHydro;
series->resizeTS(nbSeries);
area.hydro.series->resizeTS(params.nbTimeSeriesHydro);
}

// Thermal
Expand Down
4 changes: 2 additions & 2 deletions src/solver/ts-generator/hydro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu
for (uint i = 0; i < DIM; i++)
{
uint areaIndexI = i / MONTHS_PER_YEAR;
auto* prepro = study.areas.byIndex[areaIndexI]->hydro.prepro;
auto* prepro = study.areas.byIndex[areaIndexI]->hydro.prepro.get();

auto& corre = CORRE[i];

Expand All @@ -105,7 +105,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu
for (uint j = 0; j < DIM; j++)
{
uint areaIndexJ = j / MONTHS_PER_YEAR;
auto* preproJ = study.areas.byIndex[areaIndexJ]->hydro.prepro;
auto* preproJ = study.areas.byIndex[areaIndexJ]->hydro.prepro.get();

x = std::abs(((int)(i % MONTHS_PER_YEAR) - (int)(j % MONTHS_PER_YEAR)) / 2.);

Expand Down
Loading

0 comments on commit b472829

Please sign in to comment.