<< Chapter < Page | Chapter >> Page > |
How would you simplify the following loop conditional?
DO I=1,N
A(I) = A(I) * BIF (I .EQ. N/2) A(I) = 0.
ENDDO
Time this loop on your computer, both with and without the test. Run it with three sets of data: one with all
A(I)
s less than
SMALL
, one with all
A(I)
s greater than
SMALL
, and one with an even split. When is it better to leave the test in the loop, if ever?
PARAMETER (SMALL = 1.E-20)
DO I=1,NIF (ABS(A(I)) .GE. SMALL) THEN
B(I) = B(I) + A(I) * CENDIF
ENDDO
Write a simple program that calls a simple subroutine in its inner loop. Time the program execution. Then tell the compiler to inline the routine and test the performance again. Finally, modify the code to perform the operations in the body of the loop and time the code. Which option ran faster? You may have to look at the generated machine code to figure out why.
Notification Switch
Would you like to follow the 'High performance computing' conversation and receive update notifications?