Skip to content

Commit

Permalink
Merge pull request #59 from lf-lang/cleanup-pass
Browse files Browse the repository at this point in the history
Updated API usages
  • Loading branch information
edwardalee authored Feb 13, 2024
2 parents 091343f + a7bc6ff commit 66e1c3c
Show file tree
Hide file tree
Showing 30 changed files with 535 additions and 513 deletions.
48 changes: 24 additions & 24 deletions C/Distributed/src/PingPongDistributed.lf
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/**
* Basic benchmark from the Savina benchmark suite that is
* intended to measure message-passing overhead.
* This version is distributed, communicating using physical connections over sockets.
* See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks).

* This is based on https://www.scala-lang.org/old/node/54
* See https://shamsimam.github.io/papers/2014-agere-savina.pdf.
*
* This is a distributed version, where Ping and Pong run in
* separate programs and can be run on different machines.
*
* There is no parallelism in this application, so it does not benefit from being
* being distributed.
*
* These measurements are total execution time, including startup and shutdown, of
* all three programs.
*
* Basic benchmark from the Savina benchmark suite that is intended to measure message-passing
* overhead. This version is distributed, communicating using physical connections over sockets. See
* [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks).
*
* This is based on https://www.scala-lang.org/old/node/54 See
* https://shamsimam.github.io/papers/2014-agere-savina.pdf.
*
* This is a distributed version, where Ping and Pong run in separate programs and can be run on
* different machines.
*
* There is no parallelism in this application, so it does not benefit from being being distributed.
*
* These measurements are total execution time, including startup and shutdown, of all three
* programs.
*
* @author Edward A. Lee
*/
target C;
target C

import Ping, Pong from "../../Savina/src/micro/PingPong.lf"
federated reactor(count:int(10000000)) {
ping = new Ping(count = count);
pong = new Pong(expected = count);
ping.send -> pong.receive;
pong.send -> ping.receive;
}

federated reactor(count: int = 10000000) {
ping = new Ping(count=count)
pong = new Pong(expected=count)
ping.send -> pong.receive
pong.send -> ping.receive
}
72 changes: 38 additions & 34 deletions C/Distributed/src/TimeLimitDistributed.lf
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,45 @@
// for over 32 million reactions per second.
// This translates to 31 nanoseconds per reaction invocation.
target C {
flags: ["-O2", "-Wall"],
coordination: centralized,
timeout: 10 secs
};
reactor Clock(offset:time(0), period:time(1 sec)) {
output y:int;
timer t(offset, period);
state count:int(0);
reaction(t) -> y {=
(self->count)++;
//printf("Reacting at time %ld.\n", get_elapsed_logical_time());
SET(y, self->count);
=}
coordination: centralized,
timeout: 10 secs
}

reactor Clock(offset: time = 0, period: time = 1 sec) {
output y: int
timer t(offset, period)
state count: int = 0

reaction(t) -> y {=
(self->count)++;
lf_set(y, self->count);
=}
}

