Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
added mandelbrot.java under shootout
Browse files Browse the repository at this point in the history
  • Loading branch information
kayceesrk committed Jan 11, 2014
1 parent 9995604 commit 826cb5b
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 8 deletions.
Binary file not shown.
Binary file not shown.
7 changes: 5 additions & 2 deletions trunk/testing/benchmarks/shootout-manderbrot/Makefile
@@ -1,4 +1,4 @@
all: mlton multiMLton ghc
all: mlton multiMLton ghc java

mlton: mandelbrot-sml-seq.sml
mlton mandelbrot-sml-seq.sml
Expand All @@ -9,5 +9,8 @@ multiMLton: mandelbrot-sml-par.sml
ghc: mandelbrot.ghc-2.hs
ghc --make -O2 -threaded -XBangPatterns -optc-mfpmath=sse -optc-msse2 -rtsopts mandelbrot.ghc-2.hs -o mandelbrot.ghc-2.ghc_run

java:
javac mandelbrot.java

clean:
rm -f mandelbrot-sml-seq mandelbrot-sml-par mandelbrot.ghc-2.ghc_run *.o *~
rm -f mandelbrot-sml-seq mandelbrot-sml-par mandelbrot.ghc-2.ghc_run *.o *~ *.class *.hi
4 changes: 4 additions & 0 deletions trunk/testing/benchmarks/shootout-manderbrot/README
Expand Up @@ -15,3 +15,7 @@ Note: SIZE must be a multiple of 8.
* mandelbrot.ghc-2.hs
Haskell version. Compiled with GHC. Run as ./mandelbrot.ghc-2.ghc_run +RTS
-N<NUM_PROC> -RTS <SIZE>.

* mandelbrot.java
Java version. Run as java -server -XX:+TieredCompilation
-XX:+AggressiveOpts mandelbrot <SIZE> <NUM_PROC>.
Expand Up @@ -59,15 +59,23 @@ let
client ()
end

fun receiver () =
let
val _ = repeat numChunks (fn _ =>
let val (index, buf) = recv oc
in Array.update (resultArray, index, buf)
end)
val _ = Array.app (fn buf => List.app out buf) resultArray
in
OS.Process.exit OS.Process.success
end


val _ = repeat nt (fn _ => spawn client)
val _ = spawn receiver
val _ = repeat numChunks (fn i => aSend (ic, (n, n, i*8, i*8+8)))
val _ = repeat numChunks (fn _ =>
let val (index, buf) = recv oc
in Array.update (resultArray, index, buf)
end)
val _ = Array.app (fn buf => List.app out buf) resultArray
in
OS.Process.exit OS.Process.success
()
end


Expand Down
Binary file not shown.
91 changes: 91 additions & 0 deletions trunk/testing/benchmarks/shootout-manderbrot/mandelbrot.java
@@ -0,0 +1,91 @@
/* The Computer Language Benchmarks Game
* http://benchmarksgame.alioth.debian.org/
*
* contributed by Stefan Krause
* slightly modified by Chad Whipkey
* parallelized by Colin D Bennett 2008-10-04
* reduce synchronization cost by The Anh Tran
* optimizations and refactoring by Enotus 2010-11-11
* optimization by John Stalcup 2012-2-19
*/


import java.io.*;
import java.util.concurrent.atomic.*;

public final class mandelbrot {
static byte[][] out;
static AtomicInteger yCt;
static double[] Crb;
static double[] Cib;

static int getByte(int x, int y){
int res=0;
for(int i=0;i<8;i+=2){
double Zr1=Crb[x+i];
double Zi1=Cib[y];

double Zr2=Crb[x+i+1];
double Zi2=Cib[y];

int b=0;
int j=49;do{
double nZr1=Zr1*Zr1-Zi1*Zi1+Crb[x+i];
double nZi1=Zr1*Zi1+Zr1*Zi1+Cib[y];
Zr1=nZr1;Zi1=nZi1;

double nZr2=Zr2*Zr2-Zi2*Zi2+Crb[x+i+1];
double nZi2=Zr2*Zi2+Zr2*Zi2+Cib[y];
Zr2=nZr2;Zi2=nZi2;

if(Zr1*Zr1+Zi1*Zi1>4){b|=2;if(b==3)break;}
if(Zr2*Zr2+Zi2*Zi2>4){b|=1;if(b==3)break;}
}while(--j>0);
res=(res<<2)+b;
}
return res^-1;
}

static void putLine(int y, byte[] line){
for (int xb=0; xb<line.length; xb++)
line[xb]=(byte)getByte(xb*8,y);
}

public static void main(String[] args) throws Exception {
int N=6000;
int numProc = 1;
if (args.length>=1) {
N=Integer.parseInt(args[0]);
numProc = Integer.parseInt (args[1]);
}

Crb=new double[N+7]; Cib=new double[N+7];
double invN=2.0/N; for(int i=0;i<N;i++){ Cib[i]=i*invN-1.0; Crb[i]=i*invN-1.5; }
yCt=new AtomicInteger();
out=new byte[N][(N+7)/8];

Thread[] pool=new Thread[numProc];
for (int i=0;i<pool.length;i++)
pool[i]=new Thread(){
public void run() {
int y; while((y=yCt.getAndIncrement())<out.length) putLine(y,out[y]);
}
};
for (Thread t:pool) t.start();
for (Thread t:pool) t.join();

OutputStream stream = new BufferedOutputStream(System.out);
stream.write(("P4\n"+N+" "+N+"\n").getBytes());
for(int i=0;i<N;i++) stream.write(out[i]);
stream.close();
}
}

0 comments on commit 826cb5b

Please sign in to comment.