1. For each problem, submit1)your program, and2)screenshots (jpg or pngformat) of the execution (command line and output) of the program. The screenshots show that your program produces...

1 answer below »



1. For each problem, submit


1)


your program, and


2)


screenshots (


jpg or png


format) of the execution (command line and output) of the program. The screenshots show that your program produces correct results. Include only the executions. Don't include the output of gcc compilation in the screenshots. You must submit C programs (not C++, java, etc), which can be compiled using gcc on the virtual machine used in the course. Alsotest your program on the virtual machine. The grader will not give credits if your program cannot be compiled or run on the virtual machine.




2. Name your programs using the pattern HW10_Problem#.c , and name your screenshots using the pattern HW10_Problem#_Index.jpg. Problem# is the problem number (e.g., 1, 2, 3, 4, etc). Index is the index number showing the order of the screenshots (e.g., 1 or 2).













3. Both problems must use multiple threads or MPI processes to finish computation. Submissions failing to do so will not be graded.











4. Submit individual files.DO NOT SUBMIT A ZIP FILE.




PLEASE SUBMIT THE SCREENSHOTS FOR EACH PROBLEM




CS288 Intensive Programming in Linux, Prof. Xiaoning Ding DO NOT DISTRIBUTE WITHOUT WRITTEN PERMISSION FROM PROF. XIAONING DING Problem 1: Sort Integers Saved in a File Implement an MPI program that sorts a set of 4-byte integer values in ascending order. The values are saved in a file. When the program finishes, the sorted values should be saved in the same file. The values are saved in binary format. Thus, library functions such as fread() and fwrite()are used to read and write the file. File pathname can be provided to the program via user input (scanf ()). Use count sort. You can assume that the smallest value is 0 and the largest value is 999. So it is safe to set counter array size to 1000. Use the similar methods to split the computation and maximize parallelism (local counter array) as what was used in the pthread version, which has been introduced in the class and the textbook. To test your program, you can compile and use gendatai.c and checkdatai.c attached with this assignment. You can run gendatai to generate the file containing random integer values. Then, you run your program to sort the values in the file. After that, you run checkdatai to check whether the values have been sorted in ascending order. Gendatai needs you to provide the number of values and the file pathname in the command line. Checkdatai only needs the file pathname. For example, to generate 5000 random values and save them into ./file5kvalues, you can use the following command ./gendatai 5000 ./file5kvalues To check whether the values are sorted in the file, you run command ./checkdatai ./file5kvalues. Both tools report the sum of the values in the file. You need to compare the sums, in case your program misses some values or includes extra values. You can assume that all integers in the file can fit into memory. So you can malloc a buffer and read all integers into the buffer before doing countsort. You can assume that the number of integers is divisible by the number of processes used to do contsort. So you don’t need to consider the remainders when you try to evenly distribute the data and workload. Problem 2: Calculating the approximation of π Write a pthread program to calculate the approximation of π. The method of calculating of the approximation was introduced in the class in the MPI part. You need to implement this method using pthreads. The number of threads and the number of terms required to calculate the approximation should be specified in the command line. CS288 Intensive Programming in Linux, Prof. Xiaoning Ding DO NOT DISTRIBUTE WITHOUT WRITTEN PERMISSION FROM PROF. XIAONING DING To test your program, run it with different number of terms and different number of threads. You should be able to see that the approximation is closer to the real value of π when you increase the number of terms, and the execution time reduces when you increase the number of threads. Note that the server only has 4 CPU cores. Using more than 4 threads cannot increase speed. Your program usually finishes very quickly when the number of terms is not large. It may take a while only when the number of terms is large enough (e.g., greater than 1 billion). Problem 1: Sort Integers Saved in a File
Answered 6 days AfterDec 02, 2022

Answer To: 1. For each problem, submit1)your program, and2)screenshots (jpg or pngformat) of the...

Nidhi answered on Dec 09 2022
33 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here