1
Programming Assignment 2
CSC 4320/6320 – Operating Systems
Spring 2023
Due Date: Feb. 20 (Mon.), 11:59pm
Purpose of This Project
To provide experience with pthreads in UNIX
Problem Statement:
Wildfire spread simulation needs to use fuel data that describe the fuel types (i.e., vegetation types) of an
area. There are 13 standard fuel types, represented by 1-13 integer numbers. The fuel data are stored in a
grid, where the size of the grid specifies the dimension of the area and an element of the grid defines the
fuel type at the corresponding location of the area. See example below for a 10 x 10 fuel data.
Given a 200 x 200 fuel data, we are interested in counting the number of occurrences for each fuel type.
Due to data errors, we also want to know if there exist any invalid data points (an invalid data point has an
integer value that is not between 1 to 13 (inclusive)).
Your task is to design a multi-threaded application to count the number of occurrences of each fuel type
and if there exist invalid data points. Your program should create 20 new threads:
• The first set of 10 worker threads count the number of occurrences for each fuel type (excluding
the invalid data points), and prints out the number of occurrences for fuel type 1, 2, …, 13,
respectively. Each thread is responsible for counting 20 rows: the 1st thread counts rows 1-20, the
2nd thread counts rows 21-40, …, the 10th thread counts rows 181-200.
• The second set of 10 worker threads check if there exist invalid data points, and print out a message
that is either “VALID data” or “INVALID data exist”. Each thread is responsible for checking 20
columns: the 1st thread checks columns 1-20, the 2nd thread checks columns 21-40, …, the 10th
thread checks columns 181-200.
• The parent thread combines results from all the worker threads and prints out the final results. To
pass each thread’s results back to the parent thread, you can follow a similar design from the Sudoku
Solution Validator project described in the textbook (page 197 to 199), which is uploaded to the
iCollege. Specifically, a 2D integer array in the size of [10][13] can be used to pass the occurrence
number results, where the ith row corresponds to the ith worker thread, and the jth element of a row
corresponds to the occurrence number for jth fuel type. Another 1D array can be used to pass the
data checking results, in a similar way as described in the Sudoku Solution Validator project.
• When creating a thread, the parent should assign the thread a unique ID and pass that as a parameter
to the created thread. The IDs of the 20 threads are 1, 2, 3, …, 20, respectively. See the Sudoku
Solution Validator project description to learn how to create worker thread and pass parameters.
Note: you need to extend the parameter struct by adding an extra thread ID parameter.
Write your program using pthreads. Your project must meet the following requirements for full credit:
2
1. The input will be a txt file whose name is given on the command line. This file contains integers in a
200×200 grid. There will be a space between each digit so that you may read in the data either as
integers or as characters. Sample txt files (Wildfire_Fuel_test1.txt, Wildfire_Fuel_test2.txt) are
provided in iCollege under Homework2 folder.
2. The output of the program should be displayed to the screen with a printout message from each worker
thread, and the overall printout message from the parent thread. The printout message from a worker
thread should include its thread ID as part of the message. See screenshot below as an example for the
10 x 10 fuel data described above.
Design Notes
1. Program in c in the Linux Virtual Machine environment. A skeleton of Wildfire_Fuel_Data_skeleton.c
can be downloaded from iCollege.
2. Appropriate error checking of the command line and the file open should be completed.
3. Since the grid is shared between threads, it should be declared in the global data space before the main
program. This also would be the case for any other data being shared between threads.
Assignment:
1. (20 points) Implementation of this project individually. Programs should exhibit a modular design.
Using gcc -pthread -o WildireFuelData Wildfire_Fuel_Data.c to compile, and then an executable
file WildireFuelData would be generated. Use ./ WildireFuelData to execute the program. Note:
when grading we will recompile your program and use new fuel data files to test your program.
2. (5 points). Provide a high-level description (not more than half page) of the program describing the
functionality of the major components (including data structures) of the program and how they interact
with each other to achieve the task.
3. (5 points). Discuss the advantages and disadvantages of using 20 threads to solve this problem vs. using
2 threads (one to do all the fuel type counting, one to do all the data checking) vs. the parent thread
does all the work (without creating new threads).
What to submit (submit through iCollege):
Upload file Wildfire_Fuel_Data.c and a project report (named as “HW2.pdf” or “HW2.doc”) to iCollege.
The project report should include 1). a screenshot of the output for Wildfire_Fuel_test1.txt; 2) description
for question 2 (see above); 3) discussion for question 3 (see above).