An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
2.1 循环并行化 • 循环并行化是使用OpenMP来并行化程序的最重要的部分 • 在C/C++语言中,循环并行化语句的编译制导语句格式如下: #pragma omp parallel for [clause[clause…]] for( i = first ; i<last ; i++) { body of the loop; }
另一种格式: #pragma omp parallel [clause[clause…]] { #pragma omp for [clause[clause…]] for( i = first ; i<last ; i++) { body of the loop; } } • 如果并行的线程需要在循环的开始,或结束时作些工作的话,就只能用parallel与for子句分离的版本。 • Parallel 将紧跟的程序块扩展为若干完全等同的并行区域,每个线程拥有完全相同的并行区域; • For 将循环中工作分配到线程组中,线程组中的每一个线程完成循环中的一部分。 • 子句用来控制编译制导语句的具体行为。
循环并行化语句的限制 并行化的语句必须是for循环语句并具有规范格式 • 能够推测出循环的次数 • for (index = start ; index < end ; increment_expr) • 在循环过程中不能使用break语句 • 不能使用goto和return语句从循环中跳出 • 可以使用continue语句