Commit 19a55d39 authored by Mohcine Chraibi's avatar Mohcine Chraibi

fix issue #199

- We need to use barrier after force/velocity calculations and
  just after the barrier start the parallel update

- The end and start values dependent on the thread ids, lead to
  race conditions if num of pedestrians is smaller then number of
  threads (pedestrians get deleted with forthcoming simulation)

- @todo: other models need the barrier mechanism too. not done in this
  commit

- @todo: Dispense with manually distributing the threads and use
  a "#pragma omp for"
parent b27ec72b
......@@ -299,20 +299,23 @@ void Simulation::UpdateRoutesAndLocations()
unsigned long nSize = allPeds.size();
int nThreads = omp_get_max_threads();
nThreads = 1;
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
#pragma omp parallel default(shared) num_threads(nThreads)
{
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 ;//= (threadID+1)*partSize-1;
// if ((threadID==nThreads-1))
// end = nSize-1;
end = (threadID < nThreads - 1) ? (threadID + 1) * partSize - 1: (int) (nSize - 1);
for (int p = start; p<=end; ++p) {
Pedestrian* ped = allPeds[p];
Pedestrian* ped = allPeds[p];
Room* room0 = _building->GetRoom(ped->GetRoomID());
SubRoom* sub0 = room0->GetSubRoom(ped->GetSubRoomID());
......@@ -365,7 +368,6 @@ void Simulation::UpdateRoutesAndLocations()
// Log->Write("WARNING:\t pedestrian [%d] left the room in an unusual way. Please check",ped->GetID());
// Log->Write(" \t distance to previous target is %f",ped->GetDistanceToNextTarget());
//}
//also statistic for internal doors
UpdateFlowAtDoors(*ped); //@todo: ar.graf : this call should move into a critical region? check plz
......
......@@ -6,7 +6,7 @@
<!-- seed used for initialising random generator -->
<seed>12542</seed>
<max_sim_time >200</max_sim_time>
<max_sim_time >1000</max_sim_time>
<!-- geometry file -->
<geometry>1.2_bottleneck.xml</geometry>
<!-- traectories file and format -->
......@@ -15,7 +15,7 @@
</trajectories>
<!-- where to store the logs -->
<logfile>log</logfile>
<num_threads>8</num_threads>
<!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints>
<!-- room states are: good or smoked -->
......@@ -47,7 +47,7 @@
<!--persons information and distribution -->
<agents operational_model_id="3">
<agents_distribution>
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="2" number="60" goal_id="0" router_id="1" />
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="2" number="20" goal_id="0" router_id="1" />
</agents_distribution>
<!-- frequency in persons/minute -->
......
......@@ -157,8 +157,9 @@ void VelocityModel::ComputeNextTimeStep(double current, double deltaT, Building*
//nThreads = 1; //debug only
int partSize;
partSize = ((int)nSize >= nThreads)? (int) (nSize / nThreads):1;
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)
{
vector< Point > result_acc = vector<Point > ();
......@@ -171,9 +172,6 @@ void VelocityModel::ComputeNextTimeStep(double current, double deltaT, Building*
int start = threadID*partSize;
int end;
end = (threadID < nThreads - 1) ? (threadID + 1) * partSize - 1: (int) (nSize - 1);
// printf("\nstart %d, end %d Thread Id %d\n", start, end, threadID);
for (int p = start; p <= end; ++p) {
// printf("\n------------------\nid=%d\t p=%d\n", threadID, p);
Pedestrian* ped = allPeds[p];
......@@ -253,7 +251,7 @@ void VelocityModel::ComputeNextTimeStep(double current, double deltaT, Building*
} // for p
//#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