Skip to content

Commit ab1b8e6

Browse files
authored
Merge pull request #55 from lf-lang/c-separate-gen-files
Changes to accommodate refactoring of C runtime
2 parents dfba277 + 2efec4e commit ab1b8e6

35 files changed

+149
-107
lines changed

C/Savina/src/BenchmarkRunner.lf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ target C;
3434
* @author Matt Chorlian
3535
* @author Arthur Deng
3636
*/
37+
38+
preamble {=
39+
#include <stdio.h>
40+
=}
41+
3742
reactor BenchmarkRunner(num_iterations:int(12)) {
3843

3944
/** Signal to start execution. Set this input from a startup reaction in the main reactor. */

C/Savina/src/concurrency/Banking.lf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,22 @@
6161
threading: false,
6262
/// [[[end]]]
6363
files: ["../include/PseudoRandom.h",
64+
"../include/benchmark_runner.h",
6465
"/lib/c/reactor-c/util/deque.h",
6566
"/lib/c/reactor-c/util/deque.c"],
67+
cmake-include: ["../include/deque.cmake"],
6668
logging: warn,
6769
fast: true
6870
};
6971

7072
import BenchmarkRunner from "../BenchmarkRunner.lf";
7173

7274
preamble {=
75+
#include "benchmark_runner.h"
7376
#include "PseudoRandom.h"
74-
#include "deque.c"
77+
#include "deque.h"
7578
#include <float.h>
76-
long seed = 123456;
79+
extern long seed;
7780
typedef deque_t message_queue_t;
7881
typedef struct CreditMessage {
7982
size_t recipient;
@@ -84,6 +87,10 @@ preamble {=
8487

8588
reactor Teller(numAccounts:int(1000), numBankings:int(50000)) {
8689

90+
preamble {=
91+
long seed = 123456;
92+
=}
93+
8794
state message_queues : {=message_queue_t*=};
8895
state random_gen : {=PseudoRandom *=};
8996
input start: bool;

C/Savina/src/concurrency/BoundedBuffer.lf

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ target C {
3333
/// [[[end]]]
3434
files: ["/lib/c/reactor-c/util/deque.h",
3535
"/lib/c/reactor-c/util/deque.c",
36+
"../include/benchmark_runner.h",
3637
"../include/PseudoRandom.h"],
38+
cmake-include: ["../include/deque.cmake"],
3739
flags: "-lm",
3840
logging: "warn",
3941
fast: true
@@ -45,32 +47,33 @@ import BenchmarkRunner from "../BenchmarkRunner.lf";
4547
preamble {=
4648
#include "PseudoRandom.h"
4749
#include <math.h>
48-
49-
double processItem(double curTerm, size_t cost) {
50-
double res = curTerm;
51-
52-
PseudoRandom random;
53-
random.mValue = cost;
54-
55-
if(cost > 0) {
56-
for(size_t i = 0; i < cost; i++) {
57-
for(size_t j = 0; j < 100; j++) {
58-
res += log(fabs(nextDouble(&random)) + 0.01);
59-
}
60-
}
61-
} else {
62-
res += log(fabs(nextDouble(&random)) + 0.01);
63-
}
64-
65-
return res;
66-
}
50+
#include "deque.h"
51+
#include "benchmark_runner.h"
52+
double processItem(double curTerm, size_t cost);
6753
=}
6854

6955

7056
reactor ManagerReactor(bufferSize: size_t(50), numProducers: size_t(40), numConsumers: size_t(40)) {
7157

7258
preamble {=
73-
#include "deque.c"
59+
double processItem(double curTerm, size_t cost) {
60+
double res = curTerm;
61+
62+
PseudoRandom random;
63+
random.mValue = cost;
64+
65+
if(cost > 0) {
66+
for(size_t i = 0; i < cost; i++) {
67+
for(size_t j = 0; j < 100; j++) {
68+
res += log(fabs(nextDouble(&random)) + 0.01);
69+
}
70+
}
71+
} else {
72+
res += log(fabs(nextDouble(&random)) + 0.01);
73+
}
74+
75+
return res;
76+
}
7477
=}
7578

7679
input start: bool;

C/Savina/src/concurrency/CigaretteSmoker.lf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,18 @@ target C {
7070
]]] */
7171
threading: false,
7272
/// [[[end]]]
73-
files: "../include/PseudoRandom.h",
73+
files: ["../include/PseudoRandom.h", "../include/benchmark_runner.h"],
7474
fast: true
7575
};
7676

7777
import BenchmarkRunner from "../BenchmarkRunner.lf";
7878

79+
preamble {=
80+
#include "PseudoRandom.h"
81+
=}
7982

8083
reactor ArbiterReactor(numRounds:size_t(1000), numSmokers:size_t(200)) {
8184

82-
preamble {=
83-
#include "PseudoRandom.h"
84-
=}
85-
8685
state roundsSoFar: size_t(0);
8786
state random: PseudoRandom*;
8887

C/Savina/src/concurrency/Dictionary.lf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ preamble {=
4747
#include <map>
4848
#include <vector>
4949
#include <memory>
50+
#include <random>
5051
enum class AccessType {
5152
Read,
5253
Write
@@ -151,10 +152,6 @@ reactor DictionaryImpl(numWorkers: size_t(20)) {
151152

152153
reactor Worker(bank_index: size_t(0), numMessagesPerWorker: size_t(10000), writePercentage: int(10)) {
153154

154-
preamble {=
155-
#include <random>
156-
=}
157-
158155
state messageCount: size_t(0);
159156
state random: std::minstd_rand;
160157

C/Savina/src/concurrency/SleepingBarber.lf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ target C {
5353
]]] */
5454
threading: false,
5555
/// [[[end]]]
56-
files: ["/lib/c/reactor-c/util/deque.h", "/lib/c/reactor-c/util/deque.c", "../include/PseudoRandom.h"]
56+
files: ["/lib/c/reactor-c/util/deque.h", "/lib/c/reactor-c/util/deque.c", "../include/PseudoRandom.h"],
57+
cmake-include: ["../include/deque.cmake"]
5758
};
5859

5960
import BenchmarkRunner from "../BenchmarkRunner.lf";
@@ -62,8 +63,9 @@ import BenchmarkRunner from "../BenchmarkRunner.lf";
6263
preamble {=
6364

6465
#include "PseudoRandom.h"
66+
#include "deque.h"
6567

66-
size_t busyWait(size_t limit) {
68+
static size_t busyWait(size_t limit) {
6769
size_t test = 0;
6870
for(size_t k = 0; k < limit; k++) {
6971
// The Java Math.random() is used as workload in the original Akka Savina benchmark suite.
@@ -171,9 +173,6 @@ reactor CustomerFactory(numCustomers:size_t(2000), averageProductionRate:size_t(
171173
* to the customer ID.
172174
*/
173175
reactor WaitingRoom(capacity:size_t(1000), numCustomers:size_t(2000)) {
174-
preamble {=
175-
#include "deque.c"
176-
=}
177176

178177
input reset_state:bool;
179178
input receiveCustomer: size_t;

C/Savina/src/concurrency/SortedList.lf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ preamble {=
4242
access_type type;
4343
int value;
4444
} message_t;
45+
46+
template <typename T>
47+
class SortedLinkedList;
48+
#include "PseudoRandom.h"
4549
=}
4650

4751
reactor Manager(numWorkers: size_t(20)) {

C/Savina/src/include/PseudoRandom.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ typedef struct PseudoRandom {
1515
/**
1616
* Initialize the random number generator to the specified seed.
1717
*/
18-
void initPseudoRandom(struct PseudoRandom* random, long seed) {
18+
static void initPseudoRandom(struct PseudoRandom* random, long seed) {
1919
random->mValue = seed;
2020
}
2121

2222
/**
2323
* Return a random number between 0 and 65535
2424
*/
25-
long nextLong(struct PseudoRandom *random) {
25+
static long nextLong(struct PseudoRandom *random) {
2626
random->mValue = ((random->mValue * 1309) + 13849) & 65535;
2727
return random->mValue;
2828
}
2929

3030
/**
3131
* Return a random number between 0 and 65535
3232
*/
33-
int nextInt(struct PseudoRandom *random) {
33+
static int nextInt(struct PseudoRandom *random) {
3434
return (int)nextLong(random);
3535
}
3636

3737
/**
3838
* Return a random number between 1.0/65536
3939
* and 1.0.
4040
*/
41-
double nextDouble(struct PseudoRandom *random) {
41+
static double nextDouble(struct PseudoRandom *random) {
4242
return 1.0 / (nextLong(random) + 1);
4343
}
4444

4545
/**
4646
* Return a random number between 0 and exclusive_max - 1.
4747
*/
48-
int nextIntEMax(struct PseudoRandom *random, int exclusive_max) {
48+
static int nextIntEMax(struct PseudoRandom *random, int exclusive_max) {
4949
return nextInt(random) % exclusive_max;
5050
}
5151

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void printBenchmarkInfo(char* benchmarkId);
2+
3+
void printSystemInfo();

C/Savina/src/include/deque.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target_sources(${LF_MAIN_TARGET} PRIVATE deque.c)

0 commit comments

Comments
 (0)