reactor Destination {
input x:int;
state s:int(1);
reaction(x) {=
// printf("%d\n", x->value);
if (x->value != self->s) {
printf("Error: Expected %d and got %d.\n", self->s, x->value);
exit(1);
}
self->s++;
=}
reaction(shutdown) {=
lf_print("**** shutdown reaction invoked.");
if (self->s != 10000002) {
lf_print_warning("Expected 10000002 but got %d.", self->s);
}
lf_print("Approx. time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1));
=}
input x: int
state s: int = 1

reaction(x) {=
// printf("%d\n", x->value);
if (x->value != self->s) {
printf("Error: Expected %d and got %d.\n", self->s, x->value);
exit(1);
}
self->s++;
=}

reaction(shutdown) {=
lf_print("**** shutdown reaction invoked.");
if (self->s != 10000002) {
lf_print_warning("Expected 10000002 but got %d.", self->s);
}
lf_print("Approx. time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1));
=}
}
federated reactor TimeLimitDistributed(period:time(700 usec)) {
c = new Clock(period = period);
d = new Destination();
c.y -> d.x;

federated reactor TimeLimitDistributed(period: time = 700 usec) {
c = new Clock(period=period)
d = new Destination()
c.y -> d.x
}
72 changes: 37 additions & 35 deletions C/Distributed/src/TimeLimitDistributedDecentralized.lf
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,44 @@
// Correct output for this 1, 2, 3, 4.
// Failure for this test is failing to halt or getting the wrong data.
target C {
flags: ["-O2", "-Wall", "-g", "-rdynamic"],
coordination: decentralized,
timeout: 4 sec
};
reactor Clock(offset:time(0), period:time(1 sec)) {
output y:int;
timer t(0, period);
state count:int(0);
reaction(t) -> y {=
(self->count)++;
// lf_print("Reacting at time (%lld, %u).", get_elapsed_logical_time(), get_microstep());
SET(y, self->count);
=}
coordination: decentralized,
timeout: 4 sec
}

reactor Clock(offset: time = 0, period: time = 1 sec) {
output y: int
timer t(0, period)
state count: int = 0

reaction(t) -> y {=
(self->count)++;
lf_set(y, self->count);
=}
}

reactor Destination {
input x:int;
state s:int(1);
reaction(x) {=
// lf_print("%d", x->value);
// lf_print("Reacting at time (%lld, %u).", get_elapsed_logical_time(), get_microstep());
if (x->value != self->s) {
lf_print_warning("Expected %d and got %d.", self->s, x->value);
}
self->s++;
// lf_print("Approx. time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1));
=}
reaction(shutdown) {=
lf_print("**** shutdown reaction invoked.");
if (self->s != 10000002) {
lf_print_warning("Expected 10000002 but got %d.", self->s);
}
lf_print("Approx. time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1));
=}
input x: int
state s: int = 1

reaction(x) {=
// lf_print("%d", x->value);
if (x->value != self->s) {
lf_print_warning("Expected %d and got %d.", self->s, x->value);
}
self->s++;
=}

reaction(shutdown) {=
lf_print("**** shutdown reaction invoked.");
if (self->s != 10000002) {
lf_print_warning("Expected 10000002 but got %d.", self->s);
}
lf_print("Approx. time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1));
=}
}
federated reactor (period:time(3 usec)) {
c = new Clock(period = period);
d = new Destination();
c.y -> d.x after period;

federated reactor(period: time = 3 usec) {
c = new Clock(period=period)
d = new Destination()
c.y -> d.x after period
}
87 changes: 46 additions & 41 deletions C/Distributed/src/TimeLimitDistributedDecentralized2.lf
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,52 @@
// microstep apart (so that there is no waiting for physical time to elapse,
// which would distort the statistics).
target C {
flags: ["-O2", "-Wall", "-g", "-rdynamic"],
coordination: decentralized,
timeout: 1 sec
};
reactor Source(num_messages:int(10)) {
output y:int;
logical action a;
state count:int(0);
reaction(startup, a) -> y {=
(self->count)++;
if (self->count < self->num_messages) {
tag_t tag = get_current_tag();
lf_print("Source sending %d at tag (%lld, %u).",
self->count,
tag.time - lf_time_start(), tag.microstep
);
SET(y, self->count);
schedule(a, 0);
}
=}
coordination: decentralized,
timeout: 1 sec
}
reactor Destination(num_messages:int(10)) {
input x:int;
state s:int(1);
reaction(x) {=
lf_print("Destination received: %d", x->value);
if (x->value != self->s) {
error_print_and_exit("Expected %d and got %d.", self->s, x->value);
}
self->s++;
=}
reaction(shutdown) {=
lf_print("**** shutdown reaction invoked.");
if (self->s != self->num_messages) {
error_print_and_exit("Expected %d but got %d.", self->num_messages, self->s);
}
lf_print("Approximate time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1));
=}

reactor Source(num_messages: int = 10) {
output y: int
logical action a
state count: int = 0

reaction(startup, a) -> y {=
(self->count)++;
if (self->count < self->num_messages) {
tag_t tag = lf_tag();
lf_print("Source sending %d at tag " PRINTF_TAG,
self->count,
tag.time - lf_time_start(), tag.microstep
);
lf_set(y, self->count);
lf_schedule(a, 0);
}
=}
}
federated reactor (period:time(1 usec)) {
c = new Source();
d = new Destination();
c.y -> d.x after 1 usec;

reactor Destination(num_messages: int = 10) {
input x: int
state s: int = 1

reaction(x) {=
lf_print("Destination received: %d", x->value);
if (x->value != self->s) {
lf_print_error_and_exit("Expected %d and got %d.", self->s, x->value);
}
self->s++;
=}

reaction(shutdown) {=
lf_print("**** shutdown reaction invoked.");
if (self->s != self->num_messages) {
lf_print_error_and_exit("Expected %d but got %d.", self->num_messages, self->s);
}
lf_print("Approximate time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1));
=}
}

federated reactor(period: time = 1 usec) {
c = new Source()
d = new Destination()
c.y -> d.x after 1 usec
}
Loading

0 comments on commit 66e1c3c

Please sign in to comment.