Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
axmmisaka committed Aug 22, 2023
1 parent bce6352 commit 3f7a21f
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 35 deletions.
7 changes: 5 additions & 2 deletions src/benchmark/sucoverrelax/actor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/prefer-readonly */
// The SOR (Re)actor
import { Reactor, State } from "../../core/internal";
import { InPort, Reactor, State } from "../../core/internal";
import { Message } from "./sorutils";

Check failure on line 4 in src/benchmark/sucoverrelax/actor.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

export class SORActor extends Reactor {
constructor(
Expand All @@ -22,6 +23,8 @@ export class SORActor extends Reactor {
const omegaOverFour = 0.25 * omega;

Check failure on line 23 in src/benchmark/sucoverrelax/actor.ts

View workflow job for this annotation

GitHub Actions / lint

'omegaOverFour' is assigned a value but never used
const oneMinusOmega = 1.0 - omega;

Check failure on line 24 in src/benchmark/sucoverrelax/actor.ts

View workflow job for this annotation

GitHub Actions / lint

'oneMinusOmega' is assigned a value but never used

this.portFromRunner = new InPort<Message>(this);

const neighbours = (() => {

Check failure on line 28 in src/benchmark/sucoverrelax/actor.ts

View workflow job for this annotation

GitHub Actions / lint

'neighbours' is assigned a value but never used
const calPos = (x: number, y: number): number => (x * ny + y);

Expand Down Expand Up @@ -60,5 +63,5 @@ export class SORActor extends Reactor {
private msgRcv = new State(0);
private sorActors = new State<Reactor[]>([]);

protected
public portFromRunner: InPort<Message>;
}
61 changes: 57 additions & 4 deletions src/benchmark/sucoverrelax/peer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,71 @@
import { Reactor, State } from "../../core/internal";
import { InPort, MutationSandbox, OutPort, Reactor, State } from "../../core/internal";
import { SORActor } from "./actor";
import { SORRunner } from "./runner";
import { SorBorder } from "./sorutils";
import { Message, MessageTypes, SorBorder as SORBorder, SorBorder } from "./sorutils";

export class SORPeer extends Reactor {

s: State<number>;
partStart: State<number>;
matrixPart: State<number[][]>;
border: State<SORBorder>;
sorSource: State<SORRunner>


sorActors: State<Reactor[]>;
public portFromSORRunner: InPort<Message>;

constructor(
parent: Reactor,
s: number,
partStart: number,
matrixPart: number[][],
border: SorBorder,
border: SORBorder,
sorSource: SORRunner
) {
super(parent, "SORPeer");
this.sorActors = new State([]);
this.s = new State(s);
this.partStart = new State(partStart);
this.matrixPart = new State(matrixPart);
this.border = new State(border);
this.sorSource = new State(sorSour ce);

Check failure on line 32 in src/benchmark/sucoverrelax/peer.ts

View workflow job for this annotation

GitHub Actions / jest

',' expected.

this.portFromSORRunner = new InPort(this);
}
}

static boot(this: MutationSandbox, args: BootProcessingArgs) {
const myBorder: SORActor[] = [];
const {_s, border, sorActors, partStart} = args;
const s = _s.get();
const partStartVal = partStart.get();

const sorActorsValue = sorActors.get();
const borderValue = border.get();
for (let i = 0; i < s; ++i) {
sorActorsValue[i * (s - partStartVal + 1)] = borderValue.borderActors[i];
}
sorActors.set(sorActorsValue);

for ()

Check failure on line 50 in src/benchmark/sucoverrelax/peer.ts

View workflow job for this annotation

GitHub Actions / jest

Expression expected.
}

Check failure on line 51 in src/benchmark/sucoverrelax/peer.ts

View workflow job for this annotation

GitHub Actions / jest

Expression expected.
}

interface BootProcessingArgs {
type: MessageTypes.sorBootMessage,
_s: State<number>,
border: State<SORBorder>,
sorActors: State<SORActor[]>,
partStart: State<number>,
}
interface ResultProcessingArgs {
type: MessageTypes.sorResultMessage,
expectingBoot: State<boolean>,
totalMsgRcv: State<number>,
returned: State<number>,
gTotal: State<number>,
s: State<number>,
part: State<number>
}

type ProcessingArgs = BootProcessingArgs | ResultProcessingArgs;
175 changes: 155 additions & 20 deletions src/benchmark/sucoverrelax/runner.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import { InMultiPort, InPort, OutMultiPort, OutPort, Parameter, Reactor, State, } from "../../core/internal";
import { InMultiPort, InPort, MutationSandbox, OutMultiPort, OutPort, Parameter, Reactor, State, Variable, } from "../../core/internal";

Check failure on line 1 in src/benchmark/sucoverrelax/runner.ts

View workflow job for this annotation

GitHub Actions / lint

Import "MutationSandbox" is only used as types

Check failure on line 1 in src/benchmark/sucoverrelax/runner.ts

View workflow job for this annotation

GitHub Actions / lint

'InMultiPort' is defined but never used

Check failure on line 1 in src/benchmark/sucoverrelax/runner.ts

View workflow job for this annotation

GitHub Actions / lint

'OutMultiPort' is defined but never used

Check failure on line 1 in src/benchmark/sucoverrelax/runner.ts

View workflow job for this annotation

GitHub Actions / lint

'Parameter' is defined but never used

Check failure on line 1 in src/benchmark/sucoverrelax/runner.ts

View workflow job for this annotation

GitHub Actions / lint

'Variable' is defined but never used
import { SORActor } from "./actor";
import { SORPeer } from "./peer";
import { Message, SorBorder, omega } from "./sorutils";
import { Message, MessageTypes, SORBootMessage, SORResultMessage, SorBorder, jacobi, omega } from "./sorutils";

Check failure on line 4 in src/benchmark/sucoverrelax/runner.ts

View workflow job for this annotation

GitHub Actions / lint

Import "Message" is only used as types

export class SORRunner extends Reactor {
protected sorActors: State<Reactor[]>;
protected sorPeer: State<Reactor | undefined>;
protected s: State<number>;
protected part: State<number>;

protected sorActors: State<SORActor[]>;
protected sorPeer: State<SORPeer | undefined>;

protected portToSORActors: OutPort<Message>;
protected portToSORPeer: OutPort<Message>;
// Unsure if this would work, let's just try......
protected portFromSORActor: InPort<Message>;
protected portFromSORPeer: InPort<Message>;

protected gTotal = new State(0.0);
protected returned = new State(0);
protected totalMsgRcv = new State(0);
protected expectingBoot = new State(true);

// In Savina, randoms is accessed directly from SucOverRelaxConfig.
// Here we pass it in to the closure.
constructor(parent: Reactor, size: number, _randoms: number[][]) {
super(parent, "SORRunner");
// These are in SorRunner;
const s = size;
this.s = new State(size);
// In the scala implementation a simple /2 was used.
// In JS we might need to enforce some sort of guarantee as it was used to calculate position
const part = Math.floor(s / 2);
this.part = new State(Math.floor(size / 2));
/** These are from Savina. They should be rather irrelevant, actually. */
this.sorActors = new State([]);
this.sorPeer = new State(undefined);
Expand All @@ -28,16 +38,105 @@ export class SORRunner extends Reactor {
// This creates a bunch of ports.
this.portToSORActors = new OutPort(this);
this.portToSORPeer = new OutPort(this);

// SorRunner::boot()
this.portFromSORActor = new InPort(this);
this.portFromSORPeer = new InPort(this);

this.addMutation(
[this.startup],
[this.sorActors, this.sorPeer],
function (this, sorActors, sorPeer) {
const myBorder: Reactor[] = [];
const randoms = _randoms;
[this.sorActors, this.sorPeer, this.portToSORActors, this.portToSORPeer],
function (this, sorActors, sorPeer, portToSORActors, portToSORPeer) {
// TODO: Add actual stuff
;
}
);
}

// This is to be used WITHIN mutation react functions.
static process(this: MutationSandbox, message: Message, args: ProcessingArgs): void {
switch (message.messageType) {
case MessageTypes.sorBootMessage: {
if (args.type !== MessageTypes.sorBootMessage) {
throw new Error("Wrong type of arguments passed.");
}
// expectingBoot is args[0]
args.expectingBoot.set(false);
SORRunner.boot.apply(this, [args]);
break;
}
case MessageTypes.sorResultMessage: {
if (args.type !== MessageTypes.sorResultMessage) {
throw new Error("Wrong type of arguments passed.");
}

// In scala, (i <- 0 until s) is loop excluding s.
const {mv, msgRcv} = message;
const {expectingBoot, totalMsgRcv, returned, gTotal, s, part} = args;

if (expectingBoot.get()) {
throw new Error("SORRunner not booted yet!");
}

totalMsgRcv.set(totalMsgRcv.get() + msgRcv);
returned.set(returned.get() + 1);
gTotal.set(gTotal.get() + mv);

if (returned.get() === (s.get() * part.get()) + 1) {
// TODO: validate
// TODO: exit
;
}
break;
}
case MessageTypes.sorBorderMessage: {
if (args.type !== MessageTypes.sorBorderMessage) {
throw new Error("Wrong type of arguments passed.");
}

const {mBorder} = message;
const {expectingBoot, s, part, sorActors, portToSORActors} = args;

if (expectingBoot.get()) {
throw new Error("SORRunner not booted yet!");
}
const sorActorsValue = sorActors.get();
for (let i = 0; i <= s.get(); ++i) {
sorActorsValue[(i + 1) * (part.get() + 1) - 1] = mBorder.borderActors[i];
}
sorActors.set(sorActorsValue);
for (let i = 0; i <= s.get(); ++i) {
for (let j = 0; j <= part.get(); ++j) {
const pos = (i * (part.get() + 1)) + j;
// Ibidem, connect then disconnect to simulate
// "fire and forget" in scala.
this.connect(portToSORActors, sorActorsValue[pos].portFromRunner);
this.getReactor().writable(portToSORActors).set(
{
messageType: MessageTypes.sorStartMessage,
mi: jacobi,
mActors: sorActorsValue
}
);
this.disconnect(portToSORActors, sorActorsValue[pos].portFromRunner);
}
}
break;
}
default: {
throw new Error("Received wrong message from port");
}
}
}

// SorRunner::boot()
static boot(this: MutationSandbox,
args: BootProcessingArgs
): void {
const {_randoms, _s, _part, sorActors, sorPeer, portToSORPeer} = args;

const myBorder: SORActor[] = [];
const randoms = _randoms;
const s = _s.get();
const part = _part.get();
// In scala, (i <- 0 until s) is a loop excluding s.
const sorActorsValue = sorActors.get();
for (let i = 0; i < s; ++i) {
let c = i % 2;
Expand All @@ -51,7 +150,7 @@ export class SORRunner extends Reactor {
SORActor,
pos, randoms[i][j], c, s, part + 1, omega, this.getReactor(), false
);
// TODO: Make connections

if (j === (part - 1)) {
myBorder[i] = sorActorsValue[pos];
}
Expand All @@ -69,14 +168,50 @@ export class SORRunner extends Reactor {

const sorPeerValue = this.getReactor()._uncheckedAddSibling(
SORPeer,
s, part, partialMatrix, new SorBorder(myBorder),
s, part, partialMatrix, new SorBorder(myBorder),
// A dirty hack. Maybe this will be removed as ports get added.
this.getReactor() as SORRunner
);
);
sorPeer.set(sorPeerValue);
// TODO: Add connections.

}
);
// Pass message.
// This is similar to Scala's !; but it looks pretty...... interesting in LF.
// If node is concurrent or parallel, this might be a problem, so direct copy-pastaing to C++ runtime might not work.
this.connect(portToSORPeer, sorPeerValue.portFromSORRunner);
this.getReactor().writable(portToSORPeer).set({messageType: MessageTypes.sorBootMessage});
// Disconnect immediately.
this.disconnect(portToSORPeer, sorPeerValue.portFromSORRunner);
}
}


interface BootProcessingArgs {
type: MessageTypes.sorBootMessage,
expectingBoot: State<boolean>,
_randoms: number[][],
_s: State<number>,
_part: State<number>,
sorActors: State<SORActor[]>,
sorPeer: State<SORPeer>,
portToSORPeer: OutPort<Message>
}

interface ResultProcessingArgs {
type: MessageTypes.sorResultMessage,
expectingBoot: State<boolean>,
totalMsgRcv: State<number>,
returned: State<number>,
gTotal: State<number>,
s: State<number>,
part: State<number>
}

interface BorderProcessingArgs {
type: MessageTypes.sorBorderMessage,
expectingBoot: State<boolean>,
s: State<number>,
part: State<number>,
sorActors: State<SORActor[]>,
portToSORActors: OutPort<Message>
}

type ProcessingArgs = BootProcessingArgs | ResultProcessingArgs | BorderProcessingArgs;
39 changes: 33 additions & 6 deletions src/benchmark/sucoverrelax/sorutils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Reactor } from "../../core/reactor";
import { SORActor } from "./actor";

// Savina implementation of PRNG
export class SavinaPRNG {
Expand Down Expand Up @@ -62,21 +63,47 @@ export function jgfValidate(gTotal: number, size: number): void {
}

export enum MessageTypes {
sorBootMessage,
sorResultMessage,
sorBorderMessage,
sorStartMessage,
sorValueMessage,
sorBootMessage,
sorResuleMessage
}

export class SorBorder {
borderActors: Reactor[];
constructor(borderActors: Reactor[]) {
borderActors: SORActor[];
constructor(borderActors: SORActor[]) {
this.borderActors = borderActors;
}
}

export interface Message {
messageType: MessageTypes;
export interface SORBootMessage {
messageType: MessageTypes.sorBootMessage;
}

export interface SORResultMessage {
messageType: MessageTypes.sorResultMessage;
mx: number;
my: number;
mv: number;
msgRcv: number;
}

export interface SORBorderMessage {
messageType: MessageTypes.sorBorderMessage;

mBorder: SorBorder;
}

export interface SORStartMessage {
messageType: MessageTypes.sorStartMessage;
mi: number;
mActors: SORActor[];
}

export interface SORValueMessage {
messageType: MessageTypes.sorValueMessage;
}

export type Message = SORBootMessage | SORResultMessage | SORBorderMessage | SORStartMessage | SORValueMessage;

Loading

0 comments on commit 3f7a21f

Please sign in to comment.