__kernel void laplace(__global float * a, __global float * b, int size, int swap) { size_t x, y; x = get_global_id(0); y = get_global_id(1); if (y > 0 && y < size - 1 && y > 0 && y < size - 1) { if (swap) a[x + size * y] = 0.25 * (b[(x-1) + size * (y)] + b[(x-1) + size * (y)] + b[(x) + size * (y-1)] + b[(x) + size * (y+1)]); else b[x + size * y] = 0.25 * (a[(x-1) + size * (y)] + a[(x-1) + size * (y)] + a[(x) + size * (y-1)] + a[(x) + size * (y+1)]); } }