Last active
August 29, 2015 14:22
-
-
Save ncollier/8030c144c902cf803584 to your computer and use it in GitHub Desktop.
Large-Scale Agent-based Modeling with Repast HPC: A Case Study in Parallelizing an Agent-based Model, supplementary materials (PADABS 2015 Workshop Paper)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NextAct next_act; | |
size_t n = persons.size(); | |
#pragma omp parallel for firstprivate(next_act) | |
for (size_t i = 0; i < n; ++i) { | |
auto& person = persons[i]; | |
person->selectNextAct(cal, next_act); | |
#pragma omp critical | |
{ | |
next_act.place->addPerson(person); | |
} | |
} | |
n = places.size(); | |
#pragma omp parallel for | |
for (size_t i = 0; i < n; ++i) { | |
places[i]->clear(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *data variable contains all person data to a process as an array of ints | |
// total_amt_received variable is the total number of persons received by the receiving process | |
// remote_persons map is the cache of all received persons | |
// local_persons map is the map of currently active persons on the process. We iterate through this map | |
// when iterating through the person loop | |
for (int i = 0; i < total_amt_received; i += PERSON_SEND_DATA_SIZE) { | |
int next_place_id = data[i]; | |
int act_type = data[i + 1]; | |
int p_id = data[i + 2]; | |
// look up person in the "remote_persons" cache using the sent person id | |
auto iter = remote_persons.find(p_id); | |
if (iter == remote_persons.end()) { | |
// the person is not found so construct person from activity etc. caches | |
std::shared_ptr<Activities> weekday = acts_cache[data[i + 4]]; | |
... | |
// make the person from the cached data, and the current disease state | |
shared_ptr<Person> p = make_shared<Person>("remote", p_id, p_places, weekday, weekend); | |
p->setDiseaseState(state); | |
// insert the person into the "remote_persons" cache | |
remote_persons.insert(make_pair(p_id, p)); | |
// add person to local_persons map | |
local_persons.insert(make_pair(p_id, p)); | |
} else { | |
// person is found in the cache so just update the disease state | |
iter->second->setDiseaseState(state); | |
// add person to local_persons map. | |
local_persons.insert((*iter)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define a timer "t1" that can be used to profile a section of code, | |
// in this case the person loop | |
TAU_PROFILE_TIMER(t1,"person-select-place", "void (void)", TAU_USER); | |
// start the timer | |
TAU_PROFILE_START(t1); | |
for (auto p_iter = local_persons.begin(); p_iter != local_persons.end();) { | |
auto& person = p_iter->second; | |
person->selectNextAct(cal, next_act); | |
if (rank_ != next_act.place_rank()) { | |
... | |
} else { | |
... | |
} | |
} | |
// stop the timer | |
TAU_PROFILE_STOP(t1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment