2020-12-16 11:14:47 +01:00

37 lines
1.1 KiB
Common Lisp

void kernel generation(global const int *previous, global int *new, global const int *size) {
int ID, Nthreads, n, ratio, start, stop;"
ID = get_global_id(0);
Nthreads = get_global_size(0);
n = size[0] * size[1];
ratio = (n / Nthreads); // number of elements for each thread
start = ratio * ID;
stop = ratio * (ID + 1);
for (int i=start; i<stop; i++)
int x = i % size[1];
int y = i / size[0];
int left = x - 1;
int right = (x + 1) % size[0];
int up = (y - 1 + size[1]) % size[1];
int down = (y + 1) % size[1];
// Get the number of neighbors
int neighbors =
previous[size[0] * up + left]
+ previous[size[0] * up + x]
+ previous[size[0] * up + right]
+ previous[size[0] * y + left]
+ previous[size[0] * y + right]
+ previous[size[0] * down + left]
+ previous[size[0] * down + x]
+ previous[size[0] * down + right];
// Update cell
new[size[0] * y + x] = (neighbors == 3) + previous[size[0] * y + x] * (neighbors == 2);
}