Skip to content

Commit

Permalink
Memory allocation, use std::vector (#1393)
Browse files Browse the repository at this point in the history
* [DEV] Remove SIM_InitialisationResultats and members of struct RESULTATS_PAR_INTERCONNEXION

* [DEV] std::vector<double> TransitMoyenRecalculQuadratique;

* [DEV] std::vector<RESULTATS_PAR_INTERCONNEXION*> ResultatsParInterconnexion;

* [FIX] TransitMoyenRecalculQuadratique assign

* [DEV] std::vector<RESULTATS_PAR_INTERCONNEXION> ResultatsParInterconnexion

* [DEV] remove unused var in AllocateResultsForEconomicMode()

* [DEV] remove DONNEES_PAR_PAYS DONNEES_ADEQUATION DonneesParPays

* [DEV] struct VALEURS_GENEREES_PAR_PAYS

* [DEV] std::vector<VALEURS_GENEREES_PAR_PAYS**> ValeursGenereesParPays;

* [DEV] std::vector<std::vector<VALEURS_GENEREES_PAR_PAYS*>> ValeursGenereesParPays;

* [DEV] std::vector<std::vector<VALEURS_GENEREES_PAR_PAYS>> ValeursGenereesParPays;

* [FIX] Compile for previous commit

* [FIX] for causing mutiple free

* [DEV] struct NUMERO_CHRONIQUES_TIREES_PAR_PAYS

* [DEV] std::vector<std::vector<NUMERO_CHRONIQUES_TIREES_PAR_PAYS*>> NumeroChroniquesTireesParPays

* [DEV] std::vector<std::vector<NUMERO_CHRONIQUES_TIREES_PAR_PAYS>> NumeroChroniquesTireesParPays

* [DEV] std::vector<NUMERO_CHRONIQUES_TIREES_PAR_INTERCONNEXION*> NumeroChroniquesTireesParInterconnexion

* [DEV] std::vector<std::vector<NUMERO_CHRONIQUES_TIREES_PAR_INTERCONNEXION> NumeroChroniquesTireesParInterconnexion

* [DEV] removed SIM_DesallocationTableaux()

* [DEV] Try resize -1

* [DEV] Replaced struct RESULTATS_PAR_INTERCONNEXION by var transitMoyenInterconnexionsRecalculQuadratique

* [FIX] Removed desalloc from tests

* [FIX] Added destructor back

* [DEV] std::string Sens;

* [DEV] IndicesDebutDeLigne  NombreDeTermesDesLignes
  • Loading branch information
payetvin authored Jul 5, 2023
1 parent f5fef26 commit c515839
Show file tree
Hide file tree
Showing 31 changed files with 88 additions and 282 deletions.
9 changes: 4 additions & 5 deletions src/solver/aleatoire/alea_tirage_au_sort_chroniques.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ static void InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(

uint year = runtime.timeseriesNumberYear[numSpace];

const size_t nbDaysPerYearDouble = runtime.nbDaysPerYear * sizeof(double);

// each area
const unsigned int count = study.areas.size();
for (unsigned int i = 0; i != count; ++i)
{
// Variables - the current area
NUMERO_CHRONIQUES_TIREES_PAR_PAYS& ptchro = *NumeroChroniquesTireesParPays[numSpace][i];
NUMERO_CHRONIQUES_TIREES_PAR_PAYS& ptchro = NumeroChroniquesTireesParPays[numSpace][i];
auto& area = *(study.areas.byIndex[i]);
VALEURS_GENEREES_PAR_PAYS& ptvalgen = *(ValeursGenereesParPays[numSpace][i]);
VALEURS_GENEREES_PAR_PAYS& ptvalgen = ValeursGenereesParPays[numSpace][i];

// Load
{
Expand All @@ -85,7 +83,8 @@ static void InitializeTimeSeriesNumbers_And_ThermalClusterProductionCost(
ptchro.Hydraulique
= (data.count != 1) ? (long)data.timeseriesNumbers[0][year] : 0; // zero-based
// Hydro - mod
memset(ptvalgen.HydrauliqueModulableQuotidien, 0, nbDaysPerYearDouble);
std::fill(ptvalgen.HydrauliqueModulableQuotidien.begin(),
ptvalgen.HydrauliqueModulableQuotidien.end(),0);
}
// Wind
{
Expand Down
3 changes: 0 additions & 3 deletions src/solver/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,6 @@ Application::~Application()
if (!pStudy->parameters.noOutput)
pStudy->importLogsToOutputFolder();

// simulation
SIM_DesallocationTableaux();

// release all reference to the current study held by this class
pStudy->clear();
pStudy = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/solver/hydro/management/daily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
uint z = area.index;
assert(z < study.areas.size());

auto& ptchro = *NumeroChroniquesTireesParPays[numSpace][z];
auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];

auto& inflowsmatrix = area.hydro.series->storage;

Expand All @@ -237,7 +237,7 @@ inline void HydroManagement::prepareDailyOptimalGenerations(Solver::Variable::St
auto const& maxP = maxPower[Data::PartHydro::genMaxP];
auto const& maxE = maxPower[Data::PartHydro::genMaxE];

auto const& valgen = *ValeursGenereesParPays[numSpace][z];
auto& valgen = ValeursGenereesParPays[numSpace][z];

std::shared_ptr<DebugData> debugData(nullptr);

Expand Down
8 changes: 4 additions & 4 deletions src/solver/hydro/management/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void HydroManagement::prepareInflowsScaling(uint numSpace)
{
uint z = area.index;

auto& ptchro = *NumeroChroniquesTireesParPays[numSpace][z];
auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];

auto& inflowsmatrix = area.hydro.series->storage;
assert(inflowsmatrix.width && inflowsmatrix.height);
Expand Down Expand Up @@ -159,7 +159,7 @@ void HydroManagement::minGenerationScaling(uint numSpace)
{
uint z = area.index;

const auto& ptchro = *NumeroChroniquesTireesParPays[numSpace][z];
const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];
auto& mingenmatrix = area.hydro.series->mingen;
auto tsIndex = (uint)ptchro.Hydraulique;
auto const& srcmingen = mingenmatrix[tsIndex < mingenmatrix.width ? tsIndex : 0];
Expand Down Expand Up @@ -336,7 +336,7 @@ bool HydroManagement::checkMinGeneration(uint numSpace)
study.areas.each([this, &numSpace, &ret](Data::Area& area)
{
uint z = area.index;
const auto& ptchro = *NumeroChroniquesTireesParPays[numSpace][z];
const auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];
auto tsIndex = (uint)ptchro.Hydraulique;

if (area.hydro.useHeuristicTarget)
Expand All @@ -359,7 +359,7 @@ void HydroManagement::prepareNetDemand(uint numSpace)

auto& scratchpad = area.scratchpad[numSpace];

auto& ptchro = *NumeroChroniquesTireesParPays[numSpace][z];
auto& ptchro = NumeroChroniquesTireesParPays[numSpace][z];

auto& rormatrix = area.hydro.series->ror;
auto tsIndex = (uint)ptchro.Hydraulique;
Expand Down
6 changes: 3 additions & 3 deletions src/solver/optimisation/adequacy_patch_csr/solve_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ std::unique_ptr<PROBLEME_POINT_INTERIEUR> buildInteriorPointProblem(
Probleme->VariableBinaire = (char*)ProblemeAResoudre.CoutsReduits;

Probleme->NombreDeContraintes = ProblemeAResoudre.NombreDeContraintes;
Probleme->IndicesDebutDeLigne = ProblemeAResoudre.IndicesDebutDeLigne;
Probleme->NombreDeTermesDesLignes = ProblemeAResoudre.NombreDeTermesDesLignes;
Probleme->IndicesDebutDeLigne = ProblemeAResoudre.IndicesDebutDeLigne.data();
Probleme->NombreDeTermesDesLignes = ProblemeAResoudre.NombreDeTermesDesLignes.data();
Probleme->IndicesColonnes = ProblemeAResoudre.IndicesColonnes;
Probleme->CoefficientsDeLaMatriceDesContraintes
= ProblemeAResoudre.CoefficientsDeLaMatriceDesContraintes;
Probleme->Sens = ProblemeAResoudre.Sens;
Probleme->Sens = ProblemeAResoudre.Sens.data();
Probleme->SecondMembre = ProblemeAResoudre.SecondMembre;

Probleme->AffichageDesTraces = NON_PI;
Expand Down
10 changes: 3 additions & 7 deletions src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* Pr
const size_t szNbVarsint = ProblemeAResoudre->NombreDeVariables * sizeof(int);
const size_t szNbContint = ProblemeAResoudre->NombreDeContraintes * sizeof(int);

ProblemeAResoudre->Sens
= (char*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(char));
ProblemeAResoudre->IndicesDebutDeLigne = (int*)MemAlloc(szNbContint);
ProblemeAResoudre->NombreDeTermesDesLignes = (int*)MemAlloc(szNbContint);
ProblemeAResoudre->Sens.resize(ProblemeAResoudre->NombreDeContraintes);
ProblemeAResoudre->IndicesDebutDeLigne.resize(szNbContint);
ProblemeAResoudre->NombreDeTermesDesLignes.resize(szNbContint);

ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes
= (double*)MemAlloc(NbTermes * sizeof(double));
Expand Down Expand Up @@ -107,9 +106,6 @@ void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* Pr

void OPT_FreeOptimizationData(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre)
{
MemFree(ProblemeAResoudre->Sens);
MemFree(ProblemeAResoudre->IndicesDebutDeLigne);
MemFree(ProblemeAResoudre->NombreDeTermesDesLignes);
MemFree(ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes);
MemFree(ProblemeAResoudre->IndicesColonnes);
MemFree(ProblemeAResoudre->CoutQuadratique);
Expand Down
10 changes: 5 additions & 5 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
solver, ProblemeAResoudre->CoutLineaire, ProblemeAResoudre->NombreDeVariables);
ORTOOLS_ModifierLeVecteurSecondMembre(solver,
ProblemeAResoudre->SecondMembre,
ProblemeAResoudre->Sens,
ProblemeAResoudre->Sens.data(),
ProblemeAResoudre->NombreDeContraintes);
ORTOOLS_CorrigerLesBornes(solver,
ProblemeAResoudre->Xmin,
Expand All @@ -169,7 +169,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
ProbSpx, ProblemeAResoudre->CoutLineaire, ProblemeAResoudre->NombreDeVariables);
SPX_ModifierLeVecteurSecondMembre(ProbSpx,
ProblemeAResoudre->SecondMembre,
ProblemeAResoudre->Sens,
ProblemeAResoudre->Sens.data(),
ProblemeAResoudre->NombreDeContraintes);
}
measure.tick();
Expand All @@ -188,12 +188,12 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo,
Probleme.TypeDeVariable = ProblemeAResoudre->TypeDeVariable;

Probleme.NombreDeContraintes = ProblemeAResoudre->NombreDeContraintes;
Probleme.IndicesDebutDeLigne = ProblemeAResoudre->IndicesDebutDeLigne;
Probleme.NombreDeTermesDesLignes = ProblemeAResoudre->NombreDeTermesDesLignes;
Probleme.IndicesDebutDeLigne = ProblemeAResoudre->IndicesDebutDeLigne.data();
Probleme.NombreDeTermesDesLignes = ProblemeAResoudre->NombreDeTermesDesLignes.data();
Probleme.IndicesColonnes = ProblemeAResoudre->IndicesColonnes;
Probleme.CoefficientsDeLaMatriceDesContraintes
= ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes;
Probleme.Sens = ProblemeAResoudre->Sens;
Probleme.Sens = ProblemeAResoudre->Sens.data();
Probleme.SecondMembre = ProblemeAResoudre->SecondMembre;

Probleme.ChoixDeLAlgorithme = SPX_DUAL;
Expand Down
8 changes: 4 additions & 4 deletions src/solver/optimisation/opt_appel_solveur_quadratique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudr
Probleme.VariableBinaire = (char*)ProblemeAResoudre->CoutsReduits;

Probleme.NombreDeContraintes = ProblemeAResoudre->NombreDeContraintes;
Probleme.IndicesDebutDeLigne = ProblemeAResoudre->IndicesDebutDeLigne;
Probleme.NombreDeTermesDesLignes = ProblemeAResoudre->NombreDeTermesDesLignes;
Probleme.IndicesDebutDeLigne = ProblemeAResoudre->IndicesDebutDeLigne.data();
Probleme.NombreDeTermesDesLignes = ProblemeAResoudre->NombreDeTermesDesLignes.data();
Probleme.IndicesColonnes = ProblemeAResoudre->IndicesColonnes;
Probleme.CoefficientsDeLaMatriceDesContraintes
= ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes;
Probleme.Sens = ProblemeAResoudre->Sens;
Probleme.Sens = ProblemeAResoudre->Sens.data();
Probleme.SecondMembre = ProblemeAResoudre->SecondMembre;

Probleme.AffichageDesTraces = NON_PI;
Expand Down Expand Up @@ -173,4 +173,4 @@ bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudr

return false;
}
}
}
6 changes: 3 additions & 3 deletions src/solver/optimisation/opt_structure_probleme_a_resoudre.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ typedef struct
+ NombreDeContraintesCouplantes
)* NombreDePasDeTempsDUneJournee
+ NombreDePays contraintes de turbine */
char* Sens;
int* IndicesDebutDeLigne;
int* NombreDeTermesDesLignes;
std::string Sens;
std::vector<int> IndicesDebutDeLigne;
std::vector<int> NombreDeTermesDesLignes;
double* CoefficientsDeLaMatriceDesContraintes;
int* IndicesColonnes;
int NombreDeTermesAllouesDansLaMatriceDesContraintes;
Expand Down
2 changes: 1 addition & 1 deletion src/solver/optimisation/post_process_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime
{
auto& cluster = *(i->second);
uint chro = NumeroChroniquesTireesParPays[thread_number_][area.index]
->ThermiqueParPalier[cluster.areaWideIndex];
.ThermiqueParPalier[cluster.areaWideIndex];
auto& matrix = cluster.series->timeSeries;
assert(chro < matrix.width);
auto& column = matrix.entry[chro];
Expand Down
6 changes: 2 additions & 4 deletions src/solver/simulation/adequacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ bool Adequacy::simulationBegin()
return false;
}
}

SIM_InitialisationResultats();
}

