1 subroutine da_trace_init
5 !--------------------------------------------------------------------
6 ! Purpose: Initialise tracing
7 !--------------------------------------------------------------------
9 integer :: IOStatus ! I/O return code
11 character (len=200) :: TraceFile
12 character(len=200) :: csvname
13 character (len=10) :: temp
17 if (trace_all_pes .OR. myproc == trace_pe) then
21 !-----------------------------------------------------------------
22 ! Open trace output file.
23 !-----------------------------------------------------------------
25 if (trace_write .AND. trace_unit /= 0) then
27 write(unit=temp,fmt='(I10)') myproc
28 TraceFile="trace/"//trim(adjustl(temp))//".html"
30 unit=trace_unit, & ! i:
31 file=trim(tracefile), & ! i:
32 status="replace", & ! i:
33 action="write", & ! i:
36 write(unit=temp,fmt='(i10)') myproc
37 tracefile="trace/"//trim(adjustl(temp))//".txt"
39 unit=trace_unit, & ! i:
40 file=trim(tracefile), & ! i:
41 status="replace", & ! i:
42 action="write", & ! i:
46 if (IOStatus /= 0) then
47 call da_error(__FILE__,__LINE__, &
48 (/"Cannot open trace file "//TraceFile/))
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/))
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 !-----------------------------------------------------------------
67 !-----------------------------------------------------------------
68 ! Set up timing and memory usage
69 !-----------------------------------------------------------------
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
77 CPUTimeLocal(Loop1) = 0.0
79 NoCallsBody(Loop1) = 0
82 TimerNames(Loop1) = ""
89 COUNT=BaseElapsedTime)
91 call cpu_time(BaseCPUTime)
93 ! start trace output here so memory calculations are not distorted
94 ! by IO buffer being grabbed later
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>"
110 write (unit=trace_unit,fmt='(A)') "Trace Output"
111 write (unit=trace_unit,fmt='(A)') ""
115 end subroutine da_trace_init