SDL_CONFIG = $(shell sdl-config --cflags)
SDL_LIBS = $(shell sdl-config --libs)
-CFLAGS = $(SDL_CONFIG) -Wall -O2 -g
-
+CFLAGS = $(SDL_CONFIG) -Wall -O2 -g -fopenmp
+LDFLAGS = -fopenmp
LIBS = $(SDL_LIBS) -lm -lrt
CC = gcc
endif
mandelbrot: $(MANDELBROT_OBJS)
- $(QUIET_LINK)$(CC) $(LIBS) -o $@ $(MANDELBROT_OBJS)
+ $(QUIET_LINK)$(CC) $(LIBS) $(LDFLAGS) -o $@ $(MANDELBROT_OBJS)
debug-mandelbrot: $(MANDELBROT_DEBUG_OBJS)
- $(QUIET_LINK)$(CC) $(LIBS) -o $@ $(MANDELBROT_DEBUG_OBJS) -DDEBUG
+ $(QUIET_LINK)$(CC) $(LIBS) $(LDFLAGS) -o $@ $(MANDELBROT_DEBUG_OBJS) \
+ -DDEBUG
.c.o:
$(QUIET_CC)$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@
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)
putpixel(screen, xs, ys,
iteration * 8, iteration,
iteration / 4);
+ x0 += xstep;
}
-
- SDL_Flip(screen);
}
+ SDL_Flip(screen);
return 0;
}