隐含的DO循环效率低下吗? [英] Are implied DO loops inefficient?

查看:68
本文介绍了隐含的DO循环效率低下吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于隐式do循环的数组初始化,给定的大小为N.

I have an array initialization based on an implied do loop, given an odd size N.

J=(N+1)/2
XLOC(1:N) = (/ (I-J, I=1,N) /)

在F90 +的上下文中,建议使用(/../)语法,或者使用FORALL语句更有效.

In the context of F90+ is it recommended to use the (/ .. /) syntax, or is more efficient to use a FORALL statement.

示例:先N=19然后XLOC=(-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9)

您还将如何初始化此数组?

How else would you initialize this array?

编辑1

您将如何使用更具可读性的代码初始化此数组?

How would you initialize this array with more readable code?

推荐答案

对于这样一个简单的结构,两者都可能导致相同的代码,因为编译器擅长优化. FORALL语句不是一个循环语句,而是一个初始化语句,它具有许多可能会抑制优化的限制.如果一个简单的循环可行,我会用它.

For such a simple construct both are likely to lead to the same code because compilers are good at optimizing. The FORALL statement is not so much a looping statement but an initialization statement that has many restrictions that can inhibit optimizations. If a simple loop will work, I'd use it.

另请参阅以下先前的答案:

Also see this previous answer: Do Fortran 95 constructs such as WHERE, FORALL and SPREAD generally result in faster parallel code?

这篇关于隐含的DO循环效率低下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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