<< 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

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!

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  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.

Notification Switch

Would you like to follow the 'High performance computing' conversation and receive update notifications?

Ask