forked from huiqing/percept2_online
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbench.erl
executable file
·162 lines (126 loc) · 5.03 KB
/
bench.erl
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
%% orbit-int benchmarks (for RELEASE)
%%
%% Author: Patrick Maier <[email protected]>
%%
-module(bench).
-export([%% sets of generators
g/1,
g1/1, g2/1, g3/1, g4/1, g5/1,
g12/1, g13/1, g14/1, g15/1, g23/1, g24/1, g25/1, g34/1, g35/1, g45/1,
g123/1, g124/1, g125/1, g134/1, g135/1, g145/1, g234/1, g235/1, g245/1, g345/1,
g1234/1, g1235/1, g1245/1, g1345/1, g2345/1,
g12345/1,
%% sequential benchmarks
seq/2,
%% parallel benchmarks
par/3, par_seq/3,
%% distributed benchmarks
dist/4, dist_seq/4]).
-compile(export_all).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% generators
%% Fibonacci numbers
fib(0) -> 1;
fib(1) -> 1;
fib(N) -> fib(N - 1) + fib(N - 2).
%% mixing polynomials (up to degree 3)
p(A0,_N) -> A0.
p(A1,A0, N) -> A1 * N + p(A0, N).
p(A2,A1,A0, N) -> A2 * N * N + p(A1,A0, N).
p(A3,A2,A1,A0, N) -> A3 * N * N * N + p(A2,A1,A0, N).
%% step functions (up to 4 steps)
s(B0, N) -> if N < B0 -> 0; true -> 1 end.
s(B0,B1, N) -> if N < B0 -> 0; true -> 1 + s(B1, N) end.
s(B0,B1,B2, N) -> if N < B0 -> 0; true -> 1 + s(B1,B2, N) end.
s(B0,B1,B2,B3, N) -> if N < B0 -> 0; true -> 1 + s(B1,B2,B3, N) end.
%% remainder function (range 0..R-1)
r(R, N) -> abs(N) rem R.
%% generators based on Fibonacci numbers;
%% functions f1(N,_),...,f5(N,_) produce numbers in the range 0 .. N-1;
%% computationally f1 = fib(0..15),
%% f2 = fib(5..20),
%% f3 = fib(10..25),
%% f4 = fib(11,19,27), bias 49% to 11, 49% to 19, 2% to 27
%% f5 = fib(10,20,30), bias 90% to 10, 9.9% to 20, 0.1% to 30
f1(N,X) -> r(N, fib(p(1,0, r(16, X))) + p(1,0, X)).
f2(N,X) -> r(N, fib(p(1,5, r(16, X))) + p(2,5,-1, X)).
f3(N,X) -> r(N, fib(p(1,10, r(16, X))) + p(-1,0,8,0,X)).
f4(N,X) -> r(N, fib(p(8,3, s(0,49,98,100, r(100, X)))) + p(-1, X)).
f5(N,X) -> r(N, fib(p(10,0, s(0,900,999,1000, r(1000, X)))) + p(1, X)).
%% sets (= lists) of generators
g(_N) -> [].
g1(N) -> [fun(X) -> f1(N,X) end].
g2(N) -> [fun(X) -> f2(N,X) end].
g3(N) -> [fun(X) -> f3(N,X) end].
g4(N) -> [fun(X) -> f4(N,X) end].
g5(N) -> [fun(X) -> f5(N,X) end].
g12(N) -> g1(N) ++ g2(N).
g13(N) -> g1(N) ++ g3(N).
g14(N) -> g1(N) ++ g4(N).
g15(N) -> g1(N) ++ g5(N).
g23(N) -> g2(N) ++ g3(N).
g24(N) -> g2(N) ++ g4(N).
g25(N) -> g2(N) ++ g5(N).
g34(N) -> g3(N) ++ g4(N).
g35(N) -> g3(N) ++ g5(N).
g45(N) -> g4(N) ++ g5(N).
g123(N) -> g12(N) ++ g3(N).
g124(N) -> g12(N) ++ g4(N).
g125(N) -> g12(N) ++ g5(N).
g134(N) -> g13(N) ++ g4(N).
g135(N) -> g13(N) ++ g5(N).
g145(N) -> g14(N) ++ g5(N).
g234(N) -> g23(N) ++ g4(N).
g235(N) -> g23(N) ++ g5(N).
g245(N) -> g24(N) ++ g5(N).
g345(N) -> g34(N) ++ g5(N).
g1234(N) -> g123(N) ++ g4(N).
g1235(N) -> g123(N) ++ g5(N).
g1245(N) -> g124(N) ++ g5(N).
g1345(N) -> g134(N) ++ g5(N).
g2345(N) -> g234(N) ++ g5(N).
g12345(N) -> g1234(N) ++ g5(N).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% benchmarks, parametrised by
%% * list of Generators
%% * size of space N > 0
%% * number of processors P > 0 (per node)
%% * list of Workers (in short node name format 'name@host')
%% sequential orbit computation
seq(Generators, N) ->
sz(master:orbit(Generators(N), [0], 2 * N)).
%% parallel orbit computation (par_seq/3 does not spawn image computation)
par(Generators, N, P) ->
sz(master:orbit(Generators(N), [0], {P, (2 * N) div P + 1, 0, true})).
par_seq(Generators, N, P) ->
sz(master:orbit(Generators(N), [0], {P, (2 * N) div P + 1, 0, false})).
%% distributed orbit computation (dist_seq/4 does not spawn image computation)
dist(Generators, N, P, Workers) ->
W = length(Workers),
sz(master:orbit(Generators(N), [0], [{H, P, (2 * N) div (W * P) + 1, 1, true} || H <- Workers])).
dist_seq(Generators, N, P, Workers) ->
W = length(Workers),
sz(master:orbit(Generators(N), [0], [{H, P, (2 * N) div (W * P) + 1, 1, false} || H <- Workers])).
%% H: host name; P: number f procs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% auxiliary functions
%% print size of generated orbit
sz({_Orbit, [MainStats|_OtherStats]}) ->
io:write(lists:keyfind(size, 1, MainStats)), io:nl().
run_orbit_with_trace() ->
_Res = ttb:tracer(Nodes),
_Res1=ttb:p(all, [send]),
bench:dist_seq(fun bench:g124/1, 1000000, 8,
Nodes),
ttb:stop().
run_orbit() ->
bench:dist_seq(fun bench:g124/1, 1000000, 8,
Nodes).