Skip to content

Commit

Permalink
added java fib code + cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
dpzmick committed Apr 2, 2016
1 parent 20c9640 commit ff29079
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 1 deletion.
13 changes: 13 additions & 0 deletions auto_parallel.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
Binary file modified paper/paper.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion paper/paper.tex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ \section{Introduction}

% even if it is expressed in control flow, it is still data parallelism probably
Using Clojure's macro system, we have implemented a set of macros which allow developers to take advantage of Clojure's parallelism potential when their existing code is written such that parallelism is exposed through control flow.
We have shown that it is possible to attain noticeable degrees of parallelism with minimal code changes (with respect to serial code), without the need for sophisticated dependency analysis often required in other parallelism systems.
We have shown that it is possible to attain reasonable degrees of parallelism with minimal code changes (with respect to serial code).
These transformation can be applied to idiomatic Clojure code without the need for sophisticated dependency analysis often required in other parallelism systems.
% indicate that we cooperate with STM and other clojure constructs

% the other existing libraries are also a testament to this statement
Expand Down
4 changes: 4 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

:dependencies [[org.clojure/tools.trace "0.7.9"]
[org.clojure/clojure "1.8.0"]
[com.google.caliper/caliper "0.5-rc1"]
[criterium "0.4.3"]]

:main ^:skip-aot com.dpzmick.parallel-macros
Expand All @@ -13,8 +14,11 @@
:jvm-opts ["-server"]}}

:aliases {"benchmark" ["with-profile" "benchmark" "run" "-m" "benchmark.core"]
"jbenchmark" ["with-profile" "benchmark" "run" "-m" "com.dpzmick.auto_parallel_java.App"]
"slamhound" ["run" "-m" "slam.hound"]}

:jvm-opts ["-server"]

:java-source-paths ["src_java/"]

:plugins [[lein-cloverage "1.0.2"]])
File renamed without changes.
48 changes: 48 additions & 0 deletions scripts/run_java_suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# TODO log cpu usage
# TODO log git commit hash

display_usage() {
echo -e "usage $0 output_dir"
echo -e "where"
echo -e "\toutput_dir - directory to dump results to"
}

if [ $# -lt 1 ]
then
display_usage
exit 1
fi

# first, load the environment needed for benchmarks
# the set -a thing is to force them to export
set -a
source ./env
set +a

output_dir=$1
output_dir=$output_dir/$(date +"%s")-$(hostname)
log_file=$output_dir/log

echo "Running -- writing into $output_dir"

# make a new directory for this run
mkdir -p $output_dir
cp env $output_dir/env
touch $output_dir/is_java

echo "run starting" | tee $log_file
date +"%m-%d-%y %H:%m:%S" | tee -a $log_file
date +"%s" | tee -a $log_file

echo | tee -a $log_file

lein javac | tee -a $log_file

cat /proc/cpuinfo | tee -a $log_file

# run the spec and do the output
lein jbenchmark | tee $log_file.bench

echo "finished test" >> $log_file
2 changes: 2 additions & 0 deletions run_remote.sh → scripts/run_remote.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# should never be run from the scripts directory

display_usage() {
echo -e "usage $0 num_cpus num_boxes local_out specs"
echo -e "where"
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions scripts/run_while_away.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

./run_remote.sh 1 23 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 2 12 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 4 6 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 6 4 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 1 23 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 2 12 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 4 6 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 6 4 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 1 23 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 2 12 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 4 6 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 6 4 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 1 23 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 2 12 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 4 6 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
./run_remote.sh 6 4 out-tmp benchmark_specs/fib/big/{serial.csv,parfun.csv}
72 changes: 72 additions & 0 deletions src_java/com/dpzmick/auto_parallel_java/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.dpzmick.auto_parallel_java;

import java.util.concurrent.RecursiveTask;
import java.util.concurrent.ForkJoinPool;

import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;

class FibTask extends RecursiveTask<Integer> {
private int grain_;
private int n_;

public FibTask(int n, int grain) {
grain_ = grain;
n_ = n;
}

static Integer serialCompute(int n) {
if (n == 0 || n == 1)
return 1;

return serialCompute(n - 1) + serialCompute(n - 2);
}

@Override
public Integer compute() {
if (n_ == 0 || n_ == 1) {
return 1;
}

if (n_ <= grain_) {
return serialCompute(n_);
}

FibTask f1 = new FibTask(n_ - 1, grain_);
FibTask f2 = new FibTask(n_ - 2, grain_);
f1.fork();
return f1.join() + f2.compute();
}
}


public class App {
public static class Benchmark extends SimpleBenchmark {
private int n;

@Override
protected void setUp() throws Exception {
n = Integer.parseInt(System.getenv("BIG_FIB"));
}

public void timeFibFJ(int reps) {
for (int i = 0; i < reps; i++) {
ForkJoinPool pool = new ForkJoinPool();
FibTask f = new FibTask(n, 31);
Integer res = pool.invoke(f);
System.out.println(res);
}
}

public void timeFibSerial(int reps) {
for (int i = 0; i < reps; i++) {
System.out.println(FibTask.serialCompute(n));
}
}

}

public static void main(String[] args) {
Runner.main(Benchmark.class, new String[0]);
}
}

0 comments on commit ff29079

Please sign in to comment.