-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathTestBase.chpl
More file actions
128 lines (101 loc) · 3.08 KB
/
TestBase.chpl
File metadata and controls
128 lines (101 loc) · 3.08 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
public use Time;
public use CommDiagnostics;
public use IO;
public use ServerConfig;
public use ServerErrorStrings;
public use MultiTypeSymEntry;
public use MultiTypeSymbolTable;
public use SymArrayDmap;
public use SegmentedString;
public use RandArray;
public use AryUtil as AryUtil;
// Diag helpers (timers, comm diags, etc.)
config var printTimes = true;
config var printDiags = false;
config var printDiagsSum = false;
// Don't gather comm diags by default, they have a non-trivial perf overhead
const dfltGatherDiags = printDiags || printDiagsSum;
proc byteToMB(b) {
return b / 1024 / 1024;
}
record CommDiagSummary {
const GETS, PUTS, ONS: uint;
}
record Diags {
var T: stopwatch;
var elapsedTime: real;
var gatherDiags = dfltGatherDiags;
var D: [LocaleSpace] commDiagnostics;
proc init() {
init this;
resetCommDiagnostics();
D = getCommDiagnostics();
}
proc start() {
if gatherDiags then startCommDiagnostics();
T.start();
}
proc stop(param name="", printTime=printTimes, printDiag=printDiags,
printDiagSum=printDiagsSum) {
T.stop();
if gatherDiags then stopCommDiagnostics();
elapsedTime = T.elapsed();
if gatherDiags then D = getCommDiagnostics();
T.clear();
if gatherDiags then resetCommDiagnostics();
if !gatherDiags && (printDiag || printDiagSum) then
warning("gatherDiags was not enabled");
param s = if name != "" then name + ": " else "";
if printTime then writef("%s%.2drs\n", s, this.elapsed());
if printDiag then writef('%s%s\n', s, this.comm():string);
if printDiagSum then writef("%s%t\n", s, this.commSum());
}
proc elapsed() {
return elapsedTime;
}
proc comm() {
if !gatherDiags then warning("gatherDiags was not enabled");
return D;
}
proc commSum() {
if !gatherDiags then warning("gatherDiags was not enabled");
const GETS = + reduce (D.get + D.get_nb);
const PUTS = + reduce (D.put + D.put_nb);
const ONS = + reduce (D.execute_on + D.execute_on_fast + D.execute_on_nb);
return new CommDiagSummary(GETS, PUTS, ONS);
}
}
// Message helpers
proc parseName(s: string): string {
var fields = s.split();
return fields[1];
}
proc parseTwoNames(s: string): (string, string) {
var (nameOne, nameTwo) = s.splitMsgToTuple('+', 2);
return (parseName(nameOne), parseName(nameTwo));
}
config const writeReqRep = false;
proc writeReq(req: string) {
if writeReqRep then writeln(req);
}
proc writeRep(rep: string) {
if writeReqRep then writeln(rep);
}
config const writeSegStr = false;
config const showSegStrLen = 5;
proc writeSegString(msg: string, ss: SegString) {
if writeSegStr {
writeln(msg);
ss.show(showSegStrLen);
}
}
proc nameForRandintMsg(len: int, dtype:DType, aMin: int, aMax: int,
st: borrowed SymTab) {
use RandMsg;
const payload = try! "%i %s %i %i None".format(len, dtype2str(dtype), aMin,
aMax);
writeReq(payload);
const repMsg = randintMsg(cmd='randint', payload=payload, st).msg;
writeRep(repMsg);
return parseName(repMsg);
}