0
我正在編程(C++)來合併圖像(QPainter)。按照順序,它的工作很好,但我必須將其與OpenMP並行化。我怎樣才能做到這一點?我認爲可能的問題是內存分配或嵌套for循環。這是我的第一個問題在這裏,在此先感謝:)OpenMP嵌套循環(使用Qt)
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]);
}
>>另一種方法是在主線程中創建結果數組。 該數組將如何看起來像? – bgs 2012-04-22 15:40:01
例如,'QImage * results = new QImage [count]'。 – 2012-04-22 16:22:51