Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Writing a static loop scheduler A static loop scheduler is the simplest way to achieve some parallelism. We will use it to make the numerical

Writing a static loop scheduler A static loop scheduler is the simplest way to achieve some parallelism. We will use it to make the numerical integration problem parallel. Essentially, with T threads, each thread will do exactly 1 T of the loop iterations. So that if the loop has 100 iterations and there are four threads, the rst threads will execute loop iterations from 0 to 24, the second will execute iterations from 25 to 49, ... With the pthread library, one can pass parameters to a thread by passing a pointer to a struct that contains all the information it needs. The simplest way to write this code is to have one instance of the struct per thread, to give each thread the di erent information it needs. Some are the same for all the threads, a, b, a pointer to the results. Some are di erent, such as the range of indices they are supposed to execute. Note that all the threads will need access to a pointer to the oat that stores the sum of all the values. To avoid race conditions, this variables needs to be placed under mutual exclusion and there are two ways to do this: iteration-level mutual exclusion essentially puts the mutual exclusion on each access to the variable thread-level mutual exclusion makes each threads locally compute the sum of values in its own variable, and only aggregates the value into the results once all the iterations have been computed. Question: Write a static loop scheduler and use it to compute numerical integration. Use static sched.cpp as a template. Write the code so that it outputs the integral value on stdout and the time it takes to make the computation on stderr. The program should take the following command line parameters: functionid, same as in numerical integration assignment a, same as in numerical integration assignment 1 b, same as in numerical integration assignment n, same as in numerical integration assignment intensity, same as in numerical integration assignment nbthreads, an integer indicating the number of threads that should perform the numerical integration sync, a string, either iteration or thread that indicate which synchronization method to use. Question: Report time and speedup across a range of precision, intensity, and synchronization mode. Use qsub -d `pwd` -q mamba -l nodes=1:ppn=16 bench static.sh. Question: Why do you think some measurements are so erratic? Question: Why is the speedup of low intensity runs with iteration-level synchronization the way it is? Question: Compare the speedup of iteration-level synchronization to thread-level synchronization. Why is it that way?

#include

#ifdef __cplusplus extern "C" { #endif

float f1(float x, int intensity); float f2(float x, int intensity); float f3(float x, int intensity); float f4(float x, int intensity);

#ifdef __cplusplus } #endif

int main (int argc, char* argv[]) {

if (argc < 8) { std::cerr<<"usage: "< "<

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Students also viewed these Databases questions

Question

2. What type of team would you recommend?

Answered: 1 week ago