Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sparse multiport iterator #29

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
# Test the C benchmarks.
c-benchmark-tests:
uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@main
uses: lf-lang/benchmarks-lingua-franca/.github/workflows/benchmark-tests.yml@input-iterator
with:
target: 'C'
cpp-benchmark-tests:
Expand Down
2 changes: 1 addition & 1 deletion C/Distributed/src/TimeLimitDistributed.lf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ reactor Clock(offset:time(0), period:time(1 sec)) {
reaction(t) -> y {=
(self->count)++;
//printf("Reacting at time %ld.\n", get_elapsed_logical_time());
SET(y, self->count);
lf_set(y, self->count);
=}
}
reactor Destination {
Expand Down
2 changes: 1 addition & 1 deletion C/Distributed/src/TimeLimitDistributedDecentralized.lf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ reactor Clock(offset:time(0), period:time(1 sec)) {
reaction(t) -> y {=
(self->count)++;
// info_print("Reacting at time (%lld, %u).", get_elapsed_logical_time(), get_microstep());
SET(y, self->count);
lf_set(y, self->count);
=}
}
reactor Destination {
Expand Down
2 changes: 1 addition & 1 deletion C/Distributed/src/TimeLimitDistributedDecentralized2.lf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reactor Source(num_messages:int(10)) {
self->count,
tag.time - start_time, tag.microstep
);
SET(y, self->count);
lf_set(y, self->count);
schedule(a, 0);
}
=}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ reactor Clock(offset:time(0), period:time(1 sec)) {
reaction(t) -> y {=
(self->count)++;
//printf("Reacting at time %ld.\n", get_elapsed_logical_time());
SET(y, self->count);
lf_set(y, self->count);
=}
}
reactor Destination {
Expand Down
2 changes: 1 addition & 1 deletion C/Distributed/src/TimeLimitDistributedPhysical.lf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ reactor Clock(offset:time(0), period:time(1 sec)) {
reaction(t) -> y {=
(self->count)++;
//printf("Reacting at time %ld.\n", get_elapsed_logical_time());
SET(y, self->count);
lf_set(y, self->count);
=}
}
reactor Destination {
Expand Down
2 changes: 1 addition & 1 deletion C/Distributed/src/TimeLimitDistributedROSSerialization.lf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ reactor Clock(offset:time(0), period:time(1 sec)) {
auto msg = std::make_shared<std_msgs::msg::Int32>();
msg->data = self->count;

SET(y, msg);
lf_set(y, msg);
=}
}
reactor Destination {
Expand Down
6 changes: 3 additions & 3 deletions C/Savina/src/concurrency/Banking.lf
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ reactor Teller(numAccounts:int(1000), numBankings:int(50000)) {
if (!deque_is_empty(queue)) {
work_found = 1;
credit_message_t *message = (credit_message_t *) deque_peek_front(queue);
SET(credit[i], *message);
lf_set(credit[i], *message);
free(deque_pop_front(queue)); // free allocated memory
}
}
Expand All @@ -144,7 +144,7 @@ reactor Teller(numAccounts:int(1000), numBankings:int(50000)) {
schedule(next, 0);
} else {
info_print("Teller: Finished iteration\n");
SET(finished, true);
lf_set(finished, true);
}
=}
}
Expand All @@ -166,7 +166,7 @@ reactor Account(bank_index:size_t(0), numAccounts:size_t(1000), numTransactions:
// reduce the balance
self->balance -= message.amount;
// and sent the recipient a debit message
SET(outDebit[message.recipient], message.amount);
lf_set(outDebit[message.recipient], message.amount);
info_print("Account %zu credits %f to %zu\n", self->bank_index, message.amount, message.recipient);
=}

Expand Down
14 changes: 7 additions & 7 deletions C/Savina/src/concurrency/BoundedBuffer.lf
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,26 @@ reactor ManagerReactor(bufferSize: size_t(50), numProducers: size_t(40), numCons

// start execution by signalling all producers that they should send data
for (int i = 0; i < self->numProducers; i++) {
SET(producerCommand[i], true);
lf_set(producerCommand[i], true);
}
=}

