Package com.aparapi.examples.life
Class Main.LifeKernel
java.lang.Object
com.aparapi.Kernel
com.aparapi.examples.life.Main.LifeKernel
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- Main
public static class Main.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
processPixel(int gid)
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
-
processPixel
public void processPixel(int gid) -
run
public void run()- Specified by:
run
in classcom.aparapi.Kernel
-
nextGeneration
public void nextGeneration()
-