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

Store the run time (and time at which the run ends) to the output file #692

Merged
merged 2 commits into from
Sep 6, 2024
Merged
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
6 changes: 4 additions & 2 deletions doc/Advanced.tex
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ \section{General Structure of Output File}\label{sec:outputFile}
+-> Version Group
|
+-> buildTime Attribute {1}
+-> runTime Attribute {1}
+-> runStartTime Attribute {1}
+-> runEndTime Attribute {1}
+-> runDuration Attribute {1}
+-> gitBranch Attribute {1}
+-> gitHash Attribute {1}
+-> gitHashDatasets Attribute {1}
Expand Down Expand Up @@ -229,7 +231,7 @@ \subsection{Parameters}

\subsection{Version}

The {\normalfont \ttfamily Version} group contains a record of the \glc\ version used for this model, storing the {\normalfont \scshape Git} commit branch and hash (if the code is being maintained using {\normalfont \scshape Git}, otherwise a value of ``{\normalfont \ttfamily unknown}'' is entered) in the attributes {\normalfont \ttfamily gitBranch} and {\normalfont \ttfamily gitHash} respectively, along with the time at which the executable was built as {\normalfont \ttfamily buildTime}. If the {\normalfont \ttfamily datasets} path is a {\normalfont \scshape Git} repo then the hash of the checked-out commit is stored as {\normalfont \ttfamily gitHashDatasets} (if {\normalfont \ttfamily datasets} is not a {\normalfont \scshape Git} repo then a value of ``{\normalfont \ttfamily unknown}'' is entered instead). Additionally, the time at which the model was run is stored as {\normalfont \ttfamily runTime} and, if the {\normalfont \ttfamily galacticusConfig.xml} file (see \S\ref{sec:ConfigFile}) is present and contains contact details, the name and e-mail address of the person who ran the model are stored as {\normalfont \ttfamily runByName} and {\normalfont \ttfamily runByEmail} respectively.
The {\normalfont \ttfamily Version} group contains a record of the \glc\ version used for this model, storing the {\normalfont \scshape Git} commit branch and hash (if the code is being maintained using {\normalfont \scshape Git}, otherwise a value of ``{\normalfont \ttfamily unknown}'' is entered) in the attributes {\normalfont \ttfamily gitBranch} and {\normalfont \ttfamily gitHash} respectively, along with the time at which the executable was built as {\normalfont \ttfamily buildTime}. If the {\normalfont \ttfamily datasets} path is a {\normalfont \scshape Git} repo then the hash of the checked-out commit is stored as {\normalfont \ttfamily gitHashDatasets} (if {\normalfont \ttfamily datasets} is not a {\normalfont \scshape Git} repo then a value of ``{\normalfont \ttfamily unknown}'' is entered instead). Additionally, the times at which the model run started and eneded are stored as {\normalfont \ttfamily runStartTime} and {\normalfont \ttfamily runEndTime}, with the duration of the run (in seconds) stored as {\normalfont \ttfamily runDuration}. If the {\normalfont \ttfamily galacticusConfig.xml} file (see \S\ref{sec:ConfigFile}) is present and contains contact details, the name and e-mail address of the person who ran the model are stored as {\normalfont \ttfamily runByName} and {\normalfont \ttfamily runByEmail} respectively.

\subsection{Outputs}

Expand Down
50 changes: 44 additions & 6 deletions source/output.version.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ module Output_Versioning
!!{
Implements writing of the version number and run time to the \glc\ output file.
!!}
use, intrinsic :: ISO_C_Binding, only : c_char
use, intrinsic :: ISO_C_Binding, only : c_char, c_size_t
implicit none
private
public :: Version_Output, Version_String, Version
public :: Version_Output, Version_Finalize, Version_String, Version

! Include the automatically generated Git revision number.
include 'output.version.revision.inc'
Expand All @@ -48,6 +48,9 @@ Template for a C function that returns the Git hash of a repo HEAD.
end subroutine repoHeadHash
end interface
#endif

! System clock starting count.
integer(c_size_t) :: countStartClockSystem

contains

Expand Down Expand Up @@ -119,17 +122,20 @@ subroutine Version_Output
type (varying_string) :: hashFileName
#endif

! Record the count of the system clock.
call System_Clock(count=countStartClockSystem)

! Write a UUID for this model.
!$ call hdf5Access%set()
call outputFile%writeAttribute(generate_UUID(4),'UUID')

! Create a group for version information.
runTime =Formatted_Date_and_Time()
versionGroup=outputFile%openGroup('Version','Version and timestamp for this model.')
call versionGroup%writeAttribute( gitHash ,'gitHash' )
call versionGroup%writeAttribute(trim(gitBranch),'gitBranch')
call versionGroup%writeAttribute(trim(buildTime),'buildTime')
call versionGroup%writeAttribute( runTime ,'runTime' )
call versionGroup%writeAttribute( gitHash ,'gitHash' )
call versionGroup%writeAttribute(trim(gitBranch),'gitBranch' )
call versionGroup%writeAttribute(trim(buildTime),'buildTime' )
call versionGroup%writeAttribute( runTime ,'runStartTime')
#ifdef GIT2AVAIL
! Use the git2 library to get the hash of the datasets repo.
call repoHeadHash(char(inputPath(pathTypeDataStatic))//c_null_char,gitHashDatasets)
Expand Down Expand Up @@ -174,5 +180,37 @@ subroutine Version_Output
!$ call hdf5Access%unset()
return
end subroutine Version_Output

!![
<hdfPreCloseTask>
<unitName>Version_Finalize</unitName>
</hdfPreCloseTask>
!!]
subroutine Version_Finalize()
!!{
Output final version information to the main output file.
!!}
use :: Dates_and_Times , only : Formatted_Date_and_Time
use :: IO_HDF5 , only : hdf5Object
use :: HDF5_Access , only : hdf5Access
use :: Output_HDF5 , only : outputFile
use :: ISO_Varying_String, only : varying_string
implicit none
type (hdf5Object ) :: versionGroup
type (varying_string) :: runTime
integer (c_size_t ) :: countEndClockSystem, rateClockSystem
double precision :: timeRunDuration

!$ call hdf5Access%set()
call System_Clock(count=countEndClockSystem,count_rate=rateClockSystem)
runTime =Formatted_Date_and_Time()
timeRunDuration=dble(countEndClockSystem-countStartClockSystem)/dble(rateClockSystem)
versionGroup =outputFile%openGroup('Version')
call versionGroup%writeAttribute(runTime ,'runEndTime' )
call versionGroup%writeAttribute(timeRunDuration,'runDuration')
call versionGroup%close ( )
!$ call hdf5Access%unset()
return
end subroutine Version_Finalize

end module Output_Versioning
Loading