Skip to content

Commit e21f9f9

Browse files
authored
Merge pull request #28 from Wonseo-C/actorcreation
The actor creation benchmark and Subdirectories
2 parents 886780e + 4d47ff3 commit e21f9f9

File tree

14 files changed

+139
-62
lines changed

14 files changed

+139
-62
lines changed
File renamed without changes.

TS/src/BenchmarkRunner.lf renamed to TS/Savina/src/BenchmarkRunner.lf

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ target TypeScript;
77
* @author Wonseo Choi
88
*/
99

10-
reactor BenchmarkRunner(num_iterations:number(12)) {
10+
reactor BenchmarkRunner(numIterations:number(12)) {
1111

1212
output start:boolean;
1313
input finish:boolean;
@@ -25,42 +25,40 @@ reactor BenchmarkRunner(num_iterations:number(12)) {
2525

2626

2727
reaction(startup) -> nextIteration {=
28-
measuredTimes.length = num_iterations;
28+
// measuredTimes.length = numIterations;
2929
actions.nextIteration.schedule(0, true);
3030

31-
console.log("Benchmark will run " + num_iterations + " times \n");
31+
console.log("Benchmark will run " + numIterations + " times \n");
3232
console.log("System information:")
3333
console.log(`Platform: ${process.platform} \n`)
3434
=}
35-
3635

37-
reaction(nextIteration) -> start, done {=
38-
if (count < num_iterations) {
39-
startTime = util.getCurrentPhysicalTime();
40-
start = true;
41-
} else {
42-
actions.done.schedule(0, true);
43-
}
36+
reaction(nextIteration) -> start {=
37+
startTime = util.getCurrentPhysicalTime();
38+
start = true;
4439
=}
4540

46-
reaction(finish) -> nextIteration {=
41+
reaction(finish) -> nextIteration, done {=
4742
const duration = util.getCurrentPhysicalTime().subtract(startTime as TimeValue);
48-
measuredTimes[count] = duration.toMilliseconds();
43+
measuredTimes.push(duration.toMilliseconds());
4944
++count;
5045

5146
console.log("Iteration "+ count + " - " + duration.toMilliseconds() + " ms\n");
5247

53-
actions.nextIteration.schedule(0, true);
54-
48+
if (count < numIterations) {
49+
actions.nextIteration.schedule(0, true);
50+
} else {
51+
actions.done.schedule(0, true);
52+
}
5553
=}
5654

5755
reaction(done) {=
5856
measuredTimes.sort()
5957

6058
console.log("Execution - Summary:\n");
6159
console.log("Best Time:\t " + measuredTimes[0] + " msec\n");
62-
console.log("Worst Time:\t " + measuredTimes[num_iterations - 1] + " msec\n");
63-
console.log("Median Time:\t " + median(measuredTimes, num_iterations) + " msec\n");
60+
console.log("Worst Time:\t " + measuredTimes[numIterations - 1] + " msec\n");
61+
console.log("Median Time:\t " + median(measuredTimes, numIterations) + " msec\n");
6462

6563
util.requestStop();
6664
=}

TS/src/Philosophers.lf renamed to TS/Savina/src/concurrency/Philosophers.lf

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
*/
66

77

8-
target TypeScript {
8+
target TypeScript {
99
fast: true
1010
};
1111

12-
import BenchmarkRunner from "BenchmarkRunner.lf";
13-
12+
import BenchmarkRunner from "../BenchmarkRunner.lf";
1413

1514
reactor Philosopher(count:number(10000)) {
1615

@@ -48,7 +47,7 @@ reactor Philosopher(count:number(10000)) {
4847
}
4948

5049

51-
reactor Arbitrator(num_philosophers:number(20)) {
50+
reactor Arbitrator(numPhilosophers:number(20)) {
5251
preamble {=
5352
enum Reply {
5453
INVALID = 0,
@@ -60,11 +59,11 @@ reactor Arbitrator(num_philosophers:number(20)) {
6059
input start: boolean;
6160
output allFinished: boolean;
6261

63-
input[num_philosophers] finished: boolean;
64-
input[num_philosophers] done: boolean;
65-
input[num_philosophers] hungry: boolean;
66-
output[num_philosophers] eat: boolean;
67-
output[num_philosophers] denied: boolean;
62+
input[numPhilosophers] finished: boolean;
63+
input[numPhilosophers] done: boolean;
64+
input[numPhilosophers] hungry: boolean;
65+
output[numPhilosophers] eat: boolean;
66+
output[numPhilosophers] denied: boolean;
6867

6968
state forks: {=Array<boolean>=}({= [] =});
7069
state replies: {=Array<number>=}({= [] =});
@@ -75,8 +74,8 @@ reactor Arbitrator(num_philosophers:number(20)) {
7574
logical action sendReplies;
7675

7776
reaction(startup) {=
78-
forks.length = num_philosophers;
79-
replies.length = num_philosophers;
77+
forks.length = numPhilosophers;
78+
replies.length = numPhilosophers;
8079
=}
8180

8281
reaction(start) {=
@@ -88,7 +87,7 @@ reactor Arbitrator(num_philosophers:number(20)) {
8887
=}
8988

9089
reaction(sendReplies) -> eat, denied {=
91-
for(let i = 0; i < num_philosophers; i++) {
90+
for(let i = 0; i < numPhilosophers; i++) {
9291
if (replies[i] == Reply.EAT) {
9392
eat[i] = true;
9493
} else if (replies[i] == Reply.DENIED) {
@@ -99,42 +98,42 @@ reactor Arbitrator(num_philosophers:number(20)) {
9998
=}
10099

101100
reaction (done) {=
102-
for(let i = 0; i < num_philosophers; i++){
101+
for(let i = 0; i < numPhilosophers; i++){
103102
if (done[i] !== undefined) {
104103
forks[i] = false;
105-
forks[(i + 1) % num_philosophers] = false;
104+
forks[(i + 1) % numPhilosophers] = false;
106105
}
107106
}
108107
=}
109108

110109
reaction(hungry) -> sendReplies {=
111-
for(let i = 0; i < num_philosophers; i++) {
112-
const j= (i + arbitration_id) % num_philosophers;
110+
for(let i = 0; i < numPhilosophers; i++) {
111+
const j= (i + arbitration_id) % numPhilosophers;
113112

114113
if(hungry[j] !== undefined) {
115114
const left = j;
116-
const right = (j + 1) % num_philosophers;
115+
const right = (j + 1) % numPhilosophers;
117116

118117
if(forks[left] || forks[right]) {
119118
replies[j] = Reply.DENIED;
120119
++numRetries;
121120
} else {
122121
forks[j] = true;
123-
forks[(j + 1) % num_philosophers] = true;
122+
forks[(j + 1) % numPhilosophers] = true;
124123
replies[j] = Reply.EAT;
125124
}
126125
}
127126
}
128-
arbitration_id = (arbitration_id + 1) % num_philosophers;
127+
arbitration_id = (arbitration_id + 1) % numPhilosophers;
129128
actions.sendReplies.schedule(0, null);
130129
=}
131130

132131
reaction (finished) -> allFinished {=
133-
// i < finished_width ... finished_width = num_philosophers in this code
134-
for(let i = 0; i < num_philosophers; i++) {
132+
// i < finished_width ... finished_width = numPhilosophers in this code
133+
for(let i = 0; i < numPhilosophers; i++) {
135134
if(finished[i] !== undefined) {
136135
++numFinishedPhilosophers;
137-
if(num_philosophers == numFinishedPhilosophers) {
136+
if(numPhilosophers == numFinishedPhilosophers) {
138137
console.log("Arbitrator: All philosophers are sated. Number of denials to philosophers: " + numRetries + "\n");
139138
allFinished = true;
140139
}
@@ -144,11 +143,11 @@ reactor Arbitrator(num_philosophers:number(20)) {
144143
}
145144

146145

147-
main reactor Philosophers (numIterations:number(12), num_philosophers:number(20), count:number(100)){
146+
main reactor Philosophers (numIterations:number(12), numPhilosophers:number(20), count:number(100)){
148147

149-
arbitrator = new Arbitrator(num_philosophers = num_philosophers);
150-
philosophers = new[num_philosophers] Philosopher(count=count);
151-
runner = new BenchmarkRunner(num_iterations = numIterations);
148+
arbitrator = new Arbitrator(numPhilosophers = numPhilosophers);
149+
philosophers = new[numPhilosophers] Philosopher(count=count);
150+
runner = new BenchmarkRunner(numIterations = numIterations);
152151

153152
reaction (startup) {=
154153
console.log("Start Philosophers LF Benchmark!");
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2022 Hanyang University
3+
*
4+
* @author Wonseo Choi
5+
*/
6+
7+
8+
target TypeScript {
9+
fast: true
10+
};
11+
12+
reactor ReactorCreator(numReactor:number(60), createNumber:number(0)) {
13+
14+
preamble {=
15+
function performComputation(theta: number): void {
16+
const sint: number = Math.sin(theta);
17+
const res: number = sint * sint;
18+
19+
console.log("Perform Computation.");
20+
}
21+
=}
22+
23+
input inp: boolean;
24+
output outMessage: boolean;
25+
output finished: boolean;
26+
27+
mutation (inp) -> outMessage, finished {=
28+
++ createNumber;
29+
performComputation(37.2);
30+
console.log("Create " + createNumber + " reactor.");
31+
if (createNumber == numReactor) {
32+
console.log("End Benchmark.");
33+
finished = true;
34+
} else {
35+
outMessage = true;
36+
let newReactor = new ReactorCreator(this.getReactor(), numReactor, createNumber);
37+
var outPort = __outMessage.getPort();
38+
this.connect(outPort, newReactor.inp);
39+
}
40+
=}
41+
}
42+
43+
main reactor ActorCreation(numIterations:number(12), numReactor:number(60)) {
44+
state startTime: time;
45+
46+
creater = new ReactorCreator(numReactor=numReactor, createNumber=0);
47+
48+
// Start
49+
reaction (startup) -> creater.inp {=
50+
startTime = util.getCurrentPhysicalTime();
51+
creater.inp = true;
52+
console.log("Start Actor Creation LF Benchmark!");
53+
=}
54+
55+
// End
56+
reaction (creater.finished) {=
57+
const elapsedTime = util.getCurrentPhysicalTime().subtract(startTime as TimeValue);
58+
console.log("Elapsed time: " + elapsedTime);
59+
util.requestStop();
60+
=}
61+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

TS/src/PingPong.lf renamed to TS/Savina/src/micro/PingPong.lf

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
target TypeScript {
44
fast: true
55
};
6+
7+
import BenchmarkRunner from "../BenchmarkRunner.lf";
8+
69
reactor Ping(limit:number(100000)) {
710
input receive:number;
11+
input start;
812
output send:number;
913
state pingsLeft:number(limit);
10-
state startTime:time;
1114
logical action serve;
12-
logical action done;
13-
reaction (startup) -> send {=
15+
output done: boolean;
16+
reaction (start) -> send {=
1417
send = pingsLeft;
1518
pingsLeft -= 1;
16-
startTime = util.getCurrentPhysicalTime();
1719
=}
1820
reaction (serve) -> send {=
1921
send = pingsLeft;
@@ -23,25 +25,25 @@ reactor Ping(limit:number(100000)) {
2325
if (pingsLeft > 0) {
2426
actions.serve.schedule(0, null);
2527
} else {
26-
actions.done.schedule(0, null);
28+
pingsLeft = limit;
29+
done = true;
2730
}
2831
=}
29-
reaction (done) {=
30-
let elapsedTime = util.getCurrentPhysicalTime().subtract(startTime as TimeValue);
31-
console.log("Elapsed time: " + elapsedTime);
32-
util.requestStop();
33-
=}
3432
}
3533
reactor Pong {
3634
input receive:number;
3735
output send:number;
3836
reaction (receive) -> send {=
39-
send = receive as number;
37+
send = receive as number;
4038
=}
4139
}
42-
main reactor PingPong(limit:number(100000)) {
40+
main reactor PingPong(numIterations:number(12), limit:number(100000)) {
41+
runner = new BenchmarkRunner(numIterations = numIterations);
4342
ping = new Ping(limit = limit);
4443
pong = new Pong();
44+
45+
runner.start -> ping.start;
4546
ping.send -> pong.receive;
46-
pong.send -> ping.receive;
47+
pong.send -> ping.receive;
48+
ping.done -> runner.finish;
4749
}
File renamed without changes.

0 commit comments

Comments
 (0)