top_left_banner  SimCon logo


An Example of Loop Unwinding

In the fragment from a 9-body solar-system model the inner loop is marked by the fpt command !% unwind.

DO body1=1,9 DO body2=body1+1,9 !% unwind DO axis=1,3 ! Difference in position ds(axis,body1,body2) = s(axis,body1)-s(axis,body2) ! Square of difference in position s2(axis) = ds(axis,body1,body2) * ds(axis,body1,body2) ENDDO ! Square of radial distance r2(body1,body2) = s2(1) + s2(2) + s2(3) ! Radial distance r(body1,body2) = sqrt(r2(body1,body2)) ! Total gravitation field from body2 gf(body1,body2) = g * mass(body2) / r2(body1,body2) ! Total gravitational field from body1 gf(body2,body1) = g * mass(body1) / r2(body1,body2) ! Cosines and vector fields to and from each body DO axis=1,3 proj(axis,body1,body2) = ds(axis,body1,body2) / r(body1,body2) proj(axis,body2,body1) = -proj(axis,body1,body2) vf(axis,body1,body2) = proj(axis,body1,body2) * gf(body1,body2) vf(axis,body2,body1) = proj(axis,body2,body1) * gf(body2,body1) ENDDO ENDDO ENDDO

fpt unwinds this loop:

DO body1 = 1,9 DO body2 = body1+1,9 ! ! **************************************************************************** ! !% unwind ! FPT DO axis = 1,3 ! ! FPT axis = 1 ! ! Difference in position ds(1,body1,body2) = s(1,body1)-s(1,body2) ! Square of difference in position s2(1) = ds(1,body1,body2)*ds(1,body1,body2) ! FPT ENDDO ! ! **************************************************************************** ! !% unwind ! FPT DO axis = 1,3 ! ! FPT axis = 2 ! ! Difference in position ds(2,body1,body2) = s(2,body1)-s(2,body2) ! Square of difference in position s2(2) = ds(2,body1,body2)*ds(2,body1,body2) ! FPT ENDDO ! ! **************************************************************************** ! !% unwind ! FPT DO axis = 1,3 ! ! FPT axis = 3 ! ! Difference in position ds(3,body1,body2) = s(3,body1)-s(3,body2) ! Square of difference in position s2(3) = ds(3,body1,body2)*ds(3,body1,body2) ! FPT ENDDO ! ! **************************************************************************** ! ! Square of radial distance r2(body1,body2) = s2(1)+s2(2)+s2(3)

The index axis is replaced by its integer literal value wherever it occurs in each copy of the loop.

Note that fpt comments-out the original DO statement but leaves it in the code to indicate what has been done.

Please see UNWIND MARKED LOOPS in the reference manual for a description of the fpt commands.

Copyright ©1995 to 2025 Software Validation Ltd. All rights reserved.