Skip to content

Commit 7c07c76

Browse files
37 fortran interface null terminated strings (#41)
* Add c_null_char in new routine; tweaks to use later versions of doxygen. * Add Doxygen filename to profiler_mod; cosmetic tweaks. * Swap intf -> interface. (Cosmetic.) * region -> region_name (cosmetic) * Add assumed size array notation to `interface_profiler_start` `region_name` argument. * Move comment about null termination characters into `@note`. * Routine -> Region. * Add *.md to Doxygen file patterns. * Update CHANGELOG.md Co-authored-by: Andrew Coughtrie <[email protected]>
1 parent 54d2329 commit 7c07c76

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
15/03/2022 PR #5 towards #2: Initial code import. \
1919
08/07/2022 PR #27: Working Fortran (and C) interfaces. \
2020
15/07/2022 PR #30 for #29: Unit testing for Fortran interface. \
21-
04/08/2022 PR #32 for #31: Functionality improvements (walltime, swap to unordered_map, sort entries in output.
21+
04/08/2022 PR #32 for #31: Functionality improvements (walltime, swap to unordered_map, sort entries in output. \
22+
10/08/2022 PR #41 for #37 Add null terminated strings in Fortran interface.

cmake/Doxygen.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function(enable_doxygen)
2121
set(DOXYGEN_JAVADOC_BLOCK NO)
2222
set(DOXYGEN_FULL_PATH_NAMES NO)
2323
set(DOXYGEN_STRIP_CODE_COMMENTS NO)
24+
set(DOXYGEN_FILE_PATTERNS *.c *.cpp *.h *.f90 *.F90 *.md)
25+
set(DOXYGEN_EXTENSION_MAPPING "F90=Fortran")
2426
set(DOXYGEN_HTML_HEADER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/header.html)
2527
set(DOXYGEN_HTML_FOOTER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/footer.html)
2628

src/f/profiler_mod.F90

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,49 @@
55
! under which the code may be used.
66
!-------------------------------------------------------------------------------
77

8+
!> @file profiler_mod.F90
9+
!> @brief Provides Fortran profiler bindings.
10+
811
module profiler_mod
9-
use, intrinsic :: iso_c_binding, only: c_char, c_long, c_double
12+
use, intrinsic :: iso_c_binding, only: c_char, c_long, c_double, c_null_char
1013
implicit none
1114
private
1215

13-
!------------------------------------------------------------------------------
16+
!-----------------------------------------------------------------------------
1417
! Public parameters
15-
!------------------------------------------------------------------------------
18+
!-----------------------------------------------------------------------------
1619

20+
!> The integer kind for region hashes.
1721
integer, public, parameter :: pik = c_long
22+
23+
!> The real kind for region timings.
1824
integer, public, parameter :: prk = c_double
1925

20-
!------------------------------------------------------------------------------
21-
! Public interfaces
22-
!------------------------------------------------------------------------------
26+
!-----------------------------------------------------------------------------
27+
! Public interfaces / subroutines
28+
!-----------------------------------------------------------------------------
2329

2430
public :: profiler_start
2531
public :: profiler_stop
2632
public :: profiler_write
2733
public :: profiler_get_thread0_walltime
2834

35+
!-----------------------------------------------------------------------------
36+
! Interfaces
37+
!-----------------------------------------------------------------------------
38+
2939
interface
3040

31-
subroutine profiler_start(hash_out, name) bind(C, name='c_profiler_start')
32-
import :: c_char, c_long
33-
character(kind=c_char, len=1), intent(in) :: name
34-
integer(kind=c_long), intent(out) :: hash_out
35-
end subroutine profiler_start
41+
subroutine interface_profiler_start(hash_out, region_name) &
42+
bind(C, name='c_profiler_start')
43+
import :: c_char, pik
44+
character(kind=c_char, len=1), intent(in) :: region_name(*)
45+
integer(kind=pik), intent(out) :: hash_out
46+
end subroutine interface_profiler_start
3647

3748
subroutine profiler_stop(hash_in) bind(C, name='c_profiler_stop')
38-
import :: c_long
39-
integer(kind=c_long), intent(in) :: hash_in
49+
import :: pik
50+
integer(kind=pik), intent(in) :: hash_in
4051
end subroutine profiler_stop
4152

4253
subroutine profiler_write() bind(C, name='c_profiler_write')
@@ -45,12 +56,37 @@ end subroutine profiler_write
4556

4657
function profiler_get_thread0_walltime(hash_in) result(walltime) &
4758
bind(C, name='c_get_thread0_walltime')
48-
import :: c_double, c_long
49-
integer(kind=c_long), intent(in) :: hash_in
50-
real(kind=c_double) :: walltime
59+
import :: pik, prk
60+
integer(kind=pik), intent(in) :: hash_in
61+
real(kind=prk) :: walltime
5162
end function profiler_get_thread0_walltime
5263

5364
end interface
5465

66+
!-----------------------------------------------------------------------------
67+
! Contained functions / subroutines
68+
!-----------------------------------------------------------------------------
69+
contains
70+
71+
!> @brief Start profiling a code region.
72+
!> @param [out] hash_out The unique hash for this region.
73+
!> @param [in] region_name The region name.
74+
!> @note Region names need not be null terminated:
75+
!> this routine will add a null termination character.
76+
subroutine profiler_start(hash_out, region_name)
77+
implicit none
78+
79+
!Arguments
80+
character(len=*), intent(in) :: region_name
81+
integer(kind=pik), intent(out) :: hash_out
82+
83+
!Local variables
84+
character(len=len_trim(region_name)+1) :: local_region_name
85+
86+
local_region_name = trim(region_name) // c_null_char
87+
call interface_profiler_start(hash_out, local_region_name)
88+
89+
end subroutine profiler_start
90+
5591
end module profiler_mod
5692

0 commit comments

Comments
 (0)