The Mandelbrot set

The Mandelbrot set kernel with double precision floats (see The Mandelbrot set Anatomy and Animated M-set explorer).
Your GPU must support cl_khr_fp64 or cl_amd_fp64 extensions (see the WebCL test).

<script id="clProgramMandelbrot" type="text/x-opencl">
#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#else
#pragma OPENCL EXTENSION cl_amd_fp64 : enable
#endif
  __kernel void ckMandelbrot(__global int* max, float scale){
    int x = get_global_id(0),  y = get_global_id(1);
    double Cr = (x - 256) / scale + .407476;
    double Ci = (y - 256) / scale + .234204;
    double I=0, R=0,  I2=0, R2=0;
    int n=0;
    while ( (R2+I2 < 2.) && (n < 512) ){
      I=(R+R)*I+Ci;  R=R2-I2+Cr;  R2=R*R;  I2=I*I;  n++;
    }
    max[y*512 + x] = n;
  }
</script>          

WebCL Demos     updated 10 May 2011