Commit cc87deac authored by Mohcine Chraibi's avatar Mohcine Chraibi

Fix thread distribution for Gompertz and GCFM

parent 19a55d39
......@@ -144,7 +144,11 @@ void GCFMModel::ComputeNextTimeStep(double current, double deltaT, Building* bui
int nThreads = omp_get_max_threads();
int partSize = nSize / nThreads;
int partSize;
partSize = ((int)nSize > nThreads)? (int) (nSize / nThreads):(int)nSize;
if(partSize == (int)nSize)
nThreads = 1; // not worthy to parallelize
int debugPed = -10;
//building->GetGrid()->HighlightNeighborhood(debugPed, building);
#pragma omp parallel default(shared) num_threads(nThreads)
......@@ -155,8 +159,8 @@ void GCFMModel::ComputeNextTimeStep(double current, double deltaT, Building* bui
const int threadID = omp_get_thread_num();
int start = threadID*partSize;
int end = (threadID + 1) * partSize - 1;
if ((threadID == nThreads - 1)) end = nSize - 1;
int end;
end = (threadID < nThreads - 1) ? (threadID + 1) * partSize - 1: (int) (nSize - 1);
for (int p = start; p <= end; ++p) {
......@@ -227,7 +231,7 @@ void GCFMModel::ComputeNextTimeStep(double current, double deltaT, Building* bui
result_acc.push_back(acc);
}
//#pragma omp barrier
#pragma omp barrier
// update
for (int p = start; p <= end; ++p) {
Pedestrian* ped = allPeds[p];
......
......@@ -149,7 +149,9 @@ void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building
int nThreads = omp_get_max_threads();
int partSize;
partSize = (int) (nSize / nThreads);
partSize = ((int)nSize > nThreads)? (int) (nSize / nThreads):(int)nSize;
if(partSize == (int)nSize)
nThreads = 1; // not worthy to parallelize
#pragma omp parallel default(shared) num_threads(nThreads)
{
......@@ -160,9 +162,7 @@ void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building
int start = threadID * partSize;
int end;
end = (threadID + 1) * partSize - 1;
if ((threadID == nThreads - 1)) end = (int) (nSize - 1);
end = (threadID < nThreads - 1) ? (threadID + 1) * partSize - 1: (int) (nSize - 1);
for (int p = start; p <= end; ++p) {
Pedestrian *ped = allPeds[p];
......@@ -229,7 +229,7 @@ void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building
result_acc.push_back(acc);
}
//#pragma omp barrier
#pragma omp barrier
// update
for (int p = start; p <= end; ++p) {
Pedestrian *ped = allPeds[p];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment