5
5
! under which the code may be used.
6
6
!- ------------------------------------------------------------------------------
7
7
8
+ ! > @file profiler_mod.F90
9
+ ! > @brief Provides Fortran profiler bindings.
10
+
8
11
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
10
13
implicit none
11
14
private
12
15
13
- !- -----------------------------------------------------------------------------
16
+ !- ----------------------------------------------------------------------------
14
17
! Public parameters
15
- !- -----------------------------------------------------------------------------
18
+ !- ----------------------------------------------------------------------------
16
19
20
+ ! > The integer kind for region hashes.
17
21
integer , public , parameter :: pik = c_long
22
+
23
+ ! > The real kind for region timings.
18
24
integer , public , parameter :: prk = c_double
19
25
20
- !- -----------------------------------------------------------------------------
21
- ! Public interfaces
22
- !- -----------------------------------------------------------------------------
26
+ !- ----------------------------------------------------------------------------
27
+ ! Public interfaces / subroutines
28
+ !- ----------------------------------------------------------------------------
23
29
24
30
public :: profiler_start
25
31
public :: profiler_stop
26
32
public :: profiler_write
27
33
public :: profiler_get_thread0_walltime
28
34
35
+ !- ----------------------------------------------------------------------------
36
+ ! Interfaces
37
+ !- ----------------------------------------------------------------------------
38
+
29
39
interface
30
40
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
36
47
37
48
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
40
51
end subroutine profiler_stop
41
52
42
53
subroutine profiler_write () bind(C, name= ' c_profiler_write' )
@@ -45,12 +56,37 @@ end subroutine profiler_write
45
56
46
57
function profiler_get_thread0_walltime (hash_in ) result(walltime) &
47
58
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
51
62
end function profiler_get_thread0_walltime
52
63
53
64
end interface
54
65
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
+
55
91
end module profiler_mod
56
92
0 commit comments