user5431481
user5431481

Reputation:

Openmp rendering bmp images

I am trying to generate some julia fractal images and I would like to use multiple cores for faster execution. But generated images are bad if I i use parallel for (they have lines of wrong color, are out of scale,...) and also, instead of 40 images, only about 20 are created. Generated images are fine if I delete line with #pragma

#pragma omp parallel for
    for (k = 0; k < 40; k++) { //for loop that creates 40 images
        z.Im = scale;     //z and c are complex numbers

            imeDatoteke[7] = k / 10 + '0'; // file name
            imeDatoteke[8] = k % 10 + '0';

            c.Im += 0.005; // imaginary part increments every image  

            for (i = 0; i < DIM - 1; i++) { //DIM is image dimension

                z.Im -= 2 * scale / (DIM - 1);
                z.Re = -scale;

                for (j = 0; j < DIM - 1; j++) {

                    z.Re += 2 * scale / (DIM - 1);

                    picture[i][j] = polinom(z, c); // a function that returns color between 0 and 255
                }
            }

            saveBMP(picture, DIM, DIM, imeDatoteke); //save image arrays in bpm files

    } 

Upvotes: 1

Views: 381

Answers (1)

Unick
Unick

Reputation: 674

You have classic data race condition. Parallel threads use common data it is: imeDatoteke[7], imeDatoteke[8], picture[i][j]. As the result thread can use data from other thread to create image. You can use local variables for each thread or use sync objects.

Upvotes: 2

Related Questions