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

Regression Test Heap Optimization: Remove Extinct Result Arrays #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 10 additions & 16 deletions src/CovidSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ Place** Places;
AdminUnit AdUnits[MAX_ADUNITS];
//// Time Series defs:
//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every quantity in results. Mostly used in RecordSample.
//// TSMeanNE and TSVarNE are the mean and variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct time series. TSMean and TSVar are pointers that point to either extinct or non-extinct.
Results* TimeSeries, * TSMean, * TSVar, * TSMeanNE, * TSVarNE, * TSMeanE, * TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar
//// TSMean and TSVar are the mean and variance of non-extinct time series.
Results* TimeSeries, * TSMean, * TSVar; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar
Airport* Airports;
BitmapHeader* bmh;
//added declaration of pointer to events log: ggilani - 10/10/2014
Expand Down Expand Up @@ -351,15 +351,11 @@ int main(int argc, char* argv[])
}

P.NRactual = P.NRactNE;
TSMean = TSMeanNE; TSVar = TSVarNE;
if ((P.DoRecordInfEvents) && (P.RecordInfEventsPerRun == 0))
{
SaveEvents(output_file_base);
}
SaveSummaryResults(output_file_base + ".avNE");
P.NRactual = P.NRactE;
TSMean = TSMeanE; TSVar = TSVarE;
//SaveSummaryResults(output_file_base + ".avE");

Bitmap_Finalise();

Expand Down Expand Up @@ -5138,7 +5134,6 @@ void RecordSample(double t, int n, std::string const& output_file_base)

if (P.OutputBitmap >= 1)
{
TSMean = TSMeanNE; TSVar = TSVarNE;
CaptureBitmap ();
OutputBitmap (0, output_file_base);
}
Expand Down Expand Up @@ -5263,14 +5258,17 @@ void RecordInfTypes(void)
nf = sizeof(Results) / sizeof(double);
if (!P.DoAdUnits) nf -= MAX_ADUNITS; // TODO: This still processes most of the AdUnit arrays; just not the last one
fprintf(stderr, "extinct=%i (%i)\n", (int) TimeSeries[P.NumSamples - 1].extinct, P.NumSamples - 1);
PeakHeightSum += s;
PeakHeightSS += s * s;
PeakTimeSum += t;
PeakTimeSS += t * t;

if (TimeSeries[P.NumSamples - 1].extinct)
{
TSMean = TSMeanE; TSVar = TSVarE; P.NRactE++;
}
else
{
TSMean = TSMeanNE; TSVar = TSVarNE; P.NRactNE++;
P.NRactE++;
return;
}
P.NRactNE++;
lc = -k;

// This calculates sum and sum of squares of entire TimeSeries array
Expand Down Expand Up @@ -5301,10 +5299,6 @@ void RecordInfTypes(void)
}
TSMean[n].t += ((double) n )* P.SampleStep;
}
PeakHeightSum += s;
PeakHeightSS += s * s;
PeakTimeSum += t;
PeakTimeSS += t * t;
}


Expand Down
4 changes: 2 additions & 2 deletions src/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ extern AdminUnit AdUnits[MAX_ADUNITS];

//// Time Series defs:
//// TimeSeries is an array of type results, used to store (unsurprisingly) a time series of every quantity in results. Mostly used in RecordSample.
//// TSMeanNE and TSVarNE are the mean and variance of non-extinct time series. TSMeanE and TSVarE are the mean and variance of extinct time series. TSMean and TSVar are pointers that point to either extinct or non-extinct.
extern Results* TimeSeries, *TSMean, *TSVar, *TSMeanNE, *TSVarNE, *TSMeanE, *TSVarE; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar
//// TSMean and TSVar are the mean and variance of non-extinct time series.
extern Results* TimeSeries, *TSMean, *TSVar; //// TimeSeries used in RecordSample, RecordInfTypes, SaveResults. TSMean and TSVar

extern Airport* Airports;
extern Events* InfEventLog;
Expand Down
38 changes: 8 additions & 30 deletions src/SetupModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,8 @@ void SetupModel(std::string const& density_file, std::string const& out_density_
SetupPopulation(density_file, out_density_file, school_file, reg_demog_file);

TimeSeries = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));
TSMeanE = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));
TSVarE = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));
TSMeanNE = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));
TSVarNE = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));
TSMean = TSMeanE; TSVar = TSVarE;
///// This loops over index l twice just to reset the pointer TSMean from TSMeanE to TSMeanNE (same for TSVar).
int num_in_results = sizeof(Results) / sizeof(double);
for (l = 0; l < 2; l++)
{
for (int i = 0; i < P.NumSamples; i++)
{
double *ts_mean = (double *)&TSMean[i];
double *ts_var = (double *)&TSVar[i];
for (int j = 0; j < num_in_results; j++) ts_mean[j] = ts_var[j] = 0.0;
}
TSMean = TSMeanNE; TSVar = TSVarNE;
}
TSMean = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));
TSVar = (Results*)Memory::xcalloc(P.NumSamples, sizeof(Results));

if (P.DoAdUnits && P.OutputAdUnitAge)
{
Expand Down Expand Up @@ -268,24 +253,18 @@ void SetupModel(std::string const& density_file, std::string const& out_density_
TimeSeries[Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TimeSeries[Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TimeSeries[Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMeanE [Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMeanE [Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMeanE [Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMeanNE[Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMeanNE[Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMeanNE[Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMean[Time].prevInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMean[Time].incInf_age_adunit = new double* [NUM_AGE_GROUPS]();
TSMean[Time].cumInf_age_adunit = new double* [NUM_AGE_GROUPS]();

for (int AgeGroup = 0; AgeGroup < NUM_AGE_GROUPS; AgeGroup++)
{
TimeSeries[Time].prevInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TimeSeries[Time].incInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TimeSeries[Time].cumInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMeanE[Time].prevInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMeanE[Time].incInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMeanE[Time].cumInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMeanNE[Time].prevInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMeanNE[Time].incInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMeanNE[Time].cumInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMean[Time].prevInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMean[Time].incInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
TSMean[Time].cumInf_age_adunit[AgeGroup] = new double[P.NumAdunits]();
}
}
}
Expand Down Expand Up @@ -612,7 +591,6 @@ void SetupModel(std::string const& density_file, std::string const& out_density_
fprintf(stderr, "Reset spatial R0 to 0\n");
}
fprintf(stderr, "LocalBeta = %lg\n", P.LocalBeta);
TSMean = TSMeanNE; TSVar = TSVarNE;
fprintf(stderr, "Calculated approx cell probabilities\n");
for (int i = 0; i < INFECT_TYPE_MASK; i++) inftype_av[i] = 0;
for (int i = 0; i < MAX_COUNTRIES; i++) infcountry_av[i] = infcountry_num[i] = 0;
Expand Down