- 1、本文档共46页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
06 OpenMP多线程程序设计
* * Master directive The master construct denotes a structured block that is only executed by the master thread. The other threads just skip it (no implied barriers or flushes). #pragma omp parallel private (tmp) { do_many_things(); #pragma omp master { exchange_boundaries(); } #pragma barrier do_many_other_things(); } * Single directive The single construct denotes a block of code that is executed by only one thread. A barrier and a flush are implied at the end of the single block. #pragma omp parallel private (tmp) { do_many_things(); #pragma omp single { exchange_boundaries(); } do_many_other_things(); } * OpenMP: Library routines Lock routines omp_init_lock(), omp_set_lock(), omp_unset_lock(), omp_test_lock() Runtime environment routines: Modify/Check the number of threads omp_set_num_threads(), omp_get_num_threads(), omp_get_thread_num(), omp_get_max_threads() Turn on/off nesting and dynamic mode omp_set_nested(), omp_set_dynamic(), omp_get_nested(), omp_get_dynamic() Are we in a parallel region? omp_in_parallel() How many processors in the system? omp_num_procs() * #include omp.h main () { int nthreads, tid; /* Fork a team of threads giving them their own copies of variables */ #pragma omp parallel private(nthreads, tid) { /* Obtain thread number */ tid = omp_get_thread_num(); 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 thread and disband */ } 1. Hello World! * #include pthread.h #include stdio.h #define NUM_THREADS 5 void *PrintHello(void *threadid) { printf(\n%d: Hello World!\n, threadid); pthread_exit(NULL); } int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for(t=0; tNUM_THREADS; t++) { printf(Creating thread %d\n, t); rc = pthread_create(threads[t], NULL, PrintHe
您可能关注的文档
- 冀教版四年级下Lesson8 First Second Third.ppt
- Unit_4__My_First_assignment上课.ppt
- 英语演讲-the happy secret to better work.ppt
- 2012秋U3T3 the third period.ppt
- 人教版精通版五年级英语上册《unit_4_where_do_you_work》ppt课件(第1个).ppt
- 新概念3第26-36课挖空.ppt
- BI概念以及数据仓库讲解.ppt
- 美世《China_Third_Party_Logistics_Survey---Preview_of_Findings》25页.ppt
- Unit 1 When is your birthday 初一下学期英语课件.ppt
- BEC商务英语Module 2.ppt
- 人教新目标版英语九年级 中考模拟学情评估(三)(含答案).pdf
- 上海市风华中学2024-2025学年高三上学期9月阶段测试英语试题(无答案).pdf
- 统编版2024-2025学年语文六年级上册期末检测卷(有答案).pdf
- 人教新目标版英语九年级第二学期全册学情评估(含答案).pdf
- 内蒙古自治区巴彦淖尔市杭锦后旗第六中学2024-2025学年八年级上学期阶段性测试历史试题(解析版).pdf
- 湖南省娄底市涟源市部分学校2024-2025学年高一上学期9月月考语文试题 Word版无答案.pdf
- 湖南省衡阳市常宁市2023-2024学年七年级上学期期末考试英语试题.pdf
- 湖南省娄底市涟源市部分学校2024-2025学年高一上学期9月月考语文试题 Word版含解析.pdf
- 江苏省泰州市姜堰区城西实验学校2024-2025学年部编版九年级上学期月考历史试卷(原卷版).pdf
- 内蒙古伊金霍洛旗2022-2023学年七年级上学期期末考试英语试题.pdf
最近下载
- 第十一单元第二十一节德彪西教学课件-2021-2022学年高中音乐人音版必修音乐鉴赏.pptx
- 人教中图版(2019)信息技术必修2 1.2 认识信息社会 教案(表格式).docx
- 高性能低表面处理环氧涂料的制备和性能研究.docx VIP
- 永临结合及转换方案-投标200页简易版.docx
- 【语文】人教部编版语文八年级上册:古诗文理解性默写(完整版).pdf VIP
- 基本乐理音程介绍PPT课件.pptx
- GB_T27065-2015_合格评定产品、过程和服务认证机构要求.doc
- 环氧改性有机硅树脂低表面能涂料的研制.doc VIP
- 0~3岁婴幼儿心理发展与教育(高职)全套教学课件.pptx
- 语文一年级上册核心素养教案全册.pdf VIP
文档评论(0)