OpenMP编程指南.ppt
文本预览下载声明
现代密码学理论与实践之五 并行算法实践 OpenMP编程指南 OpenMP概述 OpenMP编程风络 OpenMP编程简介 运行库例程与环境变量 OpenMP计算实例 OpenMP概述 OpenMP应用编程接口API是在共享存储体系结构上的一个编程模型 包含编译制导(Compiler Directive)、运行库例程(Runtime Library)和环境变量(Environment Variables) 支持增量并行化(Incremental Parallelization) OpenMP体系结构 什么是OpenMP 什么是OpenMP 应用编程接口API(Application Programming Interface ) 由三个基本API部分(编译指令、运行部分和环境变量)构成 是C/C++ 和Fortan等的应用编程接口 已经被大多数计算机硬件和软件厂家所标准化 OpenMP不包含的性质 不是建立在分布式存储系统上的 不是在所有的环境下都是一样的 不是能保证让多数共享存储器均能有效的利用 OpenMP的历史 1994年,第一个ANSI X3H5草案提出,被否决 1997年,OpenMP标准规范代替原先被否决的ANSI X3H5,被人们认可 1997年10月公布了与Fortran语言捆绑的第一个标准规范 1998年11月9日公布了支持C和C++的标准规范 目前Fortran77、Fortran90、C、C++语言的实现规范已经完成 OpenMP的目标 标准性 简洁实用 使用方便 可移植性 OpenMP并行编程模型 基于线程的并行编程模型(Programming Model) OpenMP使用Fork-Join并行执行模型 OpenMP程序结构 基于Fortran语言的OpenMP程序的结构 PROGRAM HELLOINTEGER VAR1, VAR2, VAR3 !Serial code … !Beginning of parallel section. Fork a team of threads. !Specify variable scoping !$OMP PARALLEL PRIVATE(VAR1, VAR2) SHARED(VAR3) !Parallel section executed by all threads … !All threads join master thread and disband!$OMP END PARALLEL !Resume serial code …END OpenMP程序结构 基于c/c++语言的OpenMP程序的结构 #include omp.h main (){ int var1, var2, var3; /*Serial code*/ … /*Beginning of parallel section. Fork a team ofthreads*/ /*Specify variable scoping */ #pragma omp parallel private(var1, var2) shared(var3) { /*Parallel section executed by all threads*/ … /*All threads join master thread and disband*/ } /*Resume serial code */ … } 一个简单的OpenMP程序实例 基于C/C++语言的OpenMP程序结构的一个具体实现 #include omp.h int main(int argc, char* argv[]) { int nthreads, tid; int nprocs; char buf[32]; /* Fork a team of threads */ #pragma omp parallel private(nthreads, tid) { /* Obtain and print thread id */ tid = omp_get_thread_num(); printf(Hello World from OMP thread %d\n, tid); /* Only master thread does this */ if (tid==
显示全部