Skip to content

Commit

Permalink
Merge pull request #492 from galacticusorg/memoryLeakFixes
Browse files Browse the repository at this point in the history
Fix memory leaks
  • Loading branch information
abensonca authored Oct 7, 2023
2 parents 7f2cf52 + 805d384 commit 4a1abeb
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ sub Process_InputParametersValidate {
}
$code .= " call ".$result."%allowedParameters(".$variableName.",'".$source."',.false.)\n";
# Perform the check.
$code .= " if (.not.".$functionClassName."DsblVldtn) call ".$source."%checkParameters(".$variableName.(exists($node->{'directive'}->{'multiParameters'}) ? ",".$multiNames : "").")\n";
$code .= " if (.not.".$functionClassName."DsblVldtn) call ".$source."%checkParameters(allowedParameterNames=".$variableName.(exists($node->{'directive'}->{'multiParameters'}) ? ",allowedMultiParameterNames=".$multiNames : "").")\n";
$code .= " if (allocated(".$variableName.")) deallocate(".$variableName.")\n";
# Insert new code.
my $codeNode =
Expand Down
22 changes: 21 additions & 1 deletion perl/Galacticus/Build/SourceTree/Process/ObjectBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ sub Process_ObjectBuilder {
$defaultXML =~ s/\s*\n\s*//g;
$defaultXML =~ s/\s{2,}/ /g;
$builderCode .= " if (.not.parametersCurrent%isPresent('".$parameterName."')) then\n";
$builderCode .= " parametersDefault=inputParameters(var_str('".$defaultXML."'),allowedParameterNames=['".$parameterName."'],noOutput=.true.)\n";
$builderCode .= " allowedNames_(1)='".$parameterName."'\n";
$builderCode .= " parametersDefault=inputParameters(var_str('".$defaultXML."'),allowedParameterNames=allowedNames_,noOutput=.true.)\n";
$builderCode .= " call parametersDefault%parametersGroupCopy(parametersCurrent)\n";
$builderCode .= " parametersCurrent => parametersDefault\n";
$builderCode .= " parametersDefaultCreated=.true.\n";
Expand Down Expand Up @@ -343,12 +344,31 @@ sub Process_ObjectBuilder {
variables => [ "parametersDefault" ],
attributes => [ "target" ]
},
{
intrinsic => "type" ,
type => "varying_string" ,
variables => [ "allowedNames_" ],
attributes => [ "dimension(1)" ]
},
{
intrinsic => "logical" ,
variables => [ "parametersDefaultCreated" ]
}
);
&Galacticus::Build::SourceTree::Parse::Declarations::AddDeclarations($node->{'parent'},\@declarations);
my $usesNode =
{
type => "moduleUse",
moduleUse =>
{
ISO_Varying_String =>
{
intrinsic => 0,
only => {"varying_string" => 1, "assignment(=)" => 1}
}
}
};
&Galacticus::Build::SourceTree::Parse::ModuleUses::AddUses($node->{'parent'},$usesNode);
# Record that we have added the necessary declarations to the parent.
$node->{'parent'}->{'objectBuilderDefaultDeclarations'} = 1;
}
Expand Down
76 changes: 39 additions & 37 deletions source/intergalactic_medium.state.file.F90
Original file line number Diff line number Diff line change
Expand Up @@ -248,45 +248,47 @@ subroutine fileReadData(self)
class (intergalacticMediumStateFile), intent(inout) :: self
integer :: fileFormatVersion , iRedshift, &
& extrapolationAllowed
type (hdf5Object ) :: file

