Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C. Provided the skeleton code to use and Sudoku reference. Must use a fuel data from a txt file. Thank you Figure 4.19 Solution

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedUse C. Provided the skeleton code to use and Sudoku reference. Must use a fuel data from a txt file. Thank you

Figure 4.19 Solution to a 99 Sudoku puzzle. columns, you could create nine separate threads and have each of them check one column. Passing Parameters to Each Thread The parent thread will create the worker threads, passing each worker the location that it must check in the Sudoku grid. This step will require passing several parameters to each thread. The easiest approach is to create a data structure using a struct. For example, a structure to pass the row and column where a thread must begin validating would appear as follows: / structure for passing data to threads / typedef struct \{ int row; int column; \} parameters; Both Pthreads and Windows programs will create worker threads using a strategy similar to that shown below: parameters data =( parameters ) malloc (sizeof ( parameters)); data row =1; data > column =1; / Now create the thread passing it data as a parameter / The data pointer will be passed to either the pthread_create () (Pthreads) function or the CreateThread() (Windows) function, which in turn will pass it as a parameter to the function that is to run as a separate thread. Returning Results to the Parent Thread Each worker thread is assigned the task of determining the validity of a particular region of the Sudoku puzzle. Once a worker has performed this Figure 4.20 Multithreaded sorting. check, it must pass its results back to the parent. One good way to handle this is to create an array of integer values that is visible to each thread. The ith index in this array corresponds to the ith worker thread. If a worker sets its corresponding value to 1 , it is indicating that its region of the Sudoku puzzle is valid. A value of 0 would indicate otherwise. When all worker threads have completed, the parent thread checks each entry in the result array to determine if the Sudoku puzzle is valid. 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 1010 fuel data. Given a 200200 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 1 st thread counts rows 1-20, the 2 nd thread counts rows 2140,, the 10th thread counts rows 181200. - 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 1 st thread checks columns 120, the 2 nd thread checks columns 2140,, 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. 1. The input will be a txt file whose name is given on the command line. This file contains integers in a 200x200 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 1010 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 gec -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). A Sudoku puzzle uses a 99 grid in which each column and row, as well as each of the nine 33 subgrids, must contain all of the digits 19. Figure 4.19 presents an example of a valid Sudoku puzzle. This project consists of designing a multithreaded application that determines whether the solution to a Sudoku puzzle is valid. There are several different ways of multithreading this application. One suggested strategy is to create threads that check the following criteria: - A thread to check that each column contains the digits 1 through 9 - A thread to check that each row contains the digits 1 through 9 - Nine threads to check that each of the 33 subgrids contains the digits 1 through 9 This would result in a total of eleven separate threads for validating a Sudoku puzzle. However, you are welcome to create even more threads for this project. For example, rather than creating one thread that checks all nine

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions