use of joprt.RtThread in project jop by jop-devel.
the class LocalMatrixCalc method main.
public static void main(String[] args) {
// Initialization for benchmarking
int start = 0;
int stop = 0;
int time = 0;
System.out.println("Matrix Benchmark:");
long seed = 13;
initializeArrays(seed);
int nrCpu = Runtime.getRuntime().availableProcessors();
stats = new int[nrCpu];
for (int i = 0; i < nrCpu; i++) {
RtThread rtt = new LocalMatrixCalc(i);
rtt.setProcessor(i);
}
// Start threads on this and other CPUs
RtThread.startMission();
// give threads time to setup their memory
RtThread.sleepMs(100);
System.out.println("Start calculation");
// Start of measurement
start = (int) System.currentTimeMillis();
go = true;
while (true) {
synchronized (lock) {
if (endCalculation == N)
break;
}
}
// End of measurement
stop = (int) System.currentTimeMillis();
System.out.println("StartTime: " + start);
System.out.println("StopTime: " + stop);
time = stop - start;
System.out.println("TimeSpent: " + time);
for (int i = 0; i < nrCpu; ++i) {
System.out.println("CPU " + i + " calculated " + stats[i] + " rows");
}
}
use of joprt.RtThread in project jop by jop-devel.
the class SimpleScope method main.
/**
* @param args
*/
public static void main(String[] args) {
final ScopedMemory scope = new LTMemory(20000L);
final ScopedMemory inner = new LTMemory(10000L);
final Runnable run = new Runnable() {
public void run() {
MyRunner r = new MyRunner();
for (int i = 0; i < 10; ++i) {
Abc abc = new Abc();
r.setAbc(abc);
r.setOuter(scope);
for (int j = 0; j < 10; ++j) {
inner.enter(r);
}
}
}
};
System.out.println("some new");
new RtThread(10, 500000) {
public void run() {
for (; ; ) {
for (int i = 0; i < 20; ++i) {
System.out.print("*");
scope.enter(run);
// this is a dangling reference
// sa.ref.toString();
}
waitForNextPeriod();
}
}
};
System.out.println("start mission");
RtThread.startMission();
System.out.println("mission started");
}
use of joprt.RtThread in project jop by jop-devel.
the class EratosthenesCsp3 method main.
/**
* @param args
*/
public static void main(String[] args) {
// Initialization for benchmarking
int start = 0;
int stop = 0;
int time = 0;
System.out.println("Eratosthenes Sieve, v3, SPM");
SysDevice sys = IOFactory.getFactory().getSysDevice();
int nrCpu = Runtime.getRuntime().availableProcessors();
for (int i = 0; i < nrCpu; i++) {
int ni = i + 1;
if (ni == nrCpu)
ni = 0;
System.out.println(cpuIndex2NoCAddress(ni));
RtThread rtt = new EratosthenesCsp3(i, cpuIndex2NoCAddress(ni));
rtt.setProcessor(i);
}
System.out.println("starting cpus.");
// start threads and other cpus
RtThread.startMission();
// give threads time to setup their memory
// RtThread.sleepMs(100);
// using clock cycles instead
// (int) System.currentTimeMillis();
start = sys.cntInt;
// let them run
go = true;
// wait for finish
while (true) {
synchronized (lock) {
if (// nrCpu) // just the first needs to finish!
endCalculation == 1)
break;
}
}
// End of measurement
// (int) System.currentTimeMillis();
stop = sys.cntInt;
System.out.println("StartTime: " + start);
System.out.println("StopTime: " + stop);
time = stop - start;
System.out.println("TimeSpent: " + time);
}
use of joprt.RtThread in project jop by jop-devel.
the class EratosthenesCsp4 method main.
/**
* @param args
*/
public static void main(String[] args) {
// Initialization for benchmarking
int start = 0;
int stop = 0;
int time = 0;
System.out.println("Eratosthenes Sieve, v4, shared memory");
SysDevice sys = IOFactory.getFactory().getSysDevice();
int nrCpu = Runtime.getRuntime().availableProcessors();
wrCPU = new boolean[nrCpu];
lvlCPU = new int[nrCpu];
candidateCPU = new int[nrCpu];
for (int i = 0; i < nrCpu; i++) {
int ni = i + 1;
if (ni == nrCpu)
ni = 0;
RtThread rtt = new EratosthenesCsp4(i, ni);
rtt.setProcessor(i);
wrCPU[i] = false;
}
System.out.println("starting cpus.");
// start threads and other cpus
RtThread.startMission();
// give threads time to setup their memory
RtThread.sleepMs(100);
// using clock cycles instead
// (int) System.currentTimeMillis();
start = sys.cntInt;
// let them run
go = true;
// wait for finish
while (true) {
synchronized (lock) {
if (// nrCpu) // just the first needs to finish!
endCalculation == 1)
break;
}
}
// End of measurement
// (int) System.currentTimeMillis();
stop = sys.cntInt;
System.out.println("StartTime: " + start);
System.out.println("StopTime: " + stop);
time = stop - start;
System.out.println("TimeSpent: " + time);
}
use of joprt.RtThread in project jop by jop-devel.
the class HelloCsp method main.
/**
* @param args
*/
public static void main(String[] args) {
int start = 0;
int stop = 0;
int time = 0;
System.out.println("Csp Hello World");
int nrCpu = Runtime.getRuntime().availableProcessors();
if (nrCpu < 3) {
throw new Error("Not enogh CPUs");
}
Runnable sender = new Runnable() {
public void run() {
while (NoC.isSending()) {
// wait
}
Native.wr(2, NoC.NOC_REG_SNDDST);
// there is no send function in NoC :-(
Native.wr(CNT, NoC.NOC_REG_SNDCNT);
for (int i = 0; i < CNT; ++i) {
Native.wr(i, NoC.NOC_REG_SNDDATA);
}
}
};
Runnable receiver = new Runnable() {
public void run() {
while (!NoC.isReceiving()) {
// wait
}
for (int i = 0; i < CNT; ++i) {
int val = Native.rd(NoC.NOC_REG_RCVDATA);
}
NoC.writeReset();
finished = true;
}
};
// ni must be translated from proc index to NoC address!
new RtThread(sender, 1, 1000).setProcessor(1);
new RtThread(receiver, 1, 1000).setProcessor(2);
// start the other CPUs
System.out.println("starting cpus.");
RtThread.startMission();
start = (int) System.currentTimeMillis();
while (!finished) {
;
}
// End of measurement
stop = (int) System.currentTimeMillis();
System.out.println("StartTime: " + start);
System.out.println("StopTime: " + stop);
time = stop - start;
System.out.println("TimeSpent: " + time);
}
Aggregations