我正在编写一个程序(C++)来合并图像(QPainter)。以顺序方式它工作得很好,但我必须将它与 OpenMP 并行化。我怎样才能做到这一点?我认为可能的问题是内存分配或嵌套 for 循环。这是我的第一个问题,在此先感谢:)
int width = (x2-x1)+1;
int height = (y2-y1)+1;
//every image is 256x256
QImage mapa = QImage(256*width, 256*height, QImage::Format_ARGB32_Premultiplied);
QPainter painter(&mapa);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
int x=0;
int y=0;
#pragma omp parallel
{
char *kawalek;
#pragma omp parallel for lastprivate(i) firstprivate(j) shared(x1, x2, y1, y2, painter) reduction(+:y, x)
for(i=y1; i<=y2; i++){
x=0;
#pragma omp parallel for shared(x1, x2, i, y, painter) reduction(+:x)
for(j=x1; j<=x2; j++){
{
kawalek = (char*) malloc(snprintf(NULL, 0, "pobrane/%d_%d.png", j, i)+1);
sprintf(kawalek, "pobrane/%d_%d.png", j, i);
//cout << "czesc: " << kawalek << endl;
QImage fragment(kawalek);
painter.drawImage(x, y, fragment);
//cout << "wspolrzedne czesci x: " << x << "y: " << y << endl;
}
x+=256;
}
y+=256;
}
}
painter.end();
mapa.save(filename);
@Riateche,谢谢;)
我的下一个问题是为什么那个循环不加速......
#pragma omp parallel for private(i) shared(ile)
for(i=0; i<ile; i++){
results[i].load(sciezki[i]);
}