Ai
1 Star 6 Fork 1

jiangli/Tutorials

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_openmp.cpp 767 Bytes
一键复制 编辑 原始数据 按行查看 历史
李江 提交于 2023-08-10 08:50 +08:00 . feat[04]: add test openmp
//
// Author: jiangli
// Email: 1316762810@qq.com
//
#include <omp.h>
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
std::cout << "number of available processors: " << omp_get_num_procs()
<< std::endl;
std::cout << "number of threads: " << omp_get_max_threads() << std::endl;
auto n = 1000000000;
std::cout << "we will form sum of numbers from 1 to " << n << std::endl;
// start timer
auto t0 = omp_get_wtime();
auto s = 0LL;
#pragma omp parallel for reduction(+ : s)
for (auto i = 1; i <= n; i++) {
s += i;
}
// stop timer
auto t1 = omp_get_wtime();
std::cout << "sum: " << s << std::endl;
std::cout << "elapsed wall clock time: " << t1 - t0 << " seconds"
<< std::endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jiangli01/tutorials.git
git@gitee.com:jiangli01/tutorials.git
jiangli01
tutorials
Tutorials
master

搜索帮助