Skip to content

Commit

Permalink
Implemented Savina FJCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
axmmisaka committed Sep 7, 2023
1 parent 5b53bf7 commit 67b1b79
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/benchmark/FJCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Typescript runtime implementation of Fork Join - Create benchmark programme
* of Savina benchmark suite.
* @author axmmisaka (github.com/axmmisaka)
*/

import {
Log,
Reactor,
App,
type TimeValue,
InPort,
OutPort
} from "../core/internal";

Log.global.level = Log.levels.ERROR;

const N = 4000;

export class ForkJoinReactor extends Reactor {
// private valueToCalculate;
triggerPort: InPort<number>;
constructor(parent: Reactor, name = "Innocent Reactor") {
super(parent);
this.triggerPort = new InPort(this);
this.addReaction(
[this.triggerPort],
[this.triggerPort],
(inp) => {
const val = inp.get();
if (val == null) {
throw new Error(`inp is absent for ${this._getFullyQualifiedName()}`)
}
const sint = Math.sin(val);
const res = sint * sint;
if (res <= 0) {
throw new Error(`this is kinda insane, ${res}`);
} else {
console.log(`I am ${this._getFullyQualifiedName()}. I finished calculating after ${this.util.getElapsedLogicalTime()}; ${this.util.getElapsedPhysicalTime()}. Result is ${res}`)
}
}
);
}
}

export class FJCreator extends Reactor {
forks: ForkJoinReactor[];
outp: OutPort<number>;

constructor(parent: Reactor) {
super(parent);
this.forks = [];
this.outp = new OutPort(this);
this.addMutation(
[this.startup],
[this.writable(this.outp)],
function (this, outp) {
console.log("startup triggered!")
for (let i = 0; i < N; ++i) {
const fork = this.addSibling(ForkJoinReactor, `FJReactor ${i}`);
// this.getReactor().forks.push(fork);
this.connect(outp.getPort(), fork.triggerPort);
console.log(`Fork ${i} created at physical time ${this.util.getElapsedPhysicalTime()}`)
}
outp.set(114.514);
}
)
}
}

export class FJHost extends App {
creator: FJCreator;
constructor(
name: string,
timeout: TimeValue | undefined = undefined,
keepAlive = false,
fast = false,
success?: () => void,
fail?: () => void
) {
super(timeout, keepAlive, fast, success, fail);
this.creator = new FJCreator(this);
}
}

const fj = new FJHost("FJ");
fj._start();

0 comments on commit 67b1b79

Please sign in to comment.