Skip to content

Instantly share code, notes, and snippets.

@chaoyangnz
Created March 30, 2017 23:03
Show Gist options
  • Save chaoyangnz/169b9c480b45133e616bf86c41c35c93 to your computer and use it in GitHub Desktop.
Save chaoyangnz/169b9c480b45133e616bf86c41c35c93 to your computer and use it in GitHub Desktop.
package life;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
/**
* Example main program for running the sequential Game-of-Life.
*
* @author Mark.Utting
*
*/
public class Main {
final static int GENERATIONS = 20; //4080;
final static int BOARD_SIZE = 32768; //1024;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// control parameters
final Executor executor = ForkJoinPool.commonPool();
// final Executor executor = Executors.newFixedThreadPool(8);
final int rowsPerTask = 128;
int times = 20; int ignoreTimes = 5; double sum = 0;
for (int iter = 0; iter < times; iter++) {
// SequentialLife life = new SequentialLife(BOARD_SIZE);
// RowParallelLife life = new RowParallelLife(BOARD_SIZE, executor, rowsPerTask);
RowParallelLife1DByteArray life = new RowParallelLife1DByteArray(BOARD_SIZE, executor, rowsPerTask);
// RowParallelLifeBitSet life = new RowParallelLifeBitSet(BOARD_SIZE, executor, rowsPerTask);
// BlockParallelLife life = new BlockParallelLife(BOARD_SIZE, executor, rowsPerTask, 256);
InputStream input = Main.class.getResourceAsStream("/gosperGliderGun.patt");
life.loadPattern(input);
System.out.println("Starting " + GENERATIONS + " generations of "
+ BOARD_SIZE + "x" + BOARD_SIZE);
final long startTime = System.nanoTime();
for (int gen = 0; gen < GENERATIONS; gen++) {
life.age();
}
final long endTime = System.nanoTime();
System.out.println("Time taken was " + (endTime - startTime) / 1.0e9 + " secs");
// life.printBoard(40, 40);
if(iter >= ignoreTimes) sum += (endTime - startTime) / 1.0e9;
}
System.out.println("Average Time taken was " + sum/(times-ignoreTimes) + " secs");
((ExecutorService)executor).shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment