<< Chapter < Page | Chapter >> Page > |
What has happened here? Things were going so well, and then they slowed down. We are running this program on a 16-processor system, and there are eight other active threads, as indicated below:
E6000:uptime
4:00pm up 19 day(s), 37 min(s), 5 users, load average: 8.00, 8.05, 8.14E6000:
Once we pass eight threads, there are no available processors for our threads. So the threads must be time-shared between the processors, significantly slowing the overall operation. By the end, we are executing 16 threads on eight processors, and our performance is slower than with one thread. So it is important that you don’t create too many threads in these types of applications.
Improving performance by turning on automatic parallelization is an example of the “smarter compiler” we discussed in earlier chapters. The addition of a single compiler flag has triggered a great deal of analysis on the part of the compiler including:
DOALL
loop.Even though it seems complicated, the compiler can do a surprisingly good job on a wide variety of codes. It is not magic, however. For example, in the following code we have a loop-carried flow dependency:
PROGRAM DEP
PARAMETER(NITER=300,N=1000000)REAL*4 A(N)
DO ITIME=1,NITERCALL WHATEVER(A)
DO I=2,NA(I) = A(I-1) + A(I) * C
ENDDOENDDO
END
When we compile the code, the compiler gives us the following message:
E6000: f77 -O3 -autopar -loopinfo -o dep dep.f
dep.f:"dep.f", line 6: not parallelized, call may be unsafe
"dep.f", line 8: not parallelized, unsafe dependence (a)E6000:
The compiler throws its hands up in despair, and lets you know that the loop at Line 8 had an unsafe dependence, and so it won’t automatically parallelize the loop. When the code is executed below, adding a thread does not affect the execution performance:
E6000:setenv PARALLEL 1
E6000:/bin/time depreal 18.1
user 18.1sys 0.0
E6000:setenv PARALLEL 2E6000:/bin/time depreal 18.3
user 18.2sys 0.0
E6000:
A typical application has many loops. Not all the loops are executed in parallel. It’s a good idea to run a profile of your application, and in the routines that use most of the CPU time, check to find out which loops are not being parallelized. Within a loop nest, the compiler generally chooses only one loop to execute in parallel.
In addition to the flags shown above, you may have other compiler flags available to you that apply across the entire program:
There is some value in experimenting with a compiler to see the particular combination that will yield good performance across a variety of applications. Then that set of compiler options can be used as a starting point when you encounter a new application.
Notification Switch
Would you like to follow the 'High performance computing' conversation and receive update notifications?