Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29391 ディスカッション

Understanding do loops in Fortran

mechprog
ビギナー
915件の閲覧回数
Hi all,
I want to fully understand the do loop process behind the following code:
[fxfortran]      do kdim = 1, ndim   
         do jdim = 1, ndim
               ULOCAL(kdim) = ULOCAL(kdim)-ALOCAL(jdim,kdim)*UTEMP(jdim)
         enddo
      enddo[/fxfortran]
Does this start from the first do loop (kdim) at 1, then start the second do loop (jdim) at 1, then conduct the calculation ULOCAL(kdim) at 1. Take the value at ULOCAL(1) and minus ALOCAL(1,1)*UTEMP(1). Where 1 is the array reference?
I have been going through books in fortran but, I thought it might help to talk the problem through too to improve my understanding.
Thanks
0 件の賞賛
1 返信
TimP
名誉コントリビューター III
915件の閲覧回数
Conceptually, your understanding is correct. The compiler can choose another order of evaluation only if analysis indicates the result will be the same, except for changes in roundoff error. Ideally, the compiler could optimize this the same as a MATMUL, possibly involving unroll-and-jam (grouping outer loop iterations) as well as scalar replacement (inner loop treated as dot_product).
返信