]> git.itanic.dy.fi Git - mandelbrot/blobdiff - mandelbrot.c
Parallelize with openmp
[mandelbrot] / mandelbrot.c
index be706ebc1d15a01002c41f1943185afafabdd172..624fcf2ebda615e2275021d1d50aa59b91624a30 100644 (file)
@@ -45,8 +45,12 @@ int draw_mandelbrot(struct SDL_Surface *screen, double x1, double x2,
        xstep = xlen / (double)screen->w;
        ystep = ylen / (double)screen->h;
 
-       for (ys = 0, y0 = y1; ys < screen->h; y0 += ystep, ys++) {
-               for (xs = 0, x0 = x1; xs < screen->w; x0 += xstep, xs++) {
+       y0 = y1;
+#pragma omp parallel for private(xs, ys, x0, y0)
+       for (ys = 0; ys < screen->h; ys++) {
+               y0 = y1 + ystep * ys;
+               x0 = x1;
+               for (xs = 0; xs < screen->w; xs++) {
                        iteration = get_mandelbrot_iterations(x0, y0);
 
                        if (iteration == MAX_ITERATION)
@@ -55,11 +59,11 @@ int draw_mandelbrot(struct SDL_Surface *screen, double x1, double x2,
                                putpixel(screen, xs, ys,
                                        iteration * 8, iteration,
                                        iteration / 4);
+                       x0 += xstep;
                }
-
-               SDL_Flip(screen);
        }
 
+       SDL_Flip(screen);
        return 0;
 }