Using unrestrained MPI code logic

From here on, you can unleash the full power of your machine by simply commenting out the restraining outer for loop statement, as shown following in the code fragment. Most MPI codes you will write will not necessarily have the for loop coding format, but most of the exercises in this book will use this type of coding structure.

The code fragment will allow unrestrained processing:

// for(total_iter = 1; total_iter < n; total_iter++) ç comment this line 
{ 
  sum = 0.0; 
//     width = 1.0 / (double)total_iter; // width of a segment ç comment this 
                                                    line 
  width = 1.0 / (double)n; // width of a segment ç use this line 
//     for(i = rank + 1; i <= total_iter; i += numprocs) ç comment this line 
  for(i = rank + 1; i <= n; i += numprocs) ç use this line instead 
  { 
      x = width * ((double)i - 0.5); // x: distance to center of i(th) segment 
      sum += 4.0/(1.0 + x*x); // sum of individual segment height for a given 
                              // rank 
    } 

Please revisit Chapter 2,One Node Supercomputing, for a refresher explanation on the nested for loop used to throttle the processing power of the super cluster.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.6.153