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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
15/03/2022 PR #5 towards #2: Initial code import. \
08/07/2022 PR #27: Working Fortran (and C) interfaces. \
15/07/2022 PR #30 for #29: Unit testing for Fortran interface. \
04/08/2022 PR #32 for #31: Functionality improvements (walltime, swap to unordered_map, sort entries in output.
04/08/2022 PR #32 for #31: Functionality improvements (walltime, swap to unordered_map, sort entries in output. \
10/08/2022 PR #41 for #37 Add null terminated strings in Fortran interface.
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 *.md)
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
68 changes: 52 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(*)
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,37 @@ 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 profiling a code region.
!> @param [out] hash_out The unique hash for this region.
!> @param [in] region_name The region name.
!> @note Region names need not be null terminated:
!> this routine will add a null termination character.
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