Simulations on GPU. Introduction

Super-computer in your home PC

Modern video cards with thousands of shaders have performance more than 1TFlops. Access to the main GPU memory takes hundreds of cycles and can slow down calculations. But if you have a task in which thousands of independent similar threads start at the same time, then while some of them are waiting for memory other can be calculated. Therefore your GPU may be 100 times faster than CPU.

WebGL and fractal generation on GPU

We can use "graphical" GLSL shaders to generate fractals on GPU. The fragment shader below calculates color for the pixel with coordinates vec2 gl_FragCoord (see e.g. The Mandelbrot and Julia sets Anatomy)
<script id="shader-fs" type="x-shader/x-fragment"> 
precision highp float;
  uniform vec2 scale;
  const vec2 c = vec2(.259, .001);
void main(void) {
   float R = (gl_FragCoord.x - scale.x) / scale.y;
   float I = (gl_FragCoord.y - scale.x) / scale.y;
   float R2 = R*R, I2 = I*I;
   int mm;
   for(int m = 0; m < 255; m++){
     I=(R+R)*I + c.y;  R=R2-I2 + c.x;  R2=R*R;  I2=I*I;   mm = m;
     if( R2 + I2 > 4. ) break;
   if (mm == 254) gl_FragColor = vec4(0., 0., 0., 1.);
    float a = float(mm);  a = mod(a, 60.) / 20.;
    gl_FragColor = vec4( max(0., abs(a - 1.5) - .5),
      max(0., 1. - abs(a - 1.)), max(0., 1. - abs(a - 2.)), 1.);
Then WebGL executes the fragment shader for every pixel. By the way I can get up to 8000×8000 fractal picture (with the corresponding canvas size) and save it as image in Firefox.
Simulations on GPU
updated   2 June 2011