da_trace_init.inc
References to this file elsewhere.
1 subroutine da_trace_init
2
3 implicit none
4
5 !--------------------------------------------------------------------
6 ! Purpose: Initialise tracing
7 !--------------------------------------------------------------------
8
9 integer :: IOStatus ! I/O return code
10 integer :: Loop1
11 character (len=200) :: TraceFile
12 character(len=200) :: csvname
13 character (len=10) :: temp
14
15 IOStatus = 0
16
17 if (trace_all_pes .OR. myproc == trace_pe) then
18 trace_write = .true.
19 end if
20
21 !-----------------------------------------------------------------
22 ! Open trace output file.
23 !-----------------------------------------------------------------
24
25 if (trace_write .AND. trace_unit /= 0) then
26 if (use_html) then
27 write(unit=temp,fmt='(I10)') myproc
28 TraceFile="trace/"//trim(adjustl(temp))//".html"
29 open (&
30 unit=trace_unit, & ! i:
31 file=trim(tracefile), & ! i:
32 status="replace", & ! i:
33 action="write", & ! i:
34 iostat=iostatus) ! o:
35 else
36 write(unit=temp,fmt='(i10)') myproc
37 tracefile="trace/"//trim(adjustl(temp))//".txt"
38 open (&
39 unit=trace_unit, & ! i:
40 file=trim(tracefile), & ! i:
41 status="replace", & ! i:
42 action="write", & ! i:
43 iostat=IOStatus) ! O:
44 end if
45
46 if (IOStatus /= 0) then
47 call da_error(__FILE__,__LINE__, &
48 (/"Cannot open trace file "//TraceFile/))
49 end if
50 end if
51
52 if (trace_csv .and. rootproc) then
53 write(unit=csvname,fmt='(I10,A)') myproc,'.csv'
54 open(unit=trace_csv_unit,file="trace/"//trim(adjustl(csvname)), &
55 status="replace",iostat=IOStatus)
56 if (IOStatus /= 0) then
57 call da_error(__FILE__,__LINE__,(/"Cannot open "//csvname/))
58 end if
59 end if
60
61 !-----------------------------------------------------------------
62 ! Find out whether to trace memory usage. The Cray routine to check
63 ! memory usage is very slow, so it is best to only switch on memory
64 ! checking if actively required.
65 !-----------------------------------------------------------------
66
67 !-----------------------------------------------------------------
68 ! Set up timing and memory usage
69 !-----------------------------------------------------------------
70
71 do Loop1=1,MaxNoRoutines
72 CPUTimeStart(Loop1) = 0.0
73 ElapsedTimeStart(Loop1) = 0.0
74 ElapsedTime(Loop1) = 0.0
75 ElapsedTimeLocal(Loop1) = 0.0
76 CPUTime(Loop1) = 0.0
77 CPUTimeLocal(Loop1) = 0.0
78 NoCalls(Loop1) = 0
79 NoCallsBody(Loop1) = 0
80 CalledBy(Loop1) = 0
81 MaxHeap(Loop1) = 0
82 TimerNames(Loop1) = ""
83 end do
84
85 Pointer = 0
86 NoRoutines = 0
87
88 call system_clock(&
89 COUNT=BaseElapsedTime)
90
91 call cpu_time(BaseCPUTime)
92
93 ! start trace output here so memory calculations are not distorted
94 ! by IO buffer being grabbed later
95
96 TraceDepth = 0
97
98 if (trace_write) then
99 if (use_html) then
100 write (unit=trace_unit,fmt='(A)') "<html><head><title>Tracing</title></head>"
101 write (unit=trace_unit,fmt='(A)') "<body><h1>Trace Output</h1>"
102 write (unit=trace_unit,fmt='(A)') "<ul>"
103 write (unit=trace_unit,fmt='(A)') "<li><a href=#tree>Calling Tree</a>"
104 write (unit=trace_unit,fmt='(A)') "<li><a href=#local>Local routine timings</a>"
105 write (unit=trace_unit,fmt='(A)') "<li><a href=#overall>Overall routine timings</a>"
106 write (unit=trace_unit,fmt='(A)') "<li><a href=#memory>Memory usage</a>"
107 write (unit=trace_unit,fmt='(A)') "</ul>"
108 write (unit=trace_unit,fmt='(A)') "<a name=tree><h2>Calling Tree</h2></a><pre>"
109 else
110 write (unit=trace_unit,fmt='(A)') "Trace Output"
111 write (unit=trace_unit,fmt='(A)') ""
112 end if
113 end if
114
115 end subroutine da_trace_init
116
117