Код: Выделить всё
void solveIncompressibilityRedBlackForColumns(const float dt, const float overRelaxation, const int startColumn, const int endColumn, const bool red) {
int n = this->numY;
for (int i = startColumn; i < endColumn; ++i) {
for (int j = 1; j < numY - 1; ++j) {
if (red) {
if ((i + j) % 2 != 0) {
continue;
}
}
if (!red) {
if ((i + j) % 2 == 0) {
continue;
}
}
if (this->cellType[i * n + j] == FLUID_CELL) {
float leftType = cellType[(i - 1) * n + j] v[i * n + j];
if (this->particleRestDensity > 0.f) {
float k = 10.f; // 3, 10
float compression = this->particleDensity[i * n + j] -this->particleRestDensity;
if (compression > 0.f) {
divergence = divergence - k * compression;
}
}
float p = divergence / divideBy;
p *= overRelaxation;
this->u[i * n + j] += leftType * p;
this->u[(i + 1) * n + j] -= rightType * p;
this->v[i * n + j] += topType * p;
this->v[i * n + j + 1] -= bottomType * p;
}
}
}
}
}
Код: Выделить всё
for (int _ = 0; _ < 10; ++_) {
for (int i = 0; i < numThreads; ++i) {
if (i != numThreads - 1) {
thread_pool.addTask([&, this, i]() {
this->solveIncompressibilityRedBlackForRows(sdtoverRelaxation, i * numRowsEachThread + 1, i*numRowsEachThread + numRowsEachThread + 1, true);
});
}
else {
thread_pool.addTask([&, this, i]() {
this->solveIncompressibilityRedBlackForRows(sdtoverRelaxation, i * numRowsEachThread + 1, i*numRowsEachThread + numRowsEachThread + numMissedRows + 1, true);
});
}
}
thread_pool.waitForCompletion();
for (int i = 0; i < numThreads; ++i) {
if (i != numThreads - 1) {
thread_pool.addTask([&, this, i]() {
this->solveIncompressibilityRedBlackForRows(sdtoverRelaxation, i * numRowsEachThread + 1, i*numRowsEachThread + numRowsEachThread + 1, false);
});
}
else {
thread_pool.addTask([&, this, i]() {
this->solveIncompressibilityRedBlackForRows(sdt, overRelaxation, i * numRowsEachThread + 1, i * numRowsEachThread + numRowsEachThread + numMissedRows + 1, false);
});
}
}
thread_pool.waitForCompletion();
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... nning-slow