当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

华东师范大学:《高等数值分析(高性能计算/并行计算)》课程教学资源(讲义)04 OpenMP并行编程(一)并行编程介绍、并行域与工作共享

资源类别:文库,文档格式:PDF,文档页数:50,文件大小:0.99MB,团购合买
OpenMP介绍 并行编程模式 并行域操作 工作共享结构
点击下载完整版文档(PDF)

華束师充天学|数学科学学院 School of Mathematical Sciences.East China Normal University OpenMP并行编程 (一) 并行编程介绍 并行域与工作共享 http://math.ecnu.edu.cn/~jypan

http://math.ecnu.edu.cn/~jypan 1 OpenMP 并行编程 (一) —— 并行编程介绍 —— 并行域与工作共享

华东师范大学数学科学学院 目录页 School of Mathematical Sciences,ECNU Contents 1 OpenMP介绍 2 并行编程模式 3 并行域操作 4 工作共享结构 OpenMP Specifications,https://www.openmp.org/specifications Using OpenMP-The Next Step,van der Pas et al,2017 Using OpenMP,Chapman,Jost,and Van Der Pas,2007 http://math.ecnu.edu.cn/-jypan

http://math.ecnu.edu.cn/~jypan 华东师范大学 数学科学学院 School of Mathematical Sciences, ECNU 1 2 OpenMP 介绍 并行编程模式 3 并行域操作 4 工作共享结构  OpenMP Specifications, https://www.openmp.org/specifications  Using OpenMP – The Next Step, van der Pas et al, 2017  Using OpenMP, Chapman, Jost, and Van Der Pas, 2007 目录页 Contents

华东师范大学数学科学学院 目录页 School of Mathematical Sciences,ECNU Contents OpenMP介绍 1 OpenMP介绍 2 并行编程模式 3 并行域操作 4 工作共享结构 http://math.ecnu.edu.cn/-jypan

http://math.ecnu.edu.cn/~jypan 华东师范大学 数学科学学院 School of Mathematical Sciences, ECNU 1 2 OpenMP介绍 并行编程模式 3 并行域操作 1 OpenMP 介绍 4 工作共享结构 目录页 Contents

OpenMP简介 口通过在源代码(串行)中添加OpenMP指令和调用 QpenMP OpenMP库函数来实现在共享内存系统上的并行。 https://www.openmp.org 口为共享内存并行程序员提供了一种简单灵活的开发并 行应用的接口模型,使程序既可以在台式机上执行, 也可以在超级计算机上执行,具有良好的可移植性。 Jointly defined by a group of major computer hardware and software vendors and major parallel computing user facilities,the OpenMP API is a portable,scalable model that gives shared-memory parallel programmers a simple and flexible interface for developing parallel applications on platforms ranging from embedded systems and accelerator devices to multicore systems and shared-memory systems. https://www.openmp.org API:Application Programming Interface http://math.ecnu.edu.cn/~jypan 4

http://math.ecnu.edu.cn/~jypan 4 OpenMP 简介 Jointly defined by a group of major computer hardware and software vendors and major parallel computing user facilities, the OpenMP API is a portable, scalable model that gives shared-memory parallel programmers a simple and flexible interface for developing parallel applications on platforms ranging from embedded systems and accelerator devices to multicore systems and shared-memory systems. https://www.openmp.org API:Application Programming Interface  通过在源代码(串行)中添加 OpenMP 指令和调用 OpenMP 库函数来实现在共享内存系统上的并行。  为共享内存并行程序员提供了一种简单灵活的开发并 行应用的接口模型,使程序既可以在台式机上执行, 也可以在超级计算机上执行,具有良好的可移植性。 https://www.openmp.org

使用说明 FORTRAN/C/C++自带程序库,无需另外安装 ▣ 编译时不打开OpenMP编译选项,则编译器将忽略OpenMP指令, 从而生成串行可执行程序(串行等价性) ▣打开OpenMP编译选项,编译器将对OpenMP指令进行处理,编译 生成OpenMP并行可执行程序 口并行线程数可以在程序启动时利用环境变量等方法进行动态设置 口编程方式:增量并行 口支持与MPI混合编程 http://math.ecnu.edu.cn/-jypan 5

http://math.ecnu.edu.cn/~jypan 5 使用说明  FORTRAN/C/C++ 自带程序库,无需另外安装  编译时不打开 OpenMP 编译选项,则编译器将忽略 OpenMP 指令, 从而生成串行可执行程序(串行等价性)  打开 OpenMP 编译选项,编译器将对 OpenMP 指令进行处理,编译 生成 OpenMP 并行可执行程序  并行线程数可以在程序启动时利用环境变量等方法进行动态设置  编程方式:增量并行  支持与 MPI 混合编程

