Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the parallel program in Figure 12.8 for computing the dot product, the sum of the partial products is computed by one processor after all

image text in transcribed

In the parallel program in Figure 12.8 for computing the dot product, the sum of the partial products is computed by one processor after all threads have reached the barrier. Modify the program so that each thread adds its partial sum incrementally to a global sum for the dot product. To prevent two or more threads from trying to update the global sum at the same time synchronization is required. One method is to use a shared counter variable whose value is the identifier of the thread that is granted exclusive access to the variable for the global sum. After the thread with exclusive access has updated the global sum, it can simply increment this counter to grant exclusive access to another thread Reference of fig.12.8 #include #include "thread.h" Routines for input/output./ Routines for thread creation/synchronization. #define N 100 #define P Number of elements in each vector./ Number of processors for parallel execution. double aN], bIN: double partial_sumsP Array of results computed by threads. Barrier bar Vectors for computing the dot product. * /* Shared variable to support barrier synchronization. void ParallelFunction (void) int my id, i, start, end; double s; my_id- get my_thread id O: Get unique identifier for this thread. start (N/P) my id; end (N/P)*(my_id +1)-;N is assumed to be evenly divisible by P.I s-0.0; for i starti init barrier (&bar): for (iz1; i

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

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

What is Aufbau's rule explain with example?

Answered: 1 week ago

Question

Write Hund's rule?

Answered: 1 week ago