Skip to content

Commit

Permalink
deal with a list of memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuxiang Qin committed Nov 16, 2023
1 parent 1804b4e commit 48f4302
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/py21cmfast/src/IonisationBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ LOG_SUPER_DEBUG("erfc interpolation done");
log10_overdense_spline_SFR = calloc(NSFR_low,sizeof(double));
Overdense_spline_SFR = calloc(NSFR_high,sizeof(float));

log10_Nion_spline = calloc(NSFR_low,sizeof(float));
Nion_spline = calloc(NSFR_high,sizeof(float));

if (flag_options->USE_MINI_HALOS){
prev_log10_overdense_spline_SFR = calloc(NSFR_low,sizeof(double));
prev_Overdense_spline_SFR = calloc(NSFR_high,sizeof(float));
Expand All @@ -305,6 +302,11 @@ LOG_SUPER_DEBUG("erfc interpolation done");
prev_log10_Nion_spline_MINI = calloc(NSFR_low*NMTURN,sizeof(float));
prev_Nion_spline_MINI = calloc(NSFR_high*NMTURN,sizeof(float));
}
else{
log10_Nion_spline = calloc(NSFR_low,sizeof(float));
Nion_spline = calloc(NSFR_high,sizeof(float));

}
}

if (flag_options->USE_MINI_HALOS){
Expand Down Expand Up @@ -1681,6 +1683,12 @@ LOG_SUPER_DEBUG("freed fftw boxes");
freeSigmaMInterpTable();
}

if(!flag_options->USE_MASS_DEPENDENT_ZETA && !INIT_ERFC_INTERPOLATION) {
free(ERFC_VALS);
free(ERFC_VALS_DIFF);
INIT_ERFC_INTERPOLATION = 1;
}

free(overdense_int_boundexceeded_threaded);

LOG_DEBUG("finished!\n");
Expand Down
3 changes: 3 additions & 0 deletions src/py21cmfast/src/SpinTemperatureBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,9 @@ void free_TsCalcBoxes(struct UserParams *user_params, struct FlagOptions *flag_o
}
free(SFRD_z_high_table);
}

if(flag_options->USE_MINI_HALOS)
free(log10_Mcrit_LW_ave_list);

free(del_fcoll_Rct);
free(dxheat_dt_box);
Expand Down
5 changes: 5 additions & 0 deletions src/py21cmfast/src/UsefulFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ void inspectInitialConditions(struct InitialConditions *x, int print_pid, int pr
printf("%s\t\tlowres_vx_2LPT: ", pid);
print_corners_real(x->lowres_vx_2LPT, HII_DIM, NCF);
}
free(pid);
}


Expand Down Expand Up @@ -770,6 +771,7 @@ void inspectPerturbedField(struct PerturbedField *x, int print_pid, int print_co
printf("%s\t\tvelocity: ", pid);
print_corners_real(x->velocity, HII_DIM, NCF);
}
free(pid);

}

Expand Down Expand Up @@ -812,6 +814,7 @@ void inspectTsBox(struct TsBox *x, int print_pid, int print_corners, int print_f
printf("%s\t\tTk_box : ", pid);
print_corners_real(x->Tk_box, HII_DIM, NCF);
}
free(pid);
}

void inspectIonizedBox(struct IonizedBox *x, int print_pid, int print_corners, int print_first, int HII_DIM, float NCF){
Expand Down Expand Up @@ -861,6 +864,7 @@ void inspectIonizedBox(struct IonizedBox *x, int print_pid, int print_corners, i
printf("%s\t\tNrec_box : ", pid);
print_corners_real(x->Nrec_box, HII_DIM, NCF);
}
free(pid);
}

void inspectBrightnessTemp(struct BrightnessTemp *x, int print_pid, int print_corners, int print_first, int HII_DIM, float NCF){
Expand All @@ -884,6 +888,7 @@ void inspectBrightnessTemp(struct BrightnessTemp *x, int print_pid, int print_co
printf("%s\t\tbrightness_temp: ",pid);
print_corners_real(x->brightness_temp, HII_DIM, NCF);
}
free(pid);
}
double atomic_cooling_threshold(float z){
return TtoM(z, 1e4, 0.59);
Expand Down
13 changes: 10 additions & 3 deletions src/py21cmfast/src/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static gsl_spline *erfc_spline;

float calibrated_NF_min;

double *deltaz, *deltaz_smoothed, *NeutralFractions, *z_Q, *Q_value, *nf_vals, *z_vals;
double *deltaz, *deltaz_smoothed, *NeutralFractions, *z_Q, *Q_value, *nf_vals, *z_vals, *Q_z, *z_value;
int N_NFsamples,N_extrapolated, N_analytic, N_calibrated, N_deltaz;

bool initialised_ComputeLF = false;
Expand Down Expand Up @@ -1988,6 +1988,11 @@ int ComputeLF(int nbins, struct UserParams *user_params, struct CosmoParams *cos
if (isinf(log10phi[i + i_z*nbins]) || isnan(log10phi[i + i_z*nbins]) || log10phi[i + i_z*nbins] < -30.)
log10phi[i + i_z*nbins] = -30.;
}
gsl_spline_free (deriv_spline);
gsl_interp_accel_free(deriv_spline_acc);
free(lnM_temp);
free(deriv_temp);
free(deriv);
}
}

Expand Down Expand Up @@ -3605,8 +3610,8 @@ int InitialisePhotonCons(struct UserParams *user_params, struct CosmoParams *cos
Qmax = Q_value[0];

// initialise interpolation z as a function of Q
double *Q_z = calloc(nbin,sizeof(double));
double *z_value = calloc(nbin,sizeof(double));
Q_z = calloc(nbin,sizeof(double));
z_value = calloc(nbin,sizeof(double));

z_at_Q_spline_acc = gsl_interp_accel_alloc ();
z_at_Q_spline = gsl_spline_alloc (gsl_interp_linear, nbin);
Expand Down Expand Up @@ -4159,6 +4164,8 @@ void z_at_Q(double Q, double *splined_value){
}

void free_Q_value() {
free(z_value);
free(Q_z);
gsl_spline_free (Q_at_z_spline);
gsl_interp_accel_free (Q_at_z_spline_acc);
gsl_spline_free (z_at_Q_spline);
Expand Down

0 comments on commit 48f4302

Please sign in to comment.