我有这段代码。我正在尝试应用 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];
}
}