Programming with Hyper-Threading Technology: How to Write Multithreaded Software for Intel IA-32 Processors

The previous chapter introduced the typical building blocks of parallel programming. This chapter begins the process of assembling some of these building blocks into useful programs.
Let's start with a data decomposition example. As discussed in Chapter 2, data decomposition is the process of breaking up large, independent data sets for processing by multiple threads, with the goal of improving performance. The listing in Figure 4.1, a Windows program, creates an array of 20 million floating-point numbers and applies a series of time-consuming arithmetic and geometric operations on them whose effective result is to leave the value unchanged. This set of calculations is derived from the Savage benchmark, which was originally written by Bill Savage in Fortran to test the speed and accuracy of floating-point libraries.
// Multithreaded run of the Savage benchmark// on 20 million doubles. Using Intel processor// high-resolution timers, we see the duration// in millions of clock ticks.#include#include <a name="160"></a><a name="IDX-72"></a>#include #include #include unsigned __stdcall run_savage( LPVOID pArguments );#define BIG_ARRAY 20000000 // 20 millionstatic double fpArray [BIG_ARRAY];int threads; // the total number of threads to create// for each thread, we maintain a struct with this data:struct thInfo { int thNumber; // thread number (in the order we create it) int startItem; // item in fpArray thread should start with double total; // sum of values in fpArray the thread ...