ftimings_value.F90 3.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
! Copyright 2014 Lorenz Hüdepohl
!
! This file is part of ftimings.
!
! ftimings is free software: you can redistribute it and/or modify
! it under the terms of the GNU Lesser General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! ftimings is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU Lesser General Public License for more details.
!
! You should have received a copy of the GNU Lesser General Public License
! along with ftimings.  If not, see <http://www.gnu.org/licenses/>.

18
19
20
21
#ifdef HAVE_CONFIG_H
#include "config-f90.h"
#endif

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
22
!> \private
23
24
25
26
27
28
module ftimings_value
  use ftimings_type
  implicit none
  public

  type value_t
29
    integer(kind=C_INT64_T) :: micros = 0         ! microseconds spent in this node
30
    integer(kind=C_LONG) :: virtualmem = 0        ! newly created virtual memory
31
32
    integer(kind=C_LONG) :: maxrsssize = 0            ! newly used max. resident mem ("high water mark")

33
    integer(kind=C_LONG) :: rsssize = 0           ! newly used resident memory
34

35
    integer(kind=C_LONG_LONG) :: flop_count = 0   ! floating point operations done in this node
36
37
    integer(kind=C_INT64_T) :: mem_reads = 0          ! bytes read from DRAM
    integer(kind=C_INT64_T) :: mem_writes = 0         ! bytes written to DRAM
38
39
40
41
42
43
44
45
46
47
48
  end type

  interface operator(+)
    module procedure value_add
  end interface

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

49
50
  type(value_t), parameter :: null_value = value_t(micros = 0, &
                                                   rsssize = 0, &
51
                                                   virtualmem = 0, &
52
                                                   maxrsssize = 0, &
53
                                                   flop_count = 0)
54
55
56
57
58
59
60

  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
61
    c%rsssize = a%rsssize + b%rsssize
62
    c%virtualmem = a%virtualmem + b%virtualmem
63
    c%maxrsssize = a%maxrsssize + b%maxrsssize
64
65
#ifdef HAVE_LIBPAPI
    c%flop_count = a%flop_count + b%flop_count
66
67
68
69
#endif
#ifdef HAVE_PERF
    c%mem_reads = a%mem_reads + b%mem_reads
    c%mem_writes = a%mem_writes + b%mem_writes
70
71
72
73
74
75
76
#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
77
    c%rsssize = a%rsssize - b%rsssize
78
    c%virtualmem = a%virtualmem - b%virtualmem
79
    c%maxrsssize = a%maxrsssize - b%maxrsssize
80
81
#ifdef HAVE_LIBPAPI
    c%flop_count = a%flop_count - b%flop_count
82
83
84
85
#endif
#ifdef HAVE_PERF
    c%mem_reads = a%mem_reads - b%mem_reads
    c%mem_writes = a%mem_writes - b%mem_writes
86
87
88
89
90
91
92
#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
93
    neg_a%rsssize = - a%rsssize
94
    neg_a%virtualmem = - a%virtualmem
95
    neg_a%maxrsssize = - a%maxrsssize
96
97
#ifdef HAVE_LIBPAPI
    neg_a%flop_count = - a%flop_count
98
99
100
101
#endif
#ifdef HAVE_PERF
    neg_a%mem_reads = - a%mem_reads
    neg_a%mem_writes = - a%mem_writes
102
103
104
#endif
  end function
end module