私はこのコードを持っています。OpenMP を適用__gnu_parallel::for_each
して並列化しようとしていますが、どの方法も機能していません。
私は何をすべきか?ここで make は集合のベクトルで、集合に含まれる型は ですOctCell*
。
このアルゴリズムは正しい出力を提供しますが、コードの速度は向上しません。私は4つのコアを持っています。
void Oct :: applyFunction3(void (*Function)(OctCell* cell), unsigned int level)
{
__gnu_parallel::for_each(make.at(level).begin(),make.at(level).end(),Function);
}
関数は
void directionalSweepX(OctCell* cell) {
OctCell* positiveCell,*negativeCell;
positiveCell = cell->getNeighbour(RIGHT);
negativeCell = cell->getNeighbour(LEFT);
addFluxToConserveds(cell, positiveCell, negativeCell, X);
}
addFluxtoConserveds は次のことを行います
void addFluxToConserveds(OctCell* cell, OctCell* positiveCell, OctCell* negativeCell, SWEEP_DIRECTION direction) {
double deltaT = pow(2.0, cell->getLevel() - cell->getParentOct()->lMin)*gDeltaT;
// You have corrected that delta t is delta (L)
double alpha = (1 << (int) cell->getParentOct()->lMin) * gDeltaT/gL;// whats the purpose f <<
double beta = alpha/8.0;
double gamma;
double Flux[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
if ( positiveCell == 0) {
Flux[direction+1] = getPressure(cell);
} else if ( positiveCell->isLeaf() ) {
computeFlux(cell, positiveCell, direction, Flux);
gamma = (positiveCell->getLevel() == cell->getLevel()) ? alpha : beta;
}
for (int i=0; i<5; i++) {
cell->mConserveds_n[i] -= alpha * Flux[i];
if (positiveCell) positiveCell->mConserveds_n[i] += gamma * Flux[i];
}
Flux[0] = Flux[1] = Flux[2] = Flux[3] = Flux[4] = 0.0;
if ( negativeCell == 0 ) {
Flux[direction+1] = getPressure(cell);
} else if (negativeCell->isLeaf() && negativeCell->getLevel() == cell->getLevel() - 1 ) {
computeFlux(negativeCell, cell, direction, Flux);
}
for (int i=0; i<5; i++) {
cell->mConserveds_n[i] += alpha * Flux[i];
if (negativeCell) negativeCell->mConserveds_n[i] -= beta * Flux[i];
}
}