1
我想要生成一些茱莉亞分形圖像,我想使用多個核心更快的執行。但是如果我使用並行處理(它們有錯誤的顏色行,超出範圍,...),並且40個圖像中只有大約20個圖像被創建,那麼生成的圖像很糟糕。如果我用#pragma刪除行,生成的圖像沒問題Openmp呈現BMP圖像
#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
}