Newer
Older
struct Timings Cpu;
enum TimeMarks mark;
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
77
78
char TimeMarkDescr[CPU_LASTENTRY][20] = {
"Solver ",
"Main ",
};
void init_timing()
{
long i;
for (i = 0; i < CPU_LASTENTRY; i++) {
Cpu.Total[i] = 0;
Cpu.Start[i] = -1;
}
Cpu.Zero = get_current_time();
return;
}
void finish_timing()
{
long mark = 0;
double myTime = 0, timeTotal = 0;
if (ThisTask.Rank == 0) {
fprintf(stdout, "\n Timing Statistics [s] on <%d> CPUs : \n"
"----------------------------\n", ThisTask.NTask);
}
for (mark = 0; mark < CPU_LASTENTRY; mark++) {
myTime = Cpu.Total[mark];
timeTotal += Cpu.Total[mark];
if (ThisTask.Rank == 0)
fprintf(stdout, "%s %g \n",
TimeMarkDescr[mark], myTime);
}
if (ThisTask.Rank == 0) {
fprintf(stdout, "----------------------------\n"
"Total %g \n",
timeTotal);
}
if (ThisTask.Rank == 0)
fprintf(stdout, "\n");
return;
}
void start_timing(enum TimeMarks mark)
{
if (Cpu.Start[mark] > 0) {
fprintf(stderr, "Timing for Mark %i already running \n",
(int)mark);
} else {
Cpu.Start[mark] = get_current_time();
}
return;
}
void stop_timing(enum TimeMarks mark)
{
if (Cpu.Start[mark] < 0) {
fprintf(stderr, "Timing for Mark %i wasn't started \n",
(int)mark);
} else {
Cpu.Total[mark] += get_current_time() - Cpu.Start[mark];
}
return;
}
double get_current_time()
{
return MPI_Wtime();
}