14| Aparapi: An Open Source tool for extending the Java™ promise of 'Write Once Run Anywhere' to include the GPU | OSCON July 18th 2012, Portland CONWAYS 'GAME OF LIFE' EXAMPLE @Override public void run() { int gid = getGlobalId(); int to = gid + toBase; int from = gid + fromBase; int x = gid%width; int y = gid/width; if ((x == 0 || x == width - 1 || y == 0 || y == height - 1)) { imageData[to] = imageData[from]; }else{ int neighbors = (imageData[from - 1] & 1) + // EAST (imageData[from + 1] & 1) + // WEST (imageData[from - width - 1] & 1) + // NORTHEAST (imageData[from - width] & 1) + // NORTH (imageData[from - width + 1] & 1) + // NORTHWEST (imageData[from + width - 1] & 1) + // SOUTHEAST (imageData[from + width] & 1) + // SOUTH (imageData[from + width + 1] & 1); // SOUTHWEST if (neighbors == 3 || (neighbors == 2 && imageData[from] == ALIVE)) { imageData[to] = ALIVE; }else{ imageData[to] = DEAD; }
{}