From 9ded73325669e5fb2a2ff0dade6d883511f5b154 Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 20 Jan 2010 23:50:08 +0000 Subject: [PATCH] add --- .../Benchmarks/mlp/raytracer/Interval.java | 52 ++ .../src/Benchmarks/mlp/raytracer/Isect.java | 36 ++ .../mlp/raytracer/JGFInstrumentor.java | 200 ++++++++ .../mlp/raytracer/JGFRayTracerBench.java | 105 ++++ .../Benchmarks/mlp/raytracer/JGFTimer.java | 153 ++++++ .../src/Benchmarks/mlp/raytracer/Light.java | 38 ++ .../Benchmarks/mlp/raytracer/Primitive.java | 59 +++ Robust/src/Benchmarks/mlp/raytracer/Ray.java | 47 ++ .../Benchmarks/mlp/raytracer/RayTracer.java | 466 ++++++++++++++++++ .../src/Benchmarks/mlp/raytracer/Scene.java | 89 ++++ .../src/Benchmarks/mlp/raytracer/Sphere.java | 83 ++++ .../src/Benchmarks/mlp/raytracer/Surface.java | 52 ++ Robust/src/Benchmarks/mlp/raytracer/Vec.java | 181 +++++++ Robust/src/Benchmarks/mlp/raytracer/View.java | 54 ++ Robust/src/Benchmarks/mlp/raytracer/makefile | 29 ++ Robust/src/Benchmarks/mlp/raytracer/test.java | 14 + 16 files changed, 1658 insertions(+) create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Interval.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Isect.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/JGFInstrumentor.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/JGFRayTracerBench.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/JGFTimer.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Light.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Primitive.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Ray.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/RayTracer.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Scene.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Sphere.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Surface.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/Vec.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/View.java create mode 100644 Robust/src/Benchmarks/mlp/raytracer/makefile create mode 100644 Robust/src/Benchmarks/mlp/raytracer/test.java diff --git a/Robust/src/Benchmarks/mlp/raytracer/Interval.java b/Robust/src/Benchmarks/mlp/raytracer/Interval.java new file mode 100644 index 00000000..e1d90c94 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Interval.java @@ -0,0 +1,52 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + +public class Interval +//implements java.io.Serializable +{ +/* +public int number; + public int width; + public int height; + public int yfrom; + public int yto; + public int total; +*/ + public final int number; + public final int width; + public final int height; + public final int yfrom; + public final int yto; + public final int total; + + public Interval(int number, int width, int height, int yfrom, int yto, int total) + { + this.number = number; + this.width = width; + this.height = height; + this.yfrom = yfrom; + this.yto = yto; + this.total = total; + } +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/Isect.java b/Robust/src/Benchmarks/mlp/raytracer/Isect.java new file mode 100644 index 00000000..e1ba5c10 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Isect.java @@ -0,0 +1,36 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + +public class Isect { + public double t; + public int enter; + public Sphere prim; + public Surface surf; + + public Isect(){ + t=0; + enter=0; + } + +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/JGFInstrumentor.java b/Robust/src/Benchmarks/mlp/raytracer/JGFInstrumentor.java new file mode 100644 index 00000000..42879469 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/JGFInstrumentor.java @@ -0,0 +1,200 @@ +import String; +import System; + +import java.util.Hashtable; + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + +public class JGFInstrumentor{ + + private Hashtable timers; + private Hashtable data; +// private static Hashtable timers; +// private static Hashtable data; +// +// static { +// timers = new Hashtable(); +// data = new Hashtable(); +// } + + public JGFInstrumentor(){ + timers=new Hashtable(); + data=new Hashtable(); + } + + public synchronized void addTimer (String name){ + + if (timers.containsKey(name)) { + System.out.println("JGFInstrumentor.addTimer: warning - timer " + name + + " already exists"); + } + else { + JGFTimer t=new JGFTimer(name); + timers.put(name,t); +// timers.put(name, new JGFTimer(name)); + } + } + + public synchronized void addTimer (String name, String opname){ + + if (timers.containsKey(name)) { + System.out.println("JGFInstrumentor.addTimer: warning - timer " + name + + " already exists"); + } + else { + JGFTimer t=new JGFTimer(name,opname); + timers.put(name,t); +// timers.put(name, new JGFTimer(name,opname)); + } + + } + + public synchronized void addTimer (String name, String opname, int size){ + + if (timers.containsKey(name)) { + System.out.println("JGFInstrumentor.addTimer: warning - timer " + name + + " already exists"); + } + else { + JGFTimer t=new JGFTimer(name,opname,size); + timers.put(name,t); +// timers.put(name, new JGFTimer(name,opname,size)); + } + + } + + public synchronized void startTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).start(); + } + else { + System.out.println("JGFInstrumentor.startTimer: failed - timer " + name + + " does not exist"); + } + + } + + public synchronized void stopTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).stop(); + } + else { + System.out.println("JGFInstrumentor.stopTimer: failed - timer " + name + + " does not exist"); + } + } + + public synchronized void addOpsToTimer(String name, double count){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).addops(count); + } + else { + System.out.println("JGFInstrumentor.addOpsToTimer: failed - timer " + name + + " does not exist"); + } + } + + public synchronized double readTimer(String name){ + double time; + if (timers.containsKey(name)) { + time = ((JGFTimer) timers.get(name)).time; + } + else { + System.out.println("JGFInstrumentor.readTimer: failed - timer " + name + + " does not exist"); + time = 0.0; + } + return time; + } + + public synchronized void resetTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).reset(); + } + else { + System.out.println("JGFInstrumentor.resetTimer: failed - timer " + name + + " does not exist"); + } + } + + public synchronized void printTimer(String name){ + if (timers.containsKey(name)) { + JGFTimer t=(JGFTimer) timers.get(name); + t.print(); +// ((JGFTimer) timers.get(name)).print(); + } + else { + System.out.println("JGFInstrumentor.printTimer: failed - timer " + name + + " does not exist"); + } + } + + public synchronized void printperfTimer(String name){ + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).printperf(); + } + else { + System.out.println("JGFInstrumentor.printTimer: failed - timer " + name + + " does not exist"); + } + } + +// public static synchronized void storeData(String name, Object obj){ +// data.put(name,obj); +// } + + public synchronized void retrieveData(String name, Object obj){ + obj = data.get(name); + } + + public synchronized void printHeader(int section, int size) { + + String header, base; + + header = ""; + base = "Java Grande Forum Benchmark Suite - Version 2.0 - Section "; + + if(section==1){ + header = base + "1"; + }else if(section==2){ + if(size==0){ + header = base + "2 - Size A"; + }else if(size==1){ + header = base + "2 - Size B"; + }else if(size==2){ + header = base + "2 - Size C"; + } + }else if(section==3){ + if(size==0){ + header = base + "3 - Size A"; + }else if(size==1){ + header = base + "3 - Size B"; + } + } + + System.out.println(header); + System.out.println(""); + + + + } + +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/JGFRayTracerBench.java b/Robust/src/Benchmarks/mlp/raytracer/JGFRayTracerBench.java new file mode 100644 index 00000000..f9bd8c2d --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/JGFRayTracerBench.java @@ -0,0 +1,105 @@ +/************************************************************************** + * * Java Grande Forum Benchmark Suite - Version 2.0 * * produced by * * Java + * Grande Benchmarking Project * * at * * Edinburgh Parallel Computing Centre * + * * email: epcc-javagrande@epcc.ed.ac.uk * * * This version copyright (c) The + * University of Edinburgh, 1999. * All rights reserved. * * + **************************************************************************/ + +public class JGFRayTracerBench extends RayTracer { + JGFInstrumentor instr; + + public JGFRayTracerBench(JGFInstrumentor instr) { + super(); + this.instr = instr; + } + + public void JGFsetsize(int size) { + this.size = size; + } + + public void JGFinitialise() { + +// instr.startTimer("Section3:RayTracer:Init"); + + // set image size +// width = height = datasizes[size]; + width = datasizes[size]; + height = datasizes[size]; + + // create the objects to be rendered + scene = createScene(); + + // get lights, objects etc. from scene. + setScene(scene); + + numobjects = scene.getObjects(); + +// instr.stopTimer("Section3:RayTracer:Init"); + + } + + public void JGFapplication() { + +// instr.startTimer("Section3:RayTracer:Run"); + + // Set interval to be rendered to the whole picture + // (overkill, but will be useful to retain this for parallel versions) + Interval interval = new Interval(0, width, height, 0, height, 1); + + // Do the business! + render(interval); +// System.out.println("DONE"); +// instr.stopTimer("Section3:RayTracer:Run"); + + } + + public void JGFvalidate() { + // long refval[] = {2676692,29827635}; + long refval[] = new long[2]; + refval[0] = 2676692; + refval[1] = 29827635; + long dev = checksum - refval[size]; + if (dev != 0) { + System.out.println("Validation failed"); + System.out.println("Pixel checksum = " + checksum); + System.out.println("Reference value = " + refval[size]); + } + } + + public void JGFtidyup() { + scene = null; + lights = null; + prim = null; + tRay = null; + inter = null; + + // System.gc(); + } + + public void JGFrun(int size, JGFInstrumentor instr) { + +// instr.addTimer("Section3:RayTracer:Total", "Solutions", size); +// instr.addTimer("Section3:RayTracer:Init", "Objects", size); +// instr.addTimer("Section3:RayTracer:Run", "Pixels", size); + + JGFsetsize(size); + +// instr.startTimer("Section3:RayTracer:Total"); + + JGFinitialise(); + JGFapplication(); +// JGFvalidate(); +// JGFtidyup(); + +// instr.stopTimer("Section3:RayTracer:Total"); +// +// instr.addOpsToTimer("Section3:RayTracer:Init", (double) numobjects); +// instr.addOpsToTimer("Section3:RayTracer:Run",(double) (width * height)); +// instr.addOpsToTimer("Section3:RayTracer:Total", 1); +// +// instr.printTimer("Section3:RayTracer:Init"); +// instr.printTimer("Section3:RayTracer:Run"); +// instr.printTimer("Section3:RayTracer:Total"); + } + +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/JGFTimer.java b/Robust/src/Benchmarks/mlp/raytracer/JGFTimer.java new file mode 100644 index 00000000..2332f246 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/JGFTimer.java @@ -0,0 +1,153 @@ +import System; + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + +public class JGFTimer { + + public String name; + public String opname; + public double time; + public double opcount; + public long calls; + public int size; + + private long start_time; + private boolean on; + + public JGFTimer(String name, String opname){ + this.name = name; + this.opname = opname; + size = -1; + reset(); + } + + public JGFTimer(String name, String opname, int size){ + this.name = name; + this.opname = opname; + this.size = size; + reset(); + } + + public JGFTimer(String name){ + this.name = name; + this.opname = ""; + size = -1; + reset(); + } + + + + public void start(){ + if (on) System.out.println("Warning timer " + name + " was already turned on"); + on = true; + start_time = System.currentTimeMillis(); + } + + + public void stop(){ + time += (double) (System.currentTimeMillis()-start_time) / 1000.; + if (!on) System.out.println("Warning timer " + name + " wasn't turned on"); + calls++; + on = false; + } + + public void addops(double count){ + opcount += count; + } + + public void reset(){ + time = 0.0; + calls = 0; + opcount = 0; + on = false; + } + + public double perf(){ +// System.out.println("name="+name); +// System.out.println("opcount="+opcount); +// System.out.println("time="+time); + if(time==0){ + return 0; + } + return opcount / time; + } + + public void longprint(){ + System.out.println("Timer Calls Time(s) Performance("+opname+"/s)"); + System.out.println(name + " " + calls + " " + time + " " + this.perf()); + } + + public void print(){ + if (opname.equals("")) { + System.out.println(name + " " + time + " (s)"); + } + else { + + + if(size == 0) { + System.out.println(name + ":SizeA" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)"); + } else if (size == 1) { + System.out.println(name + ":SizeB" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)"); + } else if (size == 2) { + System.out.println(name + ":SizeC" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)"); + } else{ + System.out.println(name + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)"); + } + + +// switch(size) { +// case 0: +// System.out.println(name + ":SizeA" + "\t" + time + " (s) \t " + (float)this.perf() + "\t" +// + " ("+opname+"/s)"); +// break; +// case 1: +// System.out.println(name + ":SizeB" + "\t" + time + " (s) \t " + (float)this.perf() + "\t" +// + " ("+opname+"/s)"); +// break; +// case 2: +// System.out.println(name + ":SizeC" + "\t" + time + " (s) \t " + (float)this.perf() + "\t" +// + " ("+opname+"/s)"); +// break; +// default: +// System.out.println(name + "\t" + time + " (s) \t " + (float)this.perf() + "\t" +// + " ("+opname+"/s)"); +// break; +// } + + } + } + + + public void printperf(){ + + String name; + name = this.name; + + // pad name to 40 characters + while ( name.length() < 40 ) name = name + " "; + + System.out.println(name + "\t" + (float)this.perf() + "\t" + + " ("+opname+"/s)"); + } + +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/Light.java b/Robust/src/Benchmarks/mlp/raytracer/Light.java new file mode 100644 index 00000000..01575625 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Light.java @@ -0,0 +1,38 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + +public class Light +//implements java.io.Serializable +{ + public Vec pos; + public double brightness; + + public Light() { + } + + public Light(double x, double y, double z, double brightness) { + this.pos = new Vec(x, y, z); + this.brightness = brightness; + } +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/Primitive.java b/Robust/src/Benchmarks/mlp/raytracer/Primitive.java new file mode 100644 index 00000000..281f19a8 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Primitive.java @@ -0,0 +1,59 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + +public class Primitive +//public abstract class Primitive +//implements java.io.Serializable +{ + public Surface surf; + + public Primitive(){ + surf=new Surface(); + } + + public void setColor(double r, double g, double b) { + surf.color = new Vec(r, g, b); + } + + public /*abstract*/ Vec normal(Vec pnt); + public /*abstract*/ Isect intersect(Ray ry); + public /*abstract*/ String toString(); + public /*abstract*/ Vec getCenter(); + public /*abstract*/ void setCenter(Vec c); + +// public Vec normal(Vec pnt){ +// return null; +// } +// public Isect intersect(Ray ry){ +// return null; +// } +// public String toString(){ +// return null; +// } +// public Vec getCenter(){ +// return null; +// } +// public void setCenter(Vec c){ +// } +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/Ray.java b/Robust/src/Benchmarks/mlp/raytracer/Ray.java new file mode 100644 index 00000000..afc97616 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Ray.java @@ -0,0 +1,47 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + +final public class Ray { + public Vec P, D; + + public Ray(Vec pnt, Vec dir) { + P = new Vec(pnt.x, pnt.y, pnt.z); + D = new Vec(dir.x, dir.y, dir.z); + D.normalize(); + } + + public Ray() { + P = new Vec(); + D = new Vec(); + } + + public Vec point(double t) { + return new Vec(P.x + D.x * t, P.y + D.y * t, P.z + D.z * t); + } + + public String toString() { + return "{" + P.toString() + " -> " + D.toString() + "}"; + } +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/RayTracer.java b/Robust/src/Benchmarks/mlp/raytracer/RayTracer.java new file mode 100644 index 00000000..8eeb4664 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/RayTracer.java @@ -0,0 +1,466 @@ +import java.io.FileOutputStream; + + +/************************************************************************** + * * + * Java Grande Forum Benchmark Suite - Version 2.0 * + * * + * produced by * + * * + * Java Grande Benchmarking Project * + * * + * at * + * * + * Edinburgh Parallel Computing Centre * + * * + * email: epcc-javagrande@epcc.ed.ac.uk * + * * + * Original version of this code by * + * Florian Doyon (Florian.Doyon@sophia.inria.fr) * + * and Wilfried Klauser (wklauser@acm.org) * + * * + * This version copyright (c) The University of Edinburgh, 1999. * + * All rights reserved. * + * * + **************************************************************************/ + + +public class RayTracer { + + Scene scene; + /** + * Lights for the rendering scene + */ + Light lights[]; + + /** + * Objects (spheres) for the rendering scene + */ + Primitive prim[]; + + /** + * The view for the rendering scene + */ + View view; + + /** + * Temporary ray + */ +// Ray tRay= new Ray(); + Ray tRay; + + /** + * Alpha channel + */ +// static final int alpha = 255 << 24; + static final int alpha ; + + /** + * Null vector (for speedup, instead of new Vec(0,0,0) + */ +// static final Vec voidVec = new Vec(); + static final Vec voidVec; + + /** + * Temporary vect + */ +// Vec L = new Vec(); + Vec L; + + /** + * Current intersection instance (only one is needed!) + */ +// Isect inter = new Isect(); + Isect inter; + + /** + * Height of the Image to be rendered + */ + int height; + + /** + * Width of the Image to be rendered + */ + int width; + +// int datasizes[] = { 150, 500 }; + int datasizes[]; + +// long checksum = 0; + long checksum; + + int size; + + int numobjects; + + public RayTracer() { + tRay = new Ray(); + alpha = 255 << 24; + voidVec = new Vec(); + L = new Vec(); + inter = new Isect(); + checksum=0; + datasizes = new int[2]; + datasizes[0] = 150; + datasizes[1] = 500; + numobjects=0; + width=0; + height=0; + size=0; + } + + /** + * Create and initialize the scene for the rendering picture. + * + * @return The scene just created + */ + + Scene createScene() { + int x = 0; + int y = 0; + + Scene scene = new Scene(); + + /* create spheres */ + + Primitive p; + int nx = 4; + int ny = 4; + int nz = 4; + for (int i = 0; i < nx; i++) { + for (int j = 0; j < ny; j++) { + for (int k = 0; k < nz; k++) { + double xx = 20.0 / (nx - 1) * i - 10.0; + double yy = 20.0 / (ny - 1) * j - 10.0; + double zz = 20.0 / (nz - 1) * k - 10.0; + + p = new Sphere(new Vec(xx, yy, zz), 3); + // p.setColor(i/(double) (nx-1), j/(double)(ny-1), + // k/(double) (nz-1)); + p.setColor(0, 0, (i + j) / (double) (nx + ny - 2)); + p.surf.shine = 15.0; + p.surf.ks = 1.5 - 1.0; + p.surf.kt = 1.5 - 1.0; + scene.addObject(p); + } + } + } + + /* Creates five lights for the scene */ + scene.addLight(new Light(100, 100, -50, 1.0)); + scene.addLight(new Light(-100, 100, -50, 1.0)); + scene.addLight(new Light(100, -100, -50, 1.0)); + scene.addLight(new Light(-100, -100, -50, 1.0)); + scene.addLight(new Light(200, 200, 0, 1.0)); + + /* Creates a View (viewing point) for the rendering scene */ + View v = new View(new Vec(x, 20, -30), new Vec(x, y, 0), new Vec(0, 1, + 0), 1.0, 35.0 * 3.14159265 / 180.0, 1.0); + /* + * v.from = new Vec(x, y, -30); v.at = new Vec(x, y, -15); v.up = new + * Vec(0, 1, 0); v.angle = 35.0 * 3.14159265 / 180.0; v.aspect = 1.0; + * v.dist = 1.0; + */ + scene.setView(v); + + return scene; + } + + public void setScene(Scene scene) { + // Get the objects count + int nLights = scene.getLights(); + int nObjects = scene.getObjects(); + + lights = new Light[nLights]; + prim = new Primitive[nObjects]; + + // Get the lights + for (int l = 0; l < nLights; l++) { + lights[l] = scene.getLight(l); + } + + // Get the primitives + for (int o = 0; o < nObjects; o++) { + prim[o] = scene.getObject(o); + } + + // Set the view + view = scene.getView(); + } + + public void render(Interval interval) { + + // Screen variables + int row[] = new int[interval.width * (interval.yto - interval.yfrom)]; + int pixCounter = 0; // iterator + + // Rendering variables +// int x, y, red, green, blue; +// double xlen, ylen; + Vec viewVec; + + viewVec = Vec.sub(view.at, view.from); + + viewVec.normalize(); + + Vec tmpVec = new Vec(viewVec); + tmpVec.scale(Vec.dot(view.up, viewVec)); + + Vec upVec = Vec.sub(view.up, tmpVec); + upVec.normalize(); + + Vec leftVec = Vec.cross(view.up, viewVec); + leftVec.normalize(); + + double frustrumwidth = view.dist * Math.tan(view.angle); + + upVec.scale(-frustrumwidth); + leftVec.scale(view.aspect * frustrumwidth); + + Ray r = new Ray(view.from, voidVec); +// Vec col = new Vec(); + + // Header for .ppm file + // System.out.println("P3"); + // System.out.println(width + " " + height); + // System.out.println("255"); + + // All loops are reversed for 'speedup' (cf. thinking in java p331) + + // For each line + for (int y = interval.yfrom; y < interval.yto; y++) { +// for (int y = 0; y < 3; y++) { + double ylen = (double) (2.0 * y) / (double) interval.width - 1.0; +// System.out.println("Doing line " + y); + // For each pixel of the line, launch parallel sese + sese parallel{ + int tempArray[]=new int[interval.width]; + for (int x = 0; x < interval.width; x++) { + Vec col = new Vec(); + double xlen = (double) (2.0 * x) / (double) interval.width - 1.0; + int pixCounter_t=y*(interval.width)+x; + + r.D = Vec.comb(xlen, leftVec, ylen, upVec); + r.D.add(viewVec); + r.D.normalize(); + + col = trace(0, 1.0, r); + + // computes the color of the ray + + int red = (int) (col.x * 255.0); + if (red > 255) + red = 255; + int green = (int) (col.y * 255.0); + if (green > 255) + green = 255; + int blue = (int) (col.z * 255.0); + if (blue > 255) + blue = 255; + + checksum += red; + checksum += green; + checksum += blue; + + // RGB values for .ppm file + // System.out.println(red + " " + green + " " + blue); + // Sets the pixels +// row[pixCounter_t] = alpha | (red << 16) | (green << 8) | (blue); + tempArray[x]= alpha | (red << 16) | (green << 8) | (blue); + } // end for (x) + + } // end of sese line + + sese serial{ + for (int x = 0; x < interval.width; x++) { + int pixCounter_t=y*(interval.width)+x; + row[pixCounter_t] = tempArray[x]; + } + } + + } // end for (y) + + System.out.println("END OF WORK"); + + } + + boolean intersect(Ray r, double maxt) { + Isect tp; + int i, nhits; + + nhits = 0; + inter.t = 1e9; + for (i = 0; i < prim.length; i++) { + // uses global temporary Prim (tp) as temp.object for speedup + tp = prim[i].intersect(r); + if (tp != null && tp.t < inter.t) { + inter.t = tp.t; + inter.prim = tp.prim; + inter.surf = tp.surf; + inter.enter = tp.enter; + nhits++; + } + } + return nhits > 0 ? true : false; + } + + /** + * Checks if there is a shadow + * + * @param r + * The ray + * @return Returns 1 if there is a shadow, 0 if there isn't + */ + int Shadow(Ray r, double tmax) { + if (intersect(r, tmax)) + return 0; + return 1; + } + + /** + * Return the Vector's reflection direction + * + * @return The specular direction + */ + Vec SpecularDirection(Vec I, Vec N) { + Vec r; + r = Vec.comb(1.0 / Math.abs(Vec.dot(I, N)), I, 2.0, N); + r.normalize(); + return r; + } + + /** + * Return the Vector's transmission direction + */ + Vec TransDir(Surface m1, Surface m2, Vec I, Vec N) { + double n1, n2, eta, c1, cs2; + Vec r; + n1 = m1 == null ? 1.0 : m1.ior; + n2 = m2 == null ? 1.0 : m2.ior; + eta = n1 / n2; + c1 = -Vec.dot(I, N); + cs2 = 1.0 - eta * eta * (1.0 - c1 * c1); + if (cs2 < 0.0) + return null; + r = Vec.comb(eta, I, eta * c1 - Math.sqrt(cs2), N); + r.normalize(); + return r; + } + + /** + * Returns the shaded color + * + * @return The color in Vec form (rgb) + */ + Vec shade(int level, double weight, Vec P, Vec N, Vec I, Isect hit) { + double n1, n2, eta, c1, cs2; + Vec r; + Vec tcol; + Vec R; + double t, diff, spec; + Surface surf; + Vec col; + int l; + + col = new Vec(); + surf = hit.surf; + R = new Vec(); + if (surf.shine > 1e-6) { + R = SpecularDirection(I, N); + } + + // Computes the effectof each light + for (l = 0; l < lights.length; l++) { + L.sub2(lights[l].pos, P); + if (Vec.dot(N, L) >= 0.0) { + t = L.normalize(); + + tRay.P = P; + tRay.D = L; + + // Checks if there is a shadow + if (Shadow(tRay, t) > 0) { + diff = Vec.dot(N, L) * surf.kd * lights[l].brightness; + + col.adds(diff, surf.color); + if (surf.shine > 1e-6) { + spec = Vec.dot(R, L); + if (spec > 1e-6) { + spec = Math.pow(spec, surf.shine); + col.x += spec; + col.y += spec; + col.z += spec; + } + } + } + } // if + } // for + + tRay.P = P; + if (surf.ks * weight > 1e-3) { + tRay.D = SpecularDirection(I, N); + tcol = trace(level + 1, surf.ks * weight, tRay); + col.adds(surf.ks, tcol); + } + if (surf.kt * weight > 1e-3) { + if (hit.enter > 0) + tRay.D = TransDir(null, surf, I, N); + else + tRay.D = TransDir(surf, null, I, N); + tcol = trace(level + 1, surf.kt * weight, tRay); + col.adds(surf.kt, tcol); + } + + // garbaging... + tcol = null; + surf = null; + + return col; + } + + /** + * Launches a ray + */ + Vec trace(int level, double weight, Ray r) { + Vec P, N; + boolean hit; + + // Checks the recursion level + if (level > 6) { + return new Vec(); + } + + hit = intersect(r, 1e6); + if (hit) { + P = r.point(inter.t); + N = inter.prim.normal(P); + if (Vec.dot(r.D, N) >= 0.0) { + N.negate(); + } + return shade(level, weight, P, N, r.D, inter); + } + // no intersection --> col = 0,0,0 + return voidVec; + } + + public static void main(String argv[]) { + + RayTracer rt = new RayTracer(); + + // create the objects to be rendered + rt.scene = rt.createScene(); + + // get lights, objects etc. from scene. + rt.setScene(rt.scene); + + // Set interval to be rendered to the whole picture + // (overkill, but will be useful to retain this for parallel versions) + Interval interval = new Interval(0, rt.width, rt.height, 0, rt.height, + 1); + + // Do the business! + rt.render(interval); + + } + +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/Scene.java b/Robust/src/Benchmarks/mlp/raytracer/Scene.java new file mode 100644 index 00000000..226f99c3 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Scene.java @@ -0,0 +1,89 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + +import java.util.Vector; + +public class Scene +//implements java.io.Serializable +{ + public final Vector lights; + public final Vector objects; + private View view; + + public Scene () + { + this.lights = new Vector (); + this.objects = new Vector (); + } + + public void addLight(Light l) + { + this.lights.addElement(l); + } + + public void addObject(Primitive object) + { + this.objects.addElement(object); + } + + public void setView(View view) + { + this.view = view; + } + + public View getView() + { + return this.view; + } + + public Light getLight(int number) + { + return (Light) this.lights.elementAt(number); + } + + public Primitive getObject(int number) + { + return (Primitive) objects.elementAt(number); + } + + public int getLights() + { + return this.lights.size(); + } + + public int getObjects() + { + return this.objects.size(); + } + + public void setObject(Primitive object, int pos) + { + this.objects.setElementAt(object, pos); + } +} + + + + diff --git a/Robust/src/Benchmarks/mlp/raytracer/Sphere.java b/Robust/src/Benchmarks/mlp/raytracer/Sphere.java new file mode 100644 index 00000000..03feb1cc --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Sphere.java @@ -0,0 +1,83 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + +public class Sphere extends Primitive +//implements java.io.Serializable +{ + Vec c; + double r, r2; + Vec v,b; // temporary vecs used to minimize the memory load + + + public Sphere(Vec center, double radius) { + super(); + c = center; + r = radius; + r2 = r*r; + v=new Vec(); + b=new Vec(); + } + + public Isect intersect(Ray ry) { + double b, disc, t; + Isect ip; + v.sub2(c, ry.P); + b = Vec.dot(v, ry.D); + disc = b*b - Vec.dot(v, v) + r2; + if (disc < 0.0) { + return null; + } + disc = Math.sqrt(disc); + t = (b - disc < 1e-6) ? b + disc : b - disc; + if (t < 1e-6) { + return null; + } + ip = new Isect(); + ip.t = t; + ip.enter = Vec.dot(v, v) > r2 + 1e-6 ? 1 : 0; + ip.prim = this; + ip.surf = surf; + return ip; + } + + public Vec normal(Vec p) { + Vec r; + r = Vec.sub(p, c); + r.normalize(); + return r; + } + + public String toString() { + return "Sphere {" + c.toString() + "," + r + "}"; + } + + public Vec getCenter() { + return c; + } + public void setCenter(Vec c) { + this.c = c; + } +} + diff --git a/Robust/src/Benchmarks/mlp/raytracer/Surface.java b/Robust/src/Benchmarks/mlp/raytracer/Surface.java new file mode 100644 index 00000000..3fada018 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Surface.java @@ -0,0 +1,52 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + +public class Surface +//implements java.io.Serializable +{ + public Vec color; + public double kd; + public double ks; + public double shine; + public double kt; + public double ior; + public boolean isnull; + + public Surface() { + color = new Vec(1, 0, 0); + kd = 1.0; + ks = 0.0; + shine = 0.0; + kt = 0.0; + ior = 1.0; + isnull=false; + } + + public String toString() { + return "Surface { color=" + color + "}"; + } +} + + diff --git a/Robust/src/Benchmarks/mlp/raytracer/Vec.java b/Robust/src/Benchmarks/mlp/raytracer/Vec.java new file mode 100644 index 00000000..5bb112a2 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/Vec.java @@ -0,0 +1,181 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + + +/** + * This class reflects the 3d vectors used in 3d computations + */ +public class Vec +//implements java.io.Serializable +{ + + /** + * The x coordinate + */ + public double x; + + /** + * The y coordinate + */ + public double y; + + /** + * The z coordinate + */ + public double z; + + /** + * Constructor + * @param a the x coordinate + * @param b the y coordinate + * @param c the z coordinate + */ + public Vec(double a, double b, double c) { + x = a; + y = b; + z = c; + } + + /** + * Copy constructor + */ + public Vec(Vec a) { + x = a.x; + y = a.y; + z = a.z; + } + /** + * Default (0,0,0) constructor + */ + public Vec() { + x = 0.0; + y = 0.0; + z = 0.0; + } + + /** + * Add a vector to the current vector + * @param: a The vector to be added + */ + public final void add(Vec a) { + x+=a.x; + y+=a.y; + z+=a.z; + } + + /** + * adds: Returns a new vector such as + * new = sA + B + */ + public static Vec adds(double s, Vec a, Vec b) { + return new Vec(s * a.x + b.x, s * a.y + b.y, s * a.z + b.z); + } + + /** + * Adds vector such as: + * this+=sB + * @param: s The multiplier + * @param: b The vector to be added + */ + public final void adds(double s,Vec b){ + x+=s*b.x; + y+=s*b.y; + z+=s*b.z; + } + + /** + * Substracs two vectors + */ + public static Vec sub(Vec a, Vec b) { + return new Vec(a.x - b.x, a.y - b.y, a.z - b.z); + } + + /** + * Substracts two vects and places the results in the current vector + * Used for speedup with local variables -there were too much Vec to be gc'ed + * Consumes about 10 units, whether sub consumes nearly 999 units!! + * cf thinking in java p. 831,832 + */ + public final void sub2(Vec a,Vec b) { + this.x=a.x-b.x; + this.y=a.y-b.y; + this.z=a.z-b.z; + } + + public static Vec mult(Vec a, Vec b) { + return new Vec(a.x * b.x, a.y * b.y, a.z * b.z); + } + + public static Vec cross(Vec a, Vec b) { + return + new Vec(a.y*b.z - a.z*b.y, + a.z*b.x - a.x*b.z, + a.x*b.y - a.y*b.x); + } + + public static double dot(Vec a, Vec b) { + return a.x*b.x + a.y*b.y + a.z*b.z; + } + + public static Vec comb(double a, Vec A, double b, Vec B) { + return + new Vec(a * A.x + b * B.x, + a * A.y + b * B.y, + a * A.z + b * B.z); + } + + public final void comb2(double a,Vec A,double b,Vec B) { + x=a * A.x + b * B.x; + y=a * A.y + b * B.y; + z=a * A.z + b * B.z; + } + + public final void scale(double t) { + x *= t; + y *= t; + z *= t; + } + + public final void negate() { + x = -x; + y = -y; + z = -z; + } + + public final double normalize() { + double len; + len = Math.sqrt(x*x + y*y + z*z); + if (len > 0.0) { + x /= len; + y /= len; + z /= len; + } + return len; + } + + public final String toString() { + return "<" + x + "," + y + "," + z + ">"; + } +} diff --git a/Robust/src/Benchmarks/mlp/raytracer/View.java b/Robust/src/Benchmarks/mlp/raytracer/View.java new file mode 100644 index 00000000..f9a84186 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/View.java @@ -0,0 +1,54 @@ +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Version 2.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by * +* Florian Doyon (Florian.Doyon@sophia.inria.fr) * +* and Wilfried Klauser (wklauser@acm.org) * +* * +* This version copyright (c) The University of Edinburgh, 1999. * +* All rights reserved. * +* * +**************************************************************************/ + + + +public class View +//implements java.io.Serializable +{ +/* public Vec from; + public Vec at; + public Vec up; + public double dist; + public double angle; + public double aspect;*/ + public final Vec from; + public final Vec at; + public final Vec up; + public final double dist; + public final double angle; + public final double aspect; + + public View (Vec from, Vec at, Vec up, double dist, double angle, double aspect) + { + this.from = from; + this.at = at; + this.up = up; + this.dist = dist; + this.angle = angle; + this.aspect = aspect; + } +} + + + diff --git a/Robust/src/Benchmarks/mlp/raytracer/makefile b/Robust/src/Benchmarks/mlp/raytracer/makefile new file mode 100644 index 00000000..e5b9f8c6 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/makefile @@ -0,0 +1,29 @@ +PROGRAM=test + +SOURCE_FILES=test.java + +BUILDSCRIPT=~/eclipse/workspaces/irvine_sep09/Robust/src/buildscript + +USEMLP= -mlp 8 2 -mlpdebug # use to turn mlp on and off and make sure rest of build not broken +BSFLAGS= -64bit -nooptimize -debug -garbagestats -mainclass test +OWNERSHIP= -ownership -ownallocdepth 1 -enable-assertions -methodeffects -flatirusermethods -ownwritedots final -ownaliasfile aliases.txt + +default: + ../../../buildscript -nojava $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES) + +single: + ../../../buildscript $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES) + +java: + ../../../buildscript $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES) + +clean: + rm -f $(PROGRAM).bin + rm -fr tmpbuilddirectory + rm -f *~ + rm -f *.dot + rm -f *.png + rm -f *.txt + rm -f aliases.txt + rm -f mlpReport*txt + rm -f results*txt diff --git a/Robust/src/Benchmarks/mlp/raytracer/test.java b/Robust/src/Benchmarks/mlp/raytracer/test.java new file mode 100644 index 00000000..0b126e07 --- /dev/null +++ b/Robust/src/Benchmarks/mlp/raytracer/test.java @@ -0,0 +1,14 @@ +public class test { + + public static void main(String argv[]) { + + JGFInstrumentor instr = new JGFInstrumentor(); + + instr.printHeader(3, 0); + + JGFRayTracerBench rtb = new JGFRayTracerBench(instr); + rtb.JGFrun(0, instr); + + } + +} -- 2.34.1