perflib.F90 1.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
PROGRAM tperf_context
!$ use omp_lib, only : omp_get_thread_num
  IMPLICIT NONE

  INTEGER, PARAMETER :: N_ITERATIONS=1000
  INTEGER :: ii
  REAL(8) :: pi(N_ITERATIONS), uu

  INTEGER, PARAMETER:: SZ=N_ITERATIONS
  REAL(8) :: a(SZ), b(SZ)
  REAL(8) :: inc_time,inc_MFlops


!$omp parallel
!$  print *, 'This message must appear for each thread:', omp_get_thread_num()
!$omp end parallel

  Call perfinit
  Call perfon ('tperf')
  call perf_context_start("first context");
  Call perfon ('calc')
  !$omp parallel do
  DO ii=1, N_ITERATIONS
     call calc (pi)
  Enddo
  Call perfoff

  DO ii=1, N_ITERATIONS
     call calc(pi)
  END DO
  CALL perf_context_end()

  Call perfon ('random')
  Call random_number(a)
  Call random_number(b)
  Call perfoff

  CALL perf_context_start("context 2");
  Call perfon ('calc')
  Do ii=1, N_ITERATIONS
     uu = calc_nochmal(a, b)
  Enddo
  Call perfoff
  CALL perf_context_end();

! print *, 'Call perfout'
  Call perfoff
  inc_time = 0.0_8
  inc_MFlops = 0.0_8
  CALL perf_get('tperf',inc_time,inc_MFlops)
  WRITE(*,"(A,2F8.3)") "tperf ",inc_time,inc_MFlops
  !CALL perf_reset('calc')

  Call perfout ('tperf')
  ! print *, 'Return perfout'

CONTAINS

  FUNCTION calc_nochmal (a, b)
    REAL(8) :: calc_nochmal
    REAL(8) :: a(:), b(:)

    calc_nochmal = SUM (a * b)
  END FUNCTION calc_nochmal

  SUBROUTINE calc (p_pi)
    INTEGER:: ii
    REAL(8):: p_pi(:)

    DO ii=1, SIZE(p_pi)
       p_pi(ii) = SIN(REAL(ii))*SQRT(REAL(ii))
    ENDDO
  END SUBROUTINE calc
END PROGRAM tperf_context