fortran - Copying arrays: loops vs. array operations -


i work fortran quite long time have question can't find satisfying answer. if have 2 arrays , want copy 1 other:

real,dimension(0:100,0:100) :: array1,array2 ... i=0,100    j=0,100       array1(i,j) = array2(i,j)    enddo enddo 

but noticed works if that:

real,dimension(0:100,0:100) :: array1,array2 ... array1 = array2 

and there huge difference in computational time! (the second 1 faster!) if without loop can there problem because don't know maybe i'm not coping content memory reference? change if mathematical step like:

array1 = array2*5 

is there problem on different architecture (cluster server) or on different compiler (gfortran, ifort)?

i have perform various computational steps on huge amounts of data computational time issue.

everything @alexander_vogt said, also:

do i=0,100     j=0,100         array1(i,j) = array2(i,j)     enddo enddo 

will slower than

do j=0,100     i=0,100         array1(i,j) = array2(i,j)     enddo enddo 

(unless compiler notices , reorders loops.)

in fortran, first parameter fastest changing. means in second loop, compiler can load several elements of array in 1 big swoop in lower level caches operations on.

if have multidimensional loops, have innermost loop loop on first index, , on. (if possible in way.)


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -