2
我想知道是否有一種方法來加速稱爲(path_from_startend)的無序映射的人口。無序地圖總是有一個唯一的密鑰。使用多線程的無序映射的C++羣體
#pragma omp parallel for
for (int i=start_index;i<end_index;++i){
for (int j=start_index;j<end_index;++j){
string key= to_string(unique_locations[i])+to_string(unique_locations[j]);
//dont compute path to itself
if (i==j){
}
else {
vector <unsigned> path = pathbot.FindPath(unique_locations[i],unique_locations[j],turn_penalty);
path_from_startend.insert(make_pair(key,path));
}
}
}
由於線程之間共享'path_from_startend',因此插入操作必須進入臨界區。那麼問題是,'pathbot.FindPath'需要很長時間嗎?否則,這是毫無意義的,因爲你有效地填充地圖(由於關鍵部分)。 –
FindPath是一個確實需要一點時間(毫秒)的A *算法。 –
然後我的答案應該可以幫到你。我更新了它,以匹配您的代碼。 –