CS131 Parallel and Distributed Systems​ LAB 1

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

CS131 Parallel and Distributed Systems

LAB 1:  C++ Threads

Implementation due 04/26/24 (Wednesday) - 11:55 pm

PART A (Data Races):

1.     Build the given source code with two threads accessing the shared queue. Is the code executing correctly? Use thread sanitizer to analyze the code for data races.

2.     Fix data race using mutex. Demonstrate that your code has no data races.

3.     Now use lock-free synchronization primitives that were shown during the discussion (compare_exchange). What are the benefits of using lock-free synchronization primitives?

PART B (Parallel image processing):

Implement the parallel image processing algorithm using the skeleton code provided on Canvas. The algorithm takes a grayscale image as input and outputs a processed image with edge outlines.

You will be provided with a skeleton program to get a head start with the solution. The solution must work as follows:

1.     Read command line arguments to fetch names of the input and output image (.pgm images).

2.     Read the image file into a 2-D array.

3.     Implement the edge detection function (adjust the code to use threads)

4.     Generate the output image and write it into .pgm file

Point Breakdown:

Part A: Implementation -> 30 pts; Report -> 30pts

Part B: Implementation -> 40 pts

Compiling and Running the code:

To compile you must use gcc available from the module system.

 

$ module load gcc/local

 

To compile use the std=c++11 –pthread flags like so:

 

$ g++ -std=c++11 –pthread source.cpp –o binary.out

 

It is highly recommended to use the compilation flag –Wall to detect errors early, like so:

 

$ g++ -Wall -std=c++11 –pthread source.cpp –o binary.out

 

To check for data races in your code, use the following flags (more about them in the discussion):

 

$ g++ -Wall -std=c++11 –pthread source.cpp –o binary.out        -fsanitize=thread -fPIE -pie

 

If there are any possible data races detected in the code, they will be shown as warnings on execution.

 

Submit the .pdf file with your report and .cpp source files in a .zip archive via Canvas (Assignment "Lab1")

1.       Report and C++ source file for Part A: PartA.zip

2.       C++ source file for Part B: PartB.zip

USEFUL LINKS:

C++ Threads Examples: https://www.classes.cs.uchicago.edu/archive/2013/spring/12300-1/labs/lab6/           

C++ Threads Tutorial: http://thispointer.com/c-11-multithreading-part-1-three-different-ways-to-create-threads/                                                              

C++ Thread Sanitizer for detecting Data Races: https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual

发表评论

电子邮件地址不会被公开。 必填项已用*标注