example.cpp
来自「omptl使用openmp多核库优化过的STL库」· C++ 代码 · 共 38 行
CPP
38 行
#include <vector>#include <omptl/omptl_numeric>#include <omptl/omptl_algorithm>#include <cstdlib>#include <cmath>#include <iostream>#include <omp.h>const unsigned int N = 100 * (1 << 20);int main (int argc, char * const argv[]){ // Number of threads is derived from environment // variable "OMP_NUM_THREADS" std::cout << "Threads: " << omp_get_max_threads() << std::endl; std::vector<unsigned int> v1(N); omptl::generate(v1.begin(), v1.end(), std::rand); omptl::sort(v1.begin(), v1.end()); omptl::random_shuffle(v1.begin(), v1.end()); std::vector<unsigned int> v2(N); omptl::copy(v1.begin(), v1.end(), v2.begin()); omptl::for_each(v2.begin(), v2.end(), std::sqrt<unsigned int>); std::cout << "Nr 3's: " << omptl::count(v2.begin(), v2.end(), 3) << std::endl; std::cout << "Sum: " << omptl::accumulate(v2.begin(), v2.end(), 0) << std::endl; std::cout << *v1.begin() << std::endl; return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?