C++使用多线程的无序列图填充
C++ population of unordered map using multithreading
我想知道是否有一种方法可以加快名为(path_from_startend(的无序地图的人口。无序列图始终具有唯一键。
#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));
}
}
}
您可以尝试以下模式是否为您提供了一些速度。 您基本上是在填充部分地图,然后将其合并到整个地图中。 加速很大程度上取决于元件的构建和插入需要多长时间。 如果您的元素构建和插入成本低,那么您的加速甚至可能是负的,因为对于每个部分地图,它必须遍历整个地图以寻找重复项。
#pragma omp parallel
{
std::unordered_map < std::string, std::vector < unsigned > > partial;
#pragma omp for
for (int i = start_index; i < end_index; ++i)
{
for (int j = start_index; j < end_index; ++j)
{
std::string key = std::to_string(unique_locations[i])
+ std::to_string(unique_locations[j]);
//dont compute path to itself
if (i != j)
{
std::vector<unsigned> path = pathbot.FindPath(unique_locations[i],
unique_locations[j],
turn_penalty);
partial.insert(std::make_pair(key,path));
}
}
}
#pragma omp critical
path_from_startend.insert(partial.begin(),partial.end());
}
相关文章:
- 在c++中用vector填充一个简单的动态数组
- 如何使用用户输入在C++中正确填充2D数组
- 如何找到大小'x'数组是否完全填充,在C++?
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 通过for循环使用用户输入填充列表
- 递归无序映射
- c++找不到具有相同哈希的无序集合元素
- 正在将无序映射设置为无序映射的值
- 智能指针作为无序映射键,并通过引用进行比较
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 如何正确填充在堆上分配的二维数组?
- 将数字转换为填充字符串
- 有没有办法在一行中填充矢量图
- 如何使用set实现无序数据结构?
- 用C++中的数字和条件填充向量
- 如何写向量的无序向量集,即unordered_set<向量<向量<int>>集合?
- 用真值填充矢量
- 使用无序遍历从相同大小的排序数组填充现有 BST
- 填充一个无序的vector元素指针队列
- 用C++中的无序数据填充向量