(Solved) : Cis 345 545 Fall 2019 Project 1 Due Sep 24 Project Asked Write Two Independent Programs Th Q40167476 . . .

 

I need ASAP.

CIS 345/545 Fall 2019 Project 1 (Due Sep. 24) 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 to n, where m and specified in the command line. n are powers of 2 and are 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 0) 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. Note that your program needs to use pthread_barrier wait () to let the main thread know that alll of the 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 The program thr reduce.c is similar to thr atomic.c except that you need to use the parallel reduction approach to combine the partial sums. That is, your program uses a shared global array and each computational thread stores its partial pthread-join() to wait for their corresponding partner threads completion, and then each of these threads can add two numbers in the array together. This reduction procedure will be performed log(m) times and each time the number of the active threads will be reduced half. For example, assume that there are 8 computational threads. In the first reduction step, in order to add two elements in the array, thread 4 should wait for thread sum in an array element indexed on its thread ID. Then, half of these threads call 0 done, thread 5 has to wait for thread 1 done, threads 6 needs to wait for thread 2 done, and thread 7 should wait for thread 3 done. In the second reduction step, thread 6 waits for thread 4 finished, and thread 7 waits for thread 5 finished. In the third step, thread 7 waits for thread 6 done and then prints the final result. Hint: to find its partner thread ID during the ith reduction step, a thread can use its ID XORed with 2-, wherer= Note that the main thread just calls pthread exit () after creating threads. Calling pthread exit () in the main thread will allow other threads to continue execution. m threads. It does not need to wait for these Turning it in Each group (at most two CIS345 students, CIS545 students should work alone) has to submit your program electronically by using the following command on grail: turnin -c cis345s -p proj1 makefile thr atomic.c thr reduce.c Each group also needs to hand in a hard-copy document which includes the description of your code, experiences in debugging and testing, etc. The cover page should contain your picture(s) (taken in FH128 using iMac), name(s) and the login id you used to turnin the project. Start on time and good luck. If you have any questions, send e-mail to sang@cis.csuohio.edu. Show transcribed image text CIS 345/545 Fall 2019 Project 1 (Due Sep. 24) 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 to n, where m and specified in the command line. n are powers of 2 and are 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 0) 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. Note that your program needs to use pthread_barrier wait () to let the main thread know that alll of the 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 The program thr reduce.c is similar to thr atomic.c except that you need to use the parallel reduction approach to combine the partial sums. That is, your program uses a shared global array and each computational thread stores its partial pthread-join() to wait for their corresponding partner threads completion, and then each of these threads can add two numbers in the array together. This reduction procedure will be performed log(m) times and each time the number of the active threads will be reduced half. For example, assume that there are 8 computational threads. In the first reduction step, in order to add two elements in the array, thread 4 should wait for thread sum in an array element indexed on its thread ID. Then, half of these threads call 0 done, thread 5 has to wait for thread 1 done, threads 6 needs to wait for thread 2 done, and thread 7 should wait for thread 3 done. In the second reduction step, thread 6 waits for thread 4 finished, and thread 7 waits for thread 5 finished. In the third step, thread 7 waits for thread 6 done and then prints the final result. Hint: to find its partner thread ID during the ith reduction step, a thread can use its ID XORed with 2-, wherer= Note that the main thread just calls pthread exit () after creating threads. Calling pthread exit () in the main thread will allow other threads to continue execution. m threads. It does not need to wait for these Turning it in Each group (at most two CIS345 students, CIS545 students should work alone) has to submit your program electronically by using the following command on grail: turnin -c cis345s -p proj1 makefile thr atomic.c thr reduce.c Each group also needs to hand in a hard-copy document which includes the description of your code, experiences in debugging and testing, etc. The cover page should contain your picture(s) (taken in FH128 using iMac), name(s) and the login id you used to turnin the project. Start on time and good luck. If you have any questions, send e-mail to sang@cis.csuohio.edu.

Expert Answer


Answer to CIS 345/545 Fall 2019 Project 1 (Due Sep. 24) In this project, you are asked to write two independent programs, thr atom…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us