10.07.2015 Views

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

290 APPENDIX F. ANSWERS TO QUICK QUIZZESwe should always prefer update-side signals overread-side atomic operations, right?Answer:That depends on the workload. Note that you needa million readers (with roughly a 40-nanosecondperformance gain) to make up for even one writer(with almost a 40-millisecond performance loss).Although there are no shortage of workloads withfar greater read intensity, you will need to consideryour particular workload.In addition, although memory barriers have historicallybeen expensive compared to ordinary instructions,you should check this on the specifichardware you will be running. The properties ofcomputer hardware do change over time, and algorithmsmust change accordingly.Quick Quiz 4.51:<strong>Can</strong> advanced techniques be applied to addressthe lock contention for readers seen in Table 4.2?Answer:There are a number of ways one might go aboutthis, and these are left as exercises for the reader.shared-memory parallelism:1. Only the most performance-critical portions ofthe application must be partitioned, and suchportions are usually a small fraction of the application.2. Although cache misses are quite slow comparedto individual register-to-register instructions,they are typically considerably faster thaninter-process-communication primitives, whichin turn are considerably faster than things likeTCP/IP networking.3. Shared-memory multiprocessors are readilyavailableandquiteinexpensive, so, instarkcontrastto the 1990s, there is little cost penalty foruse of shared-memory parallelism.As always, use the right tool for the job!F.5 Chapter 5: Partitioningand Synchronization DesignQuick Quiz 4.52:The ++ operator works just fine for 1,000-digitnumbers!!! Haven’t you heard of operator overloading???Answer:In the C++ language, you might well be able to use++ on a 1,000-digit number, assuming that you hadaccess to a class implementing such numbers. Butas of 2009, the C language does not permit operatoroverloading.Quick Quiz 4.53:But if we are going to have to partition everything,why bother with shared-memory multithreading?Why not just partition the problem completely andrun as multiple processes, each in its own addressspace?Answer:Indeed, multiple processes with separate addressspacescanbeanexcellentwaytoexploitparallelism,as the proponents of the fork-join methodology andthe Erlang language would be very quick to tellyou. However, there are also some advantages toQuick Quiz 5.1:<strong>Is</strong> there a better solution to the Dining PhilosophersProblem?Answer:One such improved solution is shown in FigureF.3, where the philosophers are simply providedwith an additional five forks. All five philosophersmay now eat simultaneously, and there is never anyneed for philosophers to wait on one another. In addition,the improved disease control provided by thisapproach should not be underestimated.This solution can seem like cheating to some, butsuch “cheating” is key to finding good solutions tomany concurrency problems.Quick Quiz 5.2:<strong>And</strong> in just what sense can this “horizontal parallelism”be said to be “horizontal”?Answer:Inman was working with protocol stacks, which arenormally depicted vertically, with the application ontop and the hardware interconnect on the bottom.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!