Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, you are asked to write two independent programs, thr_atomic.c and thr_reduce.c, each of which uses m computational threads to concurrently calculate the

In this project, you are asked to write two independent programs, thr_atomic.c and thr_reduce.c, each of which uses m computational threads to concurrently calculate the sum of square roots from 1 ton, where m and n are powers of 2 and are specified in the command line. For the program thr_atomic.c, it gets the values m and n from the command line arguments and converts them to two integers, respectively. Next, it creates m threads using pthread.create() and each thread computes the sum of n/m square roots. Namely, the first thread (i.e. thread O) computes the sum of square roots from 1 to n/m, the second thread (i.e. thread 1) computes the sum of the square roots from n/m + 1 to 2n/m, etc. When a thread finishes its computation, it should print its partial sum and atomically add it to a shared global variable."m" computational threads have done the atomic additions and hence it can print the result. Below is an example of running your thread program: bach> /thr_atomic 2 65536 thr 0: 3954518.036356 thr 1: 7230420.422587 sum of square roots: 11184938.458943

should not use semaphores

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

design a simple disciplinary and grievance procedure.

Answered: 1 week ago