Package com.aparapi.examples.javaonedemo
Class Life.LifeKernel
java.lang.Object
com.aparapi.Kernel
com.aparapi.examples.javaonedemo.Life.LifeKernel
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- Life
public static class Life.LifeKernel
extends com.aparapi.Kernel
LifeKernel represents the data parallel algorithm describing by Conway's game of life.
http://en.wikipedia.org/wiki/Conway's_Game_of_Life
We examine the state of each pixel and its 8 neighbors and apply the following rules.
if pixel is dead (off) and number of neighbors == 3 {
pixel is turned on
} else if pixel is alive (on) and number of neighbors is neither 2 or 3
pixel is turned off
}
We use an image buffer which is 2*width*height the size of screen and we use fromBase and toBase to track which half of the buffer is being mutated for each pass. We basically
copy from getGlobalId()+fromBase to getGlobalId()+toBase;
Prior to each pass the values of fromBase and toBase are swapped.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LifeKernel(int _width, int _height, BufferedImage _image)
-
Method Summary
Modifier and Type Method Description void
nextGeneration()
void
run()
Methods inherited from class com.aparapi.Kernel
addExecutionModes, cancelMultiPass, cleanUpArrays, clone, dispose, execute, execute, execute, execute, execute, execute, executeFallbackAlgorithm, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getAccumulatedExecutionTime, getAccumulatedExecutionTimeAllThreads, getAccumulatedExecutionTimeCurrentThread, getCancelState, getConversionTime, getCurrentPass, getExecutionMode, getExecutionTime, getKernelState, getMappedMethodName, getProfileInfo, getProfileReportCurrentThread, getProfileReportLastThread, getTargetDevice, hasFallbackAlgorithm, hasNextExecutionMode, invalidateCaches, isAllowDevice, isAutoCleanUpArrays, isExecuting, isExplicit, isMappedMethod, isOpenCLDelegateMethod, isRunningCL, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, registerProfileReportObserver, setAutoCleanUpArrays, setExecutionMode, setExecutionModeWithoutFallback, setExplicit, setFallbackExecutionMode, toString, tryNextExecutionMode, usesAtomic32, usesAtomic64
-
Constructor Details
-
Method Details
-
run
public void run()- Specified by:
run
in classcom.aparapi.Kernel
-
nextGeneration
public void nextGeneration()
-