ftimings_value.F90 3.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifdef HAVE_CONFIG_H
#include "config-f90.h"
#endif

module ftimings_value
  use ftimings_type
  implicit none
  public

  type value_t
    integer(kind=C_INT64_T) :: micros = 0          ! Cumulative microseconds spent in this node
12
    integer(kind=C_LONG) :: rsssize = 0
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    integer(kind=C_LONG_LONG) :: flop_count = 0    ! Cumulative floating point operations done in this node
    contains
      procedure, pass :: print => print_value
  end type

  interface operator(+)
    module procedure value_add
  end interface

  interface operator(-)
    module procedure value_minus
    module procedure value_inverse
  end interface

27
28
29
  type(value_t), parameter :: null_value = value_t(micros = 0, &
                                                   rsssize = 0, &
                                                   flop_count = 0)
30
31
32
33
34
35
36

  contains

  pure elemental function value_add(a,b) result(c)
    class(value_t), intent(in) :: a, b
    type(value_t) :: c
    c%micros = a%micros + b%micros
37
    c%rsssize = a%rsssize + b%rsssize
38
39
40
41
42
43
44
45
46
#ifdef HAVE_LIBPAPI
    c%flop_count = a%flop_count + b%flop_count
#endif
  end function

  pure elemental function value_minus(a,b) result(c)
    class(value_t), intent(in) :: a, b
    type(value_t) :: c
    c%micros = a%micros - b%micros
47
    c%rsssize = a%rsssize - b%rsssize
48
49
50
51
52
53
54
55
56
#ifdef HAVE_LIBPAPI
    c%flop_count = a%flop_count - b%flop_count
#endif
  end function

  pure elemental function value_inverse(a) result(neg_a)
    class(value_t), intent(in) :: a
    type(value_t) :: neg_a
    neg_a%micros = - a%micros
57
    neg_a%rsssize = - a%rsssize
58
59
60
61
62
#ifdef HAVE_LIBPAPI
    neg_a%flop_count = - a%flop_count
#endif
  end function

63
64
65
  subroutine print_value(self, indent_level, &
        print_memory, print_flop_count, print_flop_rate, &
        label, total, unit)
66
67
    class(value_t), intent(in) :: self
    integer, intent(in) :: indent_level
68
69
    logical, intent(in) :: print_memory
    logical, intent(in) :: print_flop_count, print_flop_rate
70
71
    character(len=name_length), intent(in) :: label
    type(value_t), intent(in) :: total
72
73
    integer, intent(in) :: unit

74
75
    character(len=64) :: format_spec

76
    write(format_spec,'("(",i0,"x,""|_ "",a",i0,",2x,f12.6,1x,f12.3)")') indent_level * 2 + 1, name_length
77
    write(unit,format_spec,advance='no') &
78
79
      label, &
      real(self%micros, kind=rk) * 1e-6_rk, &
80
      real(self%micros, kind=rk) / real(total%micros, kind=rk)
81

82
83
84
    if (print_memory) then
      write(unit,'(1x,a12)',advance='no') &
        nice_format(real(self%rsssize, kind=C_DOUBLE))
85
    endif
86
87
88
89
90
91
92
    if (print_flop_count) then
      write(unit,'(1x,f12.2)',advance='no') real(self%flop_count, kind=rk) / 1e6_rk
    endif
    if (print_flop_rate) then
      write(unit,'(1x,f12.2)',advance='no') real(self%flop_count, kind=rk) / self%micros
    endif

93
    write(unit,'(a)') ""
94
95
  end subroutine

96
  pure elemental function nice_format(flops) result(string)
97
    real(kind=C_DOUBLE), intent(in) :: flops
98
    character(len=12) :: string
99
100
101
102
103
104
105
106
    real(kind=C_DOUBLE), parameter :: &
        kibi = 2.0_C_DOUBLE**10, &
        mebi = 2.0_C_DOUBLE**20, &
        gibi = 2.0_C_DOUBLE**30, &
        tebi = 2.0_C_DOUBLE**40, &
        pebi = 2.0_C_DOUBLE**50

    if (abs(flops) >= pebi) then
107
      write(string,'(es12.1)') flops
108
    else if (abs(flops) >= tebi) then
109
      write(string,'(f9.1,'' Ti'')') flops / tebi
110
    else if (abs(flops) >= gibi) then
111
      write(string,'(f9.1,'' Gi'')') flops / gibi
112
    else if (abs(flops) >= mebi) then
113
      write(string,'(f9.1,'' Mi'')') flops / mebi
114
    else if (abs(flops) >= kibi) then
115
      write(string,'(f9.1,'' ki'')') flops / kibi
116
    else
117
      write(string,'(f9.1,''  '')') flops
118
119
120
121
    endif
  end function

end module