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