This page is optimized for mobile devices, if you would prefer the desktop version just click here

5.6 Exercises

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

Got questions? Get instant answers now!

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

Got questions? Get instant answers now!

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.

Got questions? Get instant answers now!
<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, High performance computing. OpenStax CNX. Aug 25, 2010 Download for free at http://cnx.org/content/col11136/1.5
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.