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

37 fortran interface null terminated strings #41

Merged
merged 9 commits into from
Aug 10, 2022
2 changes: 2 additions & 0 deletions cmake/Doxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function(enable_doxygen)
set(DOXYGEN_JAVADOC_BLOCK NO)
set(DOXYGEN_FULL_PATH_NAMES NO)
set(DOXYGEN_STRIP_CODE_COMMENTS NO)
set(DOXYGEN_FILE_PATTERNS *.c *.cpp *.h *.f90 *.F90 )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because you're now defining the specific file extensions Doxygen no longer picks up the .md file used for the front page, adding *.md to this list should fix this though it will add the directory to the list of files shown in the Doxygen pages even if here isn't anything there.

set(DOXYGEN_EXTENSION_MAPPING "F90=Fortran")
set(DOXYGEN_HTML_HEADER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/header.html)
set(DOXYGEN_HTML_FOOTER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/footer.html)

Expand Down
67 changes: 51 additions & 16 deletions src/f/profiler_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,49 @@
! under which the code may be used.
!-------------------------------------------------------------------------------

!> @file profiler_mod.F90
!> @brief Provides Fortran profiler bindings.

module profiler_mod
use, intrinsic :: iso_c_binding, only: c_char, c_long, c_double
use, intrinsic :: iso_c_binding, only: c_char, c_long, c_double, c_null_char
implicit none
private

!------------------------------------------------------------------------------
!-----------------------------------------------------------------------------
! Public parameters
!------------------------------------------------------------------------------
!-----------------------------------------------------------------------------

!> The integer kind for region hashes.
integer, public, parameter :: pik = c_long

!> The real kind for region timings.
integer, public, parameter :: prk = c_double
bencopl marked this conversation as resolved.
Show resolved Hide resolved

!------------------------------------------------------------------------------
! Public interfaces
!------------------------------------------------------------------------------
!-----------------------------------------------------------------------------
! Public interfaces / subroutines
!-----------------------------------------------------------------------------

public :: profiler_start
public :: profiler_stop
public :: profiler_write
public :: profiler_get_thread0_walltime

!-----------------------------------------------------------------------------
! Interfaces
!-----------------------------------------------------------------------------

interface

subroutine profiler_start(hash_out, name) bind(C, name='c_profiler_start')
import :: c_char, c_long
character(kind=c_char, len=1), intent(in) :: name
integer(kind=c_long), intent(out) :: hash_out
end subroutine profiler_start
subroutine interface_profiler_start(hash_out, region_name) &
bind(C, name='c_profiler_start')
import :: c_char, pik
character(kind=c_char, len=1), intent(in) :: region_name
bencopl marked this conversation as resolved.
Show resolved Hide resolved
integer(kind=pik), intent(out) :: hash_out
end subroutine interface_profiler_start

subroutine profiler_stop(hash_in) bind(C, name='c_profiler_stop')
import :: c_long
integer(kind=c_long), intent(in) :: hash_in
import :: pik
integer(kind=pik), intent(in) :: hash_in
end subroutine profiler_stop

subroutine profiler_write() bind(C, name='c_profiler_write')
Expand All @@ -45,12 +56,36 @@ end subroutine profiler_write

function profiler_get_thread0_walltime(hash_in) result(walltime) &
bind(C, name='c_get_thread0_walltime')
import :: c_double, c_long
integer(kind=c_long), intent(in) :: hash_in
real(kind=c_double) :: walltime
import :: pik, prk
integer(kind=pik), intent(in) :: hash_in
real(kind=prk) :: walltime
end function profiler_get_thread0_walltime

end interface

!-----------------------------------------------------------------------------
! Contained functions / subroutines
!-----------------------------------------------------------------------------
contains

!> @brief Start a profiled region, taking care to add a C null character to
Copy link
Collaborator

Choose a reason for hiding this comment

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

The @brief here should be for the user, describing that the subroutine is adding a null character doesn't seem right for the API documentation. A normal comment inside the subroutine would probably be better i think.

Copy link
Collaborator Author

@mo-mglover mo-mglover Aug 9, 2022

Choose a reason for hiding this comment

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

I'll move it into a @note. I think it's important that it mentions the null character on the tin: it tells the Fortran programmer that they need not add one explicitly in higher-level code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good to me.

!> the end of the region name.
!> @param [out] hash_out The unique hash for this region.
!> @param [in] region_name The region name.
subroutine profiler_start(hash_out, region_name)
implicit none

!Arguments
character(len=*), intent(in) :: region_name
integer(kind=pik), intent(out) :: hash_out

!Local variables
character(len=len_trim(region_name)+1) :: local_region_name

local_region_name = trim(region_name) // c_null_char
call interface_profiler_start(hash_out, local_region_name)

end subroutine profiler_start

end module profiler_mod