Openmp渲染bmp图片

Openmp rendering bmp images

我正在尝试生成一些 julia 分形图像,我想使用多个内核来加快执行速度。但是如果我使用 parallel for 生成的图像是不好的(它们有错误颜色的线条,超出比例,......)而且,而不是 40 张图像,只创建了大约 20 张。如果我用 #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

    } 

您有典型的数据竞争条件。并行线程使用的公共数据是:imeDatoteke[7]、imeDatoteke[8]、picture[i][j]。结果线程可以使用来自其他线程的数据来创建图像。您可以为每个线程使用局部变量或使用同步对象。