reaction(consumerAvailable) -> consumerData, producerCommand, finished {=
// abort if all producers have terminated and all data has been send
if((self->numTerminatedProducers == self->numProducers) && deque_is_empty(&self->pendingData)) {
SET(finished, true);
lf_set(finished, true);
return;
}

size_t consumer_id = 0;
size_t activatedProducers = 0;
while(!deque_is_empty(&self->pendingData) && consumer_id < self->numConsumers) {
if (consumerAvailable[consumer_id]->is_present) {
SET(consumerData[consumer_id], (size_t)deque_peek_front(&self->pendingData));
lf_set(consumerData[consumer_id], (size_t)deque_peek_front(&self->pendingData));
deque_pop_front(&self->pendingData);
// tell a producer to create a new data item for the next round
if (activatedProducers < self->numProducers && !self->producerTerminated[self->producer_id]) {
SET(producerCommand[self->producer_id], true);
lf_set(producerCommand[self->producer_id], true);
self->producer_id = (self->producer_id + 1) % self->numProducers;
activatedProducers++;
}
Expand Down Expand Up @@ -174,11 +174,11 @@ reactor ProducerReactor(bank_index: size_t(0), numItemsToProduce: size_t(1000),

reaction(produce) -> data, finished {=
self->prodItem = processItem(self->prodItem, self->prodCost);
SET(data, self->prodItem);
lf_set(data, self->prodItem);
self->itemsProduced++;

if (self->itemsProduced == self->numItemsToProduce) {
SET(finished, true);
lf_set(finished, true);
}
=}
}
Expand All @@ -201,7 +201,7 @@ reactor ConsumerReactor(bank_index: size_t(0), consCost: size_t(25)) {
=}

reaction(sendAvailable) -> available {=
SET(available, true);
lf_set(available, true);
=}

reaction(data) -> sendAvailable {=
Expand Down
4 changes: 2 additions & 2 deletions C/Savina/src/concurrency/CigaretteSmoker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ reactor ArbiterReactor(numRounds:size_t(1000), numSmokers:size_t(200)) {

int busyWaitPeriod = nextIntEMax(self->random, 100) + 10;

SET(startSmoking[newSmokerIndex], busyWaitPeriod);
lf_set(startSmoking[newSmokerIndex], busyWaitPeriod);

// no need to wait for feedback from the smoker, as it starts smoking (logically) instantaneously
// We can immediately schedule the next round
Expand All @@ -126,7 +126,7 @@ reactor ArbiterReactor(numRounds:size_t(1000), numSmokers:size_t(200)) {
=}

reaction(stop) -> outFinished {=
SET(outFinished, true);
lf_set(outFinished, true);
=}

reaction(shutdown) {=
Expand Down
8 changes: 4 additions & 4 deletions C/Savina/src/concurrency/Dictionary.lf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ reactor Manager(numWorkers: size_t(20)) {
//In C: initialize local state
self->numWorkersTerminated = 0;
// start execution
SET(doWork, true);
lf_set(doWork, true);
=}

reaction(workerFinished) -> finished {=
Expand All @@ -84,7 +84,7 @@ reactor Manager(numWorkers: size_t(20)) {
}
if(self->numWorkersTerminated == self->numWorkers) {
info_print("All workers terminated.");
SET(finished, true);
lf_set(finished, true);
}
=}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ reactor DictionaryImpl(numWorkers: size_t(20)) {
reaction(sendAnswers) -> response {=
for(size_t i = 0; i < self->numWorkers; i++) {
if(self->answersToSend[i] >= 0) {
SET(response[i], self->answersToSend[i]);
lf_set(response[i], self->answersToSend[i]);
self->answersToSend[i] = -1;
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ reactor Worker(bank_index: size_t(0), numMessagesPerWorker: size_t(10000), write
msg->value = 0;
}
} else {
SET(finished, true);
lf_set(finished, true);
}
=}
}
Expand Down
12 changes: 6 additions & 6 deletions C/Savina/src/concurrency/LogisticMap.lf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ reactor RateComputer(bank_index: size_t(0), startRate: double(3.46), rateIncreme
reaction(compute) -> result {=
double term = compute->value;
double res = self->rate * term * (1 - term);
SET(result, res);
lf_set(result, res);
=}
}

Expand All @@ -59,15 +59,15 @@ reactor SeriesWorker(bank_index: size_t(0), termIncrement: double(0.0025), start
=}

reaction(nextTerm) -> computer.compute {=
SET(computer.compute, self->curTerm);
lf_set(computer.compute, self->curTerm);
=}

reaction(computer.result) {=
self->curTerm = computer.result->value;
=}

reaction(getTerm) -> term {=
SET(term, self->curTerm);
lf_set(term, self->curTerm);
=}
}

Expand All @@ -91,11 +91,11 @@ reactor Manager(numSeries: size_t(10), numTerms: size_t(25000)) {

reaction(start, next) -> getTerm, nextTerm, next {=
if(self->currentIteration == self->numTerms) {
SET(getTerm, 0);
lf_set(getTerm, 0);
return;
}

SET(nextTerm, 0);
lf_set(nextTerm, 0);
self->currentIteration++;
schedule(next, 0);
=}
Expand All @@ -106,7 +106,7 @@ reactor Manager(numSeries: size_t(10), numTerms: size_t(25000)) {
terms_sum += results[i]->value;
}
printf("Terms sum: %f\n", terms_sum);
SET(finished, true);
lf_set(finished, true);
self->currentIteration = 0;
=}
}
Expand Down
16 changes: 8 additions & 8 deletions C/Savina/src/concurrency/Philosophers.lf
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ reactor Philosopher(
reaction(start) -> hungry {=
info_print("Hello! I am philosopher %d, and I am very hungry!", self->bank_index);
self->times_eaten = 0;
SET(hungry, true);
lf_set(hungry, true);
=}

reaction(eat) -> done, finished, hungry {=
// ... take left and right fork
info_print("Philosopher %d is eating.", self->bank_index);
self->times_eaten++;
SET(done, true);
lf_set(done, true);

if (self->times_eaten == self->count) {
SET(finished, true);
lf_set(finished, true);
} else {
SET(hungry, true);
lf_set(hungry, true);
}
=}

reaction(denied) -> hungry {=
info_print("Philosopher %d was denied and is thinking.", self->bank_index);

// Well, I will just try again...
SET(hungry, true);
lf_set(hungry, true);
=}
}

Expand Down Expand Up @@ -143,9 +143,9 @@ reactor Arbitrator(num_philosophers:int(20)) {
reaction(send_replies) -> eat, denied {=
for(size_t i = 0; i < self->num_philosophers; i++) {
if (self->replies[i] == EAT) {
SET(eat[i], true);
lf_set(eat[i], true);
} else if (self->replies[i] == DENIED) {
SET(denied[i], true);
lf_set(denied[i], true);
}
}
memset(self->replies, INVALID, sizeof(int) * self->num_philosophers);
Expand Down Expand Up @@ -187,7 +187,7 @@ reactor Arbitrator(num_philosophers:int(20)) {
self->finished_philosophers++;
if (self->num_philosophers == self->finished_philosophers) {
printf("Arbitrator: All philosophers are sated. Number of denials to philosophers: %d\n", self->retries);
SET(allFinished, true);
lf_set(allFinished, true);
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions C/Savina/src/concurrency/SleepingBarber.lf
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ reactor CustomerFactory(numCustomers:size_t(2000), averageProductionRate:size_t(

// send the new customer to the waiting room
self->attempts++;
SET(sendCustomer, self->next_customer_id);
lf_set(sendCustomer, self->next_customer_id);

self->next_customer_id++;
if (self->next_customer_id < self->numCustomers) {
Expand All @@ -134,7 +134,7 @@ reactor CustomerFactory(numCustomers:size_t(2000), averageProductionRate:size_t(
reaction (sendCustomerAgain) -> sendCustomer {=
size_t customer_id = sendCustomerAgain->value;
self->attempts++;
SET(sendCustomer, customer_id);
lf_set(sendCustomer, customer_id);
=}

reaction (customerReturned) -> sendCustomerAgain {=
Expand All @@ -156,7 +156,7 @@ reactor CustomerFactory(numCustomers:size_t(2000), averageProductionRate:size_t(
// only need to count invocations of this reaction.
self->doneCustomers++;
if (self->doneCustomers >= self->numCustomers) {
SET(finished, true);
lf_set(finished, true);
}
=}
}
Expand Down Expand Up @@ -196,29 +196,29 @@ reactor WaitingRoom(capacity:size_t(1000), numCustomers:size_t(2000)) {
size_t customer_id = receiveCustomer->value;

if (deque_size(&self->queue) == self->capacity) {
SET(full[customer_id], true);
lf_set(full[customer_id], true);
} else {
if (self->barberAsleep) {
self->barberAsleep = false;
SET(barberEnter, customer_id);
lf_set(barberEnter, customer_id);
} else {
// Note that the customer_id is being cast to a pointer
// because the payload of a queue element is a pointer.
// As long as we never dereference that pointer, it is OK
// to recast it to size_t, assuming void* has at least as
// many bits as size_t, which it must.
deque_push_back(&self->queue, (void*)customer_id);
SET(wait[customer_id], true);
lf_set(wait[customer_id], true);
}
}
=}

reaction (barberNext) -> barberEnter, barberSleep {=
if (deque_is_empty(&self->queue)) {
self->barberAsleep = true;
SET(barberSleep, true);
lf_set(barberSleep, true);
} else {
SET(barberEnter, (size_t)deque_peek_front(&self->queue));
lf_set(barberEnter, (size_t)deque_peek_front(&self->queue));
deque_pop_front(&self->queue);
}
=}
Expand All @@ -239,7 +239,7 @@ reactor Customer(bank_index:size_t(0)) {
output done: bool;

reaction (roomFull) -> returned {=
SET(returned, true);
lf_set(returned, true);
=}

reaction (wait) {=
Expand All @@ -249,7 +249,7 @@ reactor Customer(bank_index:size_t(0)) {
=}

reaction (doneCutting) -> done {=
SET(done, true);
lf_set(done, true);
=}
}

Expand Down Expand Up @@ -300,13 +300,13 @@ reactor Barber(

reaction (done) -> doneCutting, next {=
size_t customer_id = done->value;
SET(doneCutting[customer_id], true);
SET(next, true);
lf_set(doneCutting[customer_id], true);
lf_set(next, true);
=}

reaction (enter) -> startCutting, done {=
size_t customer_id = enter->value;
SET(startCutting[customer_id], true);
lf_set(startCutting[customer_id], true);

// Calculate a random delay.
// The second argument is an upper bound (exclusive).
Expand Down
Loading