发展历史 口起源于ANSI X3H5(1994)草案,1997年, 部分设备商和编译器开发 商组成ARB(架构审查委员会),着手制定OpenMP标准化规范 口目标:编程简单,增量化并行,移植性好,扩展性好,支持主流编译器 口支持Uniⅸ,Linux,Windows等操作系统 口ARB成员:AMD,ARM,Intel,IBM,Cray,NEC,HP,NVIDIA, OpenMP FORTRAN version 1.0(1997),C/C++version 1.0(1998) OpenMP Application Programming FORTRAN version 2.0(2000),C/C++version 2.0(2002) Interface OpenMP 3.0 -(May 2008) OpenMP3.1-(uly2011)/本讲义以此版本为主 OpenMP 4.0 (July 2013) OpenMP 4.5 (Nov 2015) OpenMP 5.0 -(Nov 2018) OpenMP 5.2 -(Nov 2021) http://math.ecnu.edu.cn/-jypan 6

http://math.ecnu.edu.cn/~jypan 6 发展历史  起源于 ANSI X3H5(1994)草案,1997年,部分设备商和编译器开发 商组成 ARB(架构审查委员会),着手制定 OpenMP 标准化规范  目标:编程简单,增量化并行,移植性好,扩展性好,支持主流编译器  支持 Unix,Linux,Windows 等操作系统  ARB 成员:AMD,ARM,Intel,IBM,Cray,NEC,HP,NVIDIA,... ► FORTRAN version 1.0 (1997),C/C++ version 1.0 (1998) ► FORTRAN version 2.0 (2000),C/C++ version 2.0 (2002) ► OpenMP 3.0 – (May 2008) ► OpenMP 3.1 – (July 2011) // 本讲义以此版本为主 ► OpenMP 4.0 – (July 2013) ► OpenMP 4.5 – (Nov 2015) ► OpenMP 5.0 – (Nov 2018) ► OpenMP 5.2 – (Nov 2021)

华东师范大学数学科学学院 目录页 School of Mathematical Sciences,ECNU Contents 并行编程模式 1 Open MP介绍 OpenMP并行方式 2 OpenMP编译指导 并行编程模式 ■ 子句 3 并行域操作 变量属性 工作共享结构 http://math.ecnu.edu.cn/~jypan

http://math.ecnu.edu.cn/~jypan 华东师范大学 数学科学学院 School of Mathematical Sciences, ECNU 2 并行编程模式  OpenMP 并行方式  OpenMP 编译指导  子句  变量属性 目录页 Contents 1 2 OpenMP介绍 并行编程模式 3 并行域操作 4 工作共享结构

OpenMP并行方式 OpenMP是基于线程的并行编程模型。 OpenMP采用Fork-Join并行执行方式 ① OpenMP程序开始于一个单独的主线程(Master Thread),,然 后主线程一直串行执行(串行域) ② 直到遇见第一个并行域(Parallel Region),然后开始并行执行并 行域 ③ 并行域代码执行完后再回到主线程,执行串行域,直到遇到下一个 并行域 ④ 以此类推,直至程序运行结束。 http://math.ecnu.edu.cn/-jypan 8

http://math.ecnu.edu.cn/~jypan 8 OpenMP 并行方式 ① OpenMP 程序开始于一个单独的主线程(Master Thread),然 后主线程一直串行执行(串行域) ② 直到遇见第一个并行域(Parallel Region),然后开始并行执行并 行域 ③ 并行域代码执行完后再回到主线程,执行串行域,直到遇到下一个 并行域 ④ 以此类推,直至程序运行结束。 OpenMP 采用 Fork-Join 并行执行方式 OpenMP 是基于线程的并行编程模型

Fork-Join 并行域 并行域 串行域 串行域 F 串行域 ● Fok:主线程创建一个并行线程队列,然后并行域中的代码在不同的 线程上并行执行 ● Joi:当并行域执行完之后,它们或被同步,或被中断,最后只有主 线程继续执行 十并行域可以嵌套 http://math.ecnu.edu.cn/-jypan 9

http://math.ecnu.edu.cn/~jypan 9 Fork-Join  Fork:主线程创建一个并行线程队列,然后并行域中的代码在不同的 线程上并行执行  Join:当并行域执行完之后,它们或被同步,或被中断,最后只有主 线程继续执行 F O R K J O I N F O R K J O I N 并行域 并行域 串行域 串行域 串行域 † 并行域可以嵌套

C举例 #include #include 头文件:omp.h int main() OpenMP指令标识符#pragma omp { int nthreads,tid; #pragma omp parallel private(nthreads,tid) tid=omp_get_thread_num();/获取线程号 printf("Hello world from OpenMP thread %d\n",tid); if (tid==0) { nthreads=:omp_get_num_threads();/获取线程个数 printf("Number of threads %d\n",nthreads); } ·编译 return 0; gcc -fopenmp OMP_hello.c http://math.ecnu.edu.cn/-jypan 10

http://math.ecnu.edu.cn/~jypan #include #include int main() { int nthreads, tid; #pragma omp parallel private(nthreads,tid) { tid=omp_get_thread_num(); // 获取线程号 printf("Hello world from OpenMP thread %d\n", tid); if (tid==0) { nthreads=omp_get_num_threads(); // 获取线程个数 printf("Number of threads %d\n", nthreads); } } return 0; } 10 C 举例  头文件:omp.h  OpenMP 指令标识符 #pragma omp  编译 gcc –fopenmp OMP_hello.c

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共50页,可试读17页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有