第一个OPENMP程序
2016-05-02 10:50
423 查看
环境:
mac OSXgcc 版本: 4.9
gcc -v :
gcc version 4.9.2 20141029 (prerelease) (GCC)如果gcc版本是4.2,直接编译含omp.h的文件时,会报错(No such file or directory)
安装4.9的具体步骤如下:
http://stackoverflow.com/questions/20340117/omp-h-library-isnt-found-in-the-gcc-version-4-2-1-in-mavericks如果报错说,fatal error: stdio.h: No such file or directory
#include “stdio.h”
再执行xcode-select –install 即可解决路径依赖的问题
测试代码如下:
#include <stdio.h> #include "omp.h" int main () { int nthreads, tid; /* Fork team of threads with private var tid */ #pragma omp parallel private(tid) { tid = omp_get_thread_num(); /* get thread id */ printf("Hello World from thread = %d\n", tid); /* Only master thread does this */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } /* All threads join master and terminate */ }
编译:
» gcc -fopenmp hello.c
输出:
Hello World from thread = 2
Hello World from thread = 1
Hello World from thread = 0
Hello World from thread = 3
Number of threads = 4
系统默认开启线程为4
修改方式:
export OMP_NUM_THREADS=20
openmp教程:
http://blog.csdn.net/fulva/article/details/8089592
http://blog.csdn.net/fulva/article/details/8014116
相关文章推荐
- 在Windows平台下使用安装GCC(图)
- linux使用gcc编译c语言共享库步骤
- C/C++编译器GCC下的常用编译命令总结
- GCC 编译c程序的方法及过程解析
- Glusterfs的编译选项 #pragma GCC poison system popen
- 【笔记】CentOS上源码安装GCC 4.8.2
- 【笔记】CentOS
- Java调用动态链接库
- RHEL 4.7 (64bit) 环境安装 GCC 4.6 测试记录 (更新至gcc-4.6.1)
- ScalaMP ---- 模仿 OpenMp 的一个简单并行计算框架
- GCC 5 即将发布
- [转载]Visual Studio, GCC, Clang, Intel 对 C++11 特性的支持一览表
- C++爱好者博客
- gcc工具的运用
- gdb的运用
- GCC内联汇编(1)Get started
- GCC内嵌汇编
- g++编译 参数 .
- RHEL5.3 gcc rpm包安装