Fortran 95的构造如WHERE,FORALL和SPREAD通常会导致更快的并行代码吗? [英] Do Fortran 95 constructs such as WHERE, FORALL and SPREAD generally result in faster parallel code?

查看:145
本文介绍了Fortran 95的构造如WHERE,FORALL和SPREAD通常会导致更快的并行代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读Metcalf,Reid和Cohen的Fortran 95书以及Fortran 90中的Numerical Recipes。他们建议使用WHERE,FORALL和SPREAD以避免不必要的序列化。



然而,我偶然发现了声称FORALL在理论上是好的,但在实践中没有意义 - 你也可以编写循环,因为它们并行,并且你可以使用OpenMP明确地并行化它们(或某些编译器的自动功能,如英特尔)。

任何人都可以从经验中验证他们是否一般认为这些结构可以提供任何优于显式循环的优点,并行表现的条款?



是否还有其他语言的其他并行功能,它们本质上是好的,但不值得在pra ctice?



我明白这些问题的答案在某种程度上取决于实现,所以我对gfortran,Intel CPU和SMP并行性很感兴趣。 b $ b

解决方案

正如我在回答其他问题时所说的那样,人们普遍认为,FORALL没有像引入时所期望的那样有用语言。正如其他答案中已经解释的那样,它具有限制性要求和有限的作用,并且编译器已经在优化常规循环方面变得相当出色。编译器不断变得更好,功能因编译器而异。另一个线索是Fortran 2008再次尝试......除了在语言(共同数组,已经提到)上增加显式并行化之外,还有并发,一种新的循环形式,它需要限制,以便更好地允许编译器执行自动并行化优化,但应该足够普遍有用 - 请参阅 ftp:// ftp .nag.co.uk / sc22wg5 / N1701-N1750 / N1729.pdf

在获得速度方面,我主要选择了很好的算法和程序来提高可读性和可读性。可维护性。只有当程序速度太慢,我才能找到瓶颈并重新编码或实现多线程(OpenMP)。这将是一个罕见的情况,FORALL或WHERE与显式的do循环会产生有意义的速度差别 - 我会更多地关注他们如何清楚地表明程序的意图。

I have read through the Fortran 95 book by Metcalf, Reid and Cohen, and Numerical Recipes in Fortran 90. They recommend using WHERE, FORALL and SPREAD amongst other things to avoid unnecessary serialisation of your program.

However, I stumbled upon this answer which claims that FORALL is good in theory, but pointless in practice - you might as well write loops as they parallelise just as well and you can explicitly parallelise them using OpenMP (or automatic features of some compilers such as Intel).

Can anyone verify from experience whether they have generally found these constructs to offer any advantages over explicit loops and if statements in terms of parallel performance?

And are there any other parallel features of the language which are good in principal but not worth it in practice?

I appreciate that the answers to these questions are somewhat implementation dependant, so I'm most interested in gfortran, Intel CPUs and SMP parallelism.

解决方案

As I said in my answer to the other question, there is a general belief that FORALL has not been as useful as was hoped when it was introduced to the language. As already explained in other answers, it has restrictive requirements and a limited role, and compilers have become quite good at optimizing regular loops. Compilers keep getting better, and capabilities vary from compiler to compiler. Another clue is that the Fortran 2008 is trying again... besides adding explicit parallelization to the language (co-arrays, already mentioned), there is also "do concurrent", a new loop form that requires restrictions that should better allow the compiler to perform automatic parallization optimizations, yet should be sufficiently general to be useful -- see ftp://ftp.nag.co.uk/sc22wg5/N1701-N1750/N1729.pdf.

In terms of obtaining speed, mostly I select good algorithms and program for readability & maintainability. Only if the program is too slow do I locate the bottle necks and recode or implement multi-threading (OpenMP). It will be a rare case where FORALL or WHERE versus an explicit do loop will have a meaningful speed difference -- I'd look more to how clearly they state the intent of the program.

这篇关于Fortran 95的构造如WHERE,FORALL和SPREAD通常会导致更快的并行代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