--- /dev/null
+/**************************************************************************
+* *
+* 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;
+ }
+}
--- /dev/null
+/**************************************************************************
+* *
+* 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;
+ }
+
+}
--- /dev/null
+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("");
+
+
+
+ }
+
+}
--- /dev/null
+/**************************************************************************
+ * * 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 = disjoint 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");
+ }
+
+}
--- /dev/null
+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)");
+ }
+
+}
--- /dev/null
+/**************************************************************************
+* *
+* 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;
+ }
+}
--- /dev/null
+/**************************************************************************
+* *
+* 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){
+// }
+}
--- /dev/null
+/**************************************************************************
+* *
+* 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() + "}";
+ }
+}
--- /dev/null
+
+
+/**************************************************************************
+ * *
+ * 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 <code>new Vec(0,0,0)</code>
+ */
+// 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 <code>Image</code> to be rendered
+ */
+ int height;
+
+ /**
+ * Width of the <code>Image</code> to be rendered
+ */
+ int width;
+
+// int datasizes[] = { 150, 500 };
+ int datasizes[];
+
+ 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) {
+
+// long checksum;
+// checksum=0;
+
+ // Screen variables
+ int row[] = disjoint 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, new Vec(0,0,0));
+// 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++) {
+ 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[]= disjoint TEMPARRAY new int[interval.width];
+ int line_checksum=0;
+ Ray tRay = new Ray();
+ Ray r = new Ray(view.from, new Vec(0,0,0));
+
+ 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,new Isect(),new Ray(),new Vec());
+
+ // 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;
+
+ line_checksum += red;
+ line_checksum += green;
+ line_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];
+ }
+ checksum+=line_checksum;
+ if(y== (interval.yto-1)){
+ System.out.println("CHECKSUM="+checksum);
+ }
+ }
+
+ } // end for (y)
+
+ System.out.println("END OF WORK");
+
+ }
+
+
+ boolean intersect(Ray r, double maxt,Isect inter) {
+ 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,Isect inter) {
+ if (intersect(r, tmax,inter))
+ 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,Ray tRay,Vec L) {
+ 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);
+
+ L.x=lights[l].pos.x-P.x;
+ L.y=lights[l].pos.y-P.y;
+ L.z=lights[l].pos.z-P.z;
+
+ 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,hit) > 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,hit,tRay,L);
+ 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,hit,tRay,L);
+ col.adds(surf.kt, tcol);
+ }
+
+ // garbaging...
+ tcol = null;
+ surf = null;
+
+ return col;
+ }
+
+ /**
+ * Launches a ray
+ */
+ Vec trace(int level, double weight, Ray r,Isect inter,Ray tRay,Vec L) {
+
+ Vec P, N;
+ boolean hit;
+
+ // Checks the recursion level
+ if (level > 6) {
+ return new Vec();
+ }
+ hit = intersect(r, 1e6,inter);
+ 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,tRay,L);
+ }
+
+ // no intersection --> col = 0,0,0
+ return new Vec(0,0,0);
+ }
+
+}
--- /dev/null
+/**************************************************************************
+* *
+* 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);
+ }
+}
+
+
+
+
--- /dev/null
+/**************************************************************************
+* *
+* 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 double dot(double x1, double y1, double z1, double x2, double y2, double z2){
+
+ return x1*x2 + y1*y2 + z1*z2;
+
+ }
+
+ public Isect intersect(Ray ry) {
+
+
+// Vec v=new Vec();
+ double b, disc, t;
+ Isect ip;
+// Vec v=Vec.sub(c, ry.P);
+// v.sub2(c, ry.P);
+
+ double x=c.x-ry.P.x;
+ double y=c.y-ry.P.y;
+ double z=c.z-ry.P.z;
+
+ b=dot(x,y,z,ry.D.x,ry.D.y,ry.D.z);
+// b = Vec.dot(v, ry.D);
+
+// disc = b*b - Vec.dot(v, v) + r2;
+ disc = b*b -dot(x,y,z,x,y,z) + 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 = dot(x,y,z,x,y,z) > r2 + 1e-6 ? 1 : 0;
+// ip.enter = Vec.dot(v, v) > r2 + 1e-6 ? 1 : 0;
+ ip.prim = this;
+ ip.surf = surf;
+ return ip;
+
+ /*
+ 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;
+ }
+}
+
--- /dev/null
+/**************************************************************************
+* *
+* 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 + "}";
+ }
+}
+
+
--- /dev/null
+/**************************************************************************
+* *
+* 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 disjoint SUB 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
+ disjoint CROSS 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 + ">";
+ }
+}
--- /dev/null
+/**************************************************************************
+* *
+* 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;
+ }
+}
+
+
+
--- /dev/null
+BUILDSCRIPT=../../../buildscript
+
+#DEBUGFLAGS= -disjoint-debug-callsite MDRunner t3 100
+#DEBUGFLAGS= -disjoint-debug-callsite calcGoodFeature calcGoodFeatureTask 100
+#DEBUGFLAGS= -disjoint-debug-callsite getRows calcGoodFeature 4
+#DEBUGFLAGS= -disjoint-debug-callsite setKMeans t3 500
+
+#SNAPFLAGS= -disjoint-debug-snap-method calcGoodFeatureTask 5 10 true
+#SNAPFLAGS= -disjoint-debug-snap-method calcGoodFeature 5 1 true
+
+#SNAPFLAGS= -disjoint-debug-snap-method t3 5 20 true
+
+BSFLAGS= -justanalyze -disjoint -disjoint-k 1 -disjoint-write-dots all -disjoint-alias-file aliases.txt normal -enable-assertions
+
+all:
+ $(BUILDSCRIPT) $(BSFLAGS) $(DEBUGFLAGS) $(SNAPFLAGS) *.java
+
+clean:
+ rm -f *.bin
+ rm -fr tmpbuilddirectory
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f *.aux
+ rm -f *.log
+ rm -f *.pdf
+ rm -f aliases.txt
+ rm -f tabResults.tex
--- /dev/null
+public class test {
+
+ public static void main(String argv[]) {
+ JGFInstrumentor instr = new JGFInstrumentor();
+ instr.printHeader(3, 0);
+
+ JGFRayTracerBench rtb = new JGFRayTracerBench(instr);
+ rtb.JGFrun(1, instr);
+ }
+
+}