- 1、本文档共62页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
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() OpenMP: Environment Variables OMP_NUM_THREADS bsh: export OMP_NUM_THREADS=2 csh: setenv OMP_NUM_THREADS 4 Content Overview of OpenMP Acknowledgement OpenMP constructs (5 categories) OpenMP exercises References #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! Example Code - Pthread Creation and Termination #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, PrintHello, (void *)t); if (rc) { printf(ERROR; return code from pthread_create() is %d\n, rc); exit(-1); } } pthread_exit(NULL); } PROGRAM REDUCTION INTEGER I, N REAL A(100), B(100), SUM ! Some initializations N = 100 DO I = 1, N A(I) = I *1.0 B(I) = A(I) ENDDO SUM = 0.0 !
您可能关注的文档
- Grid-based access control for Unix environments, filesystems 课件.PPT
- Group Projects Class of 2008 Logistics课件.ppt
- Growth-rate Functions课件.ppt
- GUI Programming in Java课件.ppt
- GUI 实现的自助操作系统课件.ppt
- Höflichkeit und Komplexität课件.ppt
- H.J.Harrington 5个质量定律 10个质量改进步骤课件.ppt
- H1N1新型流感的认识与预防(教学篇)课件.ppt
- Habitats课件.ppt
- HACCP对控制动物饲料和宠物食品安全卫生的研究课件.ppt
文档评论(0)