Skip to content

Commit

Permalink
Temporary HelloDistributed.lf for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakio815 committed May 6, 2024
1 parent cb79f08 commit f353a74
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions test/C/src/federated/HelloDistributed.lf
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,63 @@
* coordination of the advancement of time (HLA or Ptides) is needed.
* @author Edward A. Lee
*/
target C {
logging: DEBUG,
comm-type: TCP
target C {
// logging: DEBUG,
// comm-type: SST,
// tracing: true,
timeout: 5 sec,
auth: true
}

preamble {=
#include <string.h>
=}

reactor Source {
output out: string
output out: int
timer t(0, 500 msec)

reaction(startup) -> out {=
lf_print("Sending 'Hello World!' message from source federate.");
lf_set(out, "Hello World!");
lf_request_stop();
reaction(t) -> out {=
lf_set(out, 47);
=}
}

reactor Destination {
input in: string
state received: bool = false

reaction(startup) {=
lf_print("Destination started.");
=}
input in: int
state count: int = 0
state avg_lag: instant_t = 0
state max_lag: instant_t = 0
state min_lag: instant_t = 1000000000 //1sec
state total_lag: instant_t = 0

reaction(in) {=
lf_print("At logical time " PRINTF_TIME ", destination received: %s", lf_time_logical_elapsed(), in->value);
if (strcmp(in->value, "Hello World!") != 0) {
fprintf(stderr, "ERROR: Expected to receive 'Hello World!'\n");
exit(1);
instant_t lag = lf_time_physical() - lf_time_logical();
char time_buffer[LF_TIME_BUFFER_LENGTH];
lf_readable_time(time_buffer, lag);
lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer);
if (self->max_lag < lag){
self->max_lag = lag;
}
if (self->min_lag > lag){
self->min_lag = lag;
}
self->received = true;
self->count ++;
self->total_lag += lag;
=}

reaction(shutdown) {=
lf_print("Shutdown invoked.");
if (!self->received) {
lf_print_error_and_exit("Destination did not receive the message.");
self->avg_lag = self->total_lag / self->count;
FILE* fp;
fp = fopen("eval.csv", "a");
if(fp == NULL) {
lf_print("Couldn't open the file.");
} else {
fprintf(fp, "%ld,", self->avg_lag);
fprintf(fp, "%ld,", self->max_lag);
fprintf(fp, "%ld\n", self->min_lag);
fprintf(fp, "\n");
}
fclose(fp);
=}

}

federated reactor HelloDistributed at localhost {
federated reactor HelloDistributed{
s = new Source() // Reactor s is in federate Source
d = new Destination() // Reactor d is in federate Destination
s.out -> d.in // This version preserves the timestamp.

reaction(startup) {=
lf_print("Printing something in top-level federated reactor.");
=}
}

0 comments on commit f353a74

Please sign in to comment.