Silverfrost Forums

Welcome to our forums

Nested Implied DO LOOP - order of indices

7 Aug 2017 3:34 #19957

Good evening, everyone,

is the order of indices within an implied DO LOOP important, regarding performance?

Example: Order of icoun, jcoun, kcoun

		ALLOCATE(bmatt(ndib1,ndib2,nlays))

!		Assemble array bmatt - contains layerwise results
!		Reshape is used, because implied DO LOOP returns 1D-array  
		bmatt=reshape([((assign_belem(...),jcoun=1,ndib1),kcoun=1,ndib2),icoun=1,nlays)],shape(bmatt))

Thanks!

7 Aug 2017 4:34 #19958

It might well be, depending on how often the assignment is performed and how many dimensions there are in the array.

Fortran uses 'column major' ordering and the compiler may optimise the process of calculating the address of each element. For FTN95 further optimisation may be applied when using /opt on the command line.

I suggest that you run a simple timing test, wrapping the assignment in a do loop with (say) 10000 passes. This will give you a sensible speed comparison between different orderings and different compiler command lines options.

8 Aug 2017 8:00 #19959

Thanks, I'll try that.

Please login to reply.