if (pProblemesHebdo)
Expand All @@ -121,7 +119,7 @@ bool Adequacy::simplexIsRequired(uint hourInTheYear, uint numSpace) const

for (uint k = 0; k != areaCount; ++k)
{
auto& valgen = *ValeursGenereesParPays[numSpace][k];
auto& valgen = ValeursGenereesParPays[numSpace][k];

double quantity
= pProblemesHebdo[numSpace]->ConsommationsAbattues[j].ConsommationAbattueDuPays[k]
Expand Down Expand Up @@ -308,7 +306,7 @@ bool Adequacy::year(Progression::Task& progression,
{
assert(k < state.resSpilled.width);
assert(j < state.resSpilled.height);
auto& valgen = *ValeursGenereesParPays[numSpace][k];
auto& valgen = ValeursGenereesParPays[numSpace][k];
auto& hourlyResults = pProblemesHebdo[numSpace]->ResultatsHoraires[k];

hourlyResults.TurbinageHoraire[j]
Expand Down
8 changes: 3 additions & 5 deletions src/solver/simulation/common-eco-adq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void RecalculDesEchangesMoyens(Data::Study& study,

for (uint j = 0; j < study.runtime->interconnectionsCount(); ++j)
{
ResultatsParInterconnexion[j]->TransitMoyenRecalculQuadratique[indx]
transitMoyenInterconnexionsRecalculQuadratique[j][indx]
= ntcValues.ValeurDuFlux[j];
}
}
Expand All @@ -130,7 +130,7 @@ void PrepareDataFromClustersInMustrunMode(Data::Study& study, uint numSpace)
if (inAdequacy)
memset(scratchpad.originalMustrunSum, 0, sizeof(double) * HOURS_PER_YEAR);

auto& PtChro = *(NumeroChroniquesTireesParPays[numSpace][i]);
auto& PtChro = NumeroChroniquesTireesParPays[numSpace][i];
double* mrs = scratchpad.mustrunSum;
double* adq = scratchpad.originalMustrunSum;

Expand Down Expand Up @@ -239,9 +239,7 @@ void ComputeFlowQuad(Data::Study& study,
for (uint i = 0; i < (uint)problem.NombreDePasDeTemps; ++i)
{
const uint indx = i + PasDeTempsDebut;
assert(ResultatsParInterconnexion[j]);
ResultatsParInterconnexion[j]->TransitMoyenRecalculQuadratique[indx] = 0;
;
transitMoyenInterconnexionsRecalculQuadratique[j][indx] = 0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/solver/simulation/common-hydro-remix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static bool Remix(const Data::AreaList& areas, PROBLEME_HEBDO& problem, uint num
double bottom = std::numeric_limits<double>::max();
double top = 0;

uint loadTS = NumeroChroniquesTireesParPays[numSpace][index]->Consommation;
uint loadTS = NumeroChroniquesTireesParPays[numSpace][index].Consommation;
auto& load = area.load.series->timeSeries;
assert(load.width > 0);

Expand Down
2 changes: 0 additions & 2 deletions src/solver/simulation/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ bool Economy::simulationBegin()
study.parameters.simplexOptimizationRange,
study.calendar);
}

SIM_InitialisationResultats();
}

if (pProblemesHebdo)
Expand Down
2 changes: 0 additions & 2 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,6 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, unsigned NombreDePasDe

void SIM_DesallocationProblemeHebdo(PROBLEME_HEBDO& problem)
{
auto& study = *Data::Study::Current::Get();

for (uint k = 0; k < problem.NombreDePasDeTemps; k++)
{
delete problem.CorrespondanceVarNativesVarOptim[k];
Expand Down
Loading

0 comments on commit c515839

Please sign in to comment.