c++11,std::find的并行化模板化
来源:互联网 发布:股市模拟交易软件 编辑:程序博客网 时间:2024/06/05 13:28
#include <atomic>template<typename Iterator,typename MatchType>Iterator parallel_find_inter(Iterator first,Iterator last,MatchType match,std::atomic<bool>& done){try{unsigned long const length = std::distance(first,last);unsigned long const min_per_thread = 25;if(length < (2*min_per_thread)){for(;(first!=last)&&!done.load();++first){if(*first == match){done = true;return first;}}return last;}else{Iterator const mid_point = first + (length/2);std::future<Iterator> async_result = std::async(¶llel_find_inter<Iterator,MatchType>,mid_point,last,match,std::ref(done));Iterator const direct_result = parallel_find_inter(first,mid_point,match,done);return (direct_result == mid_point)?async_result.get():direct_result;}}catch(...){done = true;throw;}}template<typename Iterator,typename MatchType>Iterator parallel_find(Iterator first,Iterator last,MatchType match){std::atomic<bool>done(false);return parallel_find_inter(first,last,match,done);}
1 0
- c++11,std::find的并行化模板化
- C++并发实战5:并行化的std::accumulate
- c++11,for_each的并行化,改写模板
- 【C/C++开发】C++11的模板类型判断——std::is_same和std::decay
- C#---并行化Parallel
- std:find
- Openmp并行域内的子函数并行化
- OpenMP: 并行域内的子函数并行化
- C++11的模板类型判断——std::is_same和std::decay
- C++11的模板类型判断——std::is_same和std::decay
- lr的并行化
- 最简单的std::find例子
- std::vector的find();与erase();
- std::vector<string>的find();与erase();
- c 的并行机制
- C++,vector模板类的问题? std::vector<PointT, Eigen::aligned_allocator<PointT> > points;
- std::accumulate异常安全的两个并行版本
- std::bind std::find 学习
- 文件的操作
- C语言实现字符串函数
- openflow简介
- 【Ajax 3】JavaScript封装Ajax
- iOS 【应用程序app运行原理-UIApplication-AppDelegate.m-UIApplicationMain】
- c++11,std::find的并行化模板化
- 前端工程化和Reactjs的模式
- unity3D 实现NGUI物体朝鼠标点击位置移动
- Java8の字符串操作
- Arduino- 编译引用 IRremote 出现 error: ‘TKD2′ was not declared in this scope
- 使用此函数添加任意数量的load事件处理函数
- 【已解决】Xen下虚拟机执行Shutdown失败,开机自动重启虚拟机,并出现页故障问题
- SlidingMenu-jar包
- 第二十四节 OAD空中升级