! Check if data has yet to be read.
if (.not.self%dataRead) then
if (.not.File_Exists(char(self%fileName))) call Error_Report('Unable to find intergalactic medium state file "' //char(self%fileName)//'"'//{introspection:location})
!$ call hdf5Access%set()
! Open the file.
call file%openFile(char(self%fileName),readOnly=.true.)
! Check the file format version of the file.
call file%readAttribute('fileFormat',fileFormatVersion)
if (fileFormatVersion /= fileFormatVersionCurrent) call Error_Report('file format version is out of date'//{introspection:location})
! Check if extrapolation is allowed.
self%extrapolationType=extrapolationTypeAbort
if (file%hasAttribute('extrapolationAllowed')) then
call file%readAttribute('extrapolationAllowed',extrapolationAllowed)
if (extrapolationAllowed /= 0) self%extrapolationType=extrapolationTypeExtrapolate
end if
call file%readAttribute('fileFormat',fileFormatVersion)
! Read the data.
call file%readDataset('redshift' ,self%timeTable )
call file%readDataset('electronFraction' ,self%electronFractionTable )
call file%readDataset('hIonizedFraction' ,self%ionizedHydrogenFractionTable)
call file%readDataset('heIonizedFraction',self%ionizedHeliumFractionTable )
call file%readDataset('matterTemperature',self%temperatureTable )
call file%close ( )
!$ call hdf5Access%unset()
self%redshiftCount=size(self%timeTable)
! Convert redshifts to times.
do iRedshift=1,self%redshiftCount
self%timeTable(iRedshift)=self%cosmologyFunctions_%cosmicTime(self%cosmologyFunctions_%expansionFactorFromRedshift(self%timeTable(iRedshift)))
end do
! Build interpolators.
self%interpolatorElectronFraction =interpolator(self%timeTable,self%electronFractionTable ,extrapolationType=self%extrapolationType)
self%interpolatorTemperature =interpolator(self%timeTable,self%temperatureTable ,extrapolationType=self%extrapolationType)
self%interpolatorIonizedHydrogenFraction=interpolator(self%timeTable,self%ionizedHydrogenFractionTable,extrapolationType=self%extrapolationType)
self%interpolatorIonizedHeliumFraction =interpolator(self%timeTable,self%ionizedHeliumFractionTable ,extrapolationType=self%extrapolationType)
! Flag that data has now been read.
self%dataRead=.true.
end if
if (self%dataRead) return
block
type(hdf5Object) :: file

if (.not.File_Exists(char(self%fileName))) call Error_Report('Unable to find intergalactic medium state file "' //char(self%fileName)//'"'//{introspection:location})
!$ call hdf5Access%set()
! Open the file.
call file%openFile(char(self%fileName),readOnly=.true.)
! Check the file format version of the file.
call file%readAttribute('fileFormat',fileFormatVersion)
if (fileFormatVersion /= fileFormatVersionCurrent) call Error_Report('file format version is out of date'//{introspection:location})
! Check if extrapolation is allowed.
self%extrapolationType=extrapolationTypeAbort
if (file%hasAttribute('extrapolationAllowed')) then
call file%readAttribute('extrapolationAllowed',extrapolationAllowed)
if (extrapolationAllowed /= 0) self%extrapolationType=extrapolationTypeExtrapolate
end if
call file%readAttribute('fileFormat',fileFormatVersion)
! Read the data.
call file%readDataset('redshift' ,self%timeTable )
call file%readDataset('electronFraction' ,self%electronFractionTable )
call file%readDataset('hIonizedFraction' ,self%ionizedHydrogenFractionTable)
call file%readDataset('heIonizedFraction',self%ionizedHeliumFractionTable )
call file%readDataset('matterTemperature',self%temperatureTable )
call file%close ( )
!$ call hdf5Access%unset()
self%redshiftCount=size(self%timeTable)
! Convert redshifts to times.
do iRedshift=1,self%redshiftCount
self%timeTable(iRedshift)=self%cosmologyFunctions_%cosmicTime(self%cosmologyFunctions_%expansionFactorFromRedshift(self%timeTable(iRedshift)))
end do
! Build interpolators.
self%interpolatorElectronFraction =interpolator(self%timeTable,self%electronFractionTable ,extrapolationType=self%extrapolationType)
self%interpolatorTemperature =interpolator(self%timeTable,self%temperatureTable ,extrapolationType=self%extrapolationType)
self%interpolatorIonizedHydrogenFraction=interpolator(self%timeTable,self%ionizedHydrogenFractionTable,extrapolationType=self%extrapolationType)
self%interpolatorIonizedHeliumFraction =interpolator(self%timeTable,self%ionizedHeliumFractionTable ,extrapolationType=self%extrapolationType)
! Flag that data has now been read.
self%dataRead=.true.
end block
return
end subroutine fileReadData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ function massFunctionStellarBernardi2013SDSSConstructorInternal(cosmologyFunctio
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_"/>
Expand All @@ -312,7 +313,8 @@ subroutine massFunctionStellarBernardi2013SDSSDestructor(self)
type(outputAnalysisMassFunctionStellarBernardi2013SDSS), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarBernardi2013SDSSDestructor
5 changes: 3 additions & 2 deletions source/output.analyses.mass_function_stellar.GAMA.F90
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function massFunctionStellarBaldry2012GAMAConstructorInternal(cosmologyFunctions
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_" />
Expand All @@ -356,7 +356,8 @@ subroutine massFunctionStellarBaldry2012GAMADestructor(self)
type(outputAnalysisMassFunctionStellarBaldry2012GAMA), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarBaldry2012GAMADestructor
4 changes: 3 additions & 1 deletion source/output.analyses.mass_function_stellar.PRIMUS.F90
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ function massFunctionStellarPRIMUSConstructorInternal(cosmologyFunctions_,gravit
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_"/>
Expand All @@ -383,7 +384,8 @@ subroutine massFunctionStellarPRIMUSDestructor(self)
type(outputAnalysisMassFunctionStellarPRIMUS), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarPRIMUSDestructor
4 changes: 3 additions & 1 deletion source/output.analyses.mass_function_stellar.SDSS.F90
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ function massFunctionStellarSDSSConstructorInternal(cosmologyFunctions_,gravitat
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_"/>
Expand All @@ -339,7 +340,8 @@ subroutine massFunctionStellarSDSSDestructor(self)
type(outputAnalysisMassFunctionStellarSDSS), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarSDSSDestructor
4 changes: 3 additions & 1 deletion source/output.analyses.mass_function_stellar.UKIDSS_UDS.F90
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function massFunctionStellarUKIDSSUDSConstructorInternal(cosmologyFunctions_,gra
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_"/>
Expand All @@ -361,7 +362,8 @@ subroutine massFunctionStellarUKIDSSUDSDestructor(self)
type(outputAnalysisMassFunctionStellarUKIDSSUDS), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarUKIDSSUDSDestructor
3 changes: 2 additions & 1 deletion source/output.analyses.mass_function_stellar.ULTRAVISTA.F90
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ subroutine massFunctionStellarULTRAVISTADestructor(self)
type(outputAnalysisMassFunctionStellarULTRAVISTA), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarULTRAVISTADestructor
4 changes: 3 additions & 1 deletion source/output.analyses.mass_function_stellar.VIPERS.F90
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function massFunctionStellarVIPERSConstructorInternal(cosmologyFunctions_,gravit
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_"/>
Expand All @@ -361,7 +362,8 @@ subroutine massFunctionStellarVIPERSDestructor(self)
type(outputAnalysisMassFunctionStellarVIPERS), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarVIPERSDestructor
4 changes: 3 additions & 1 deletion source/output.analyses.mass_function_stellar.ZFOURGE.F90
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ function massFunctionStellarZFOURGEConstructorInternal(cosmologyFunctions_,gravi
<objectDestructor name="galacticFilter_" />
<objectDestructor name="cosmologyParametersData" />
<objectDestructor name="cosmologyFunctionsData" />
<objectDestructor name="outputAnalysisPropertyOperator_" />
<objectDestructor name="outputAnalysisDistributionOperator_" />
<objectDestructor name="outputAnalysisDistributionOperatorGrvtnlLnsng_" />
<objectDestructor name="outputAnalysisDistributionOperatorRandomErrorPlynml_"/>
Expand All @@ -394,7 +395,8 @@ subroutine massFunctionStellarZFOURGEDestructor(self)
type(outputAnalysisMassFunctionStellarZFOURGE), intent(inout) :: self

!![
<objectDestructor name="self%galacticStructure_"/>
<objectDestructor name="self%galacticStructure_" />
<objectDestructor name="self%gravitationalLensing_"/>
!!]
return
end subroutine massFunctionStellarZFOURGEDestructor
Loading

1 comment on commit 4a1abeb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Milky Way model benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.10.

Benchmark suite Current: 4a1abeb Previous: 7f2cf52 Ratio
Milky Way model - Likelihood - localGroupMassMetallicityRelation 3.36461935373672 -logℒ 3.04384072964081 -logℒ 1.11

This comment was automatically generated by workflow using github-action-benchmark.

CC: @abensonca

Please sign in to comment.