Directions: Use a file city.txt for answering the questions that follow each scheduling algorithm. This file has three columns (comma separated): the first column contains the job Id, the second column indicates the CPU burst, and column three is the arrival time of the corresponding job. Parallel Programming It is vaccine season! COVID19 vaccines are out, and everyone is rushing to get one. Vaccines are available from six different brands and you have been entrusted to write a program to count the total number of vaccines of each brand administered across 21 cities in the state. Write a multithreaded program (in the file vaccines.cpp) that counts the number of vaccines in 21 different files of numbers. Each line in each of the files will contain either one of the following brand names: v1, v2, v3. Your program must count the number of units for each vaccine brand administered, across all 21 cities, and display the tota
Directions:
Use a file city.txt for answering the questions that follow each scheduling
Parallel
It is vaccine season! COVID19 vaccines are out, and everyone is rushing to get one. Vaccines are available from six different brands and you have been entrusted to write a program to count the total number of vaccines of each brand administered across 21 cities in the state. Write a multithreaded program (in the file vaccines.cpp) that counts the number of vaccines in 21 different files of numbers. Each line in each of the files will contain either one of the following brand names: v1, v2, v3. Your program must count the number of units for each vaccine brand administered, across all 21 cities, and display the total number of units for each brand. The files are named "city1.txt", “city2.txt", … , and " city21.txt".
Illustrative Toy Example:
If there were only three cities, with the contents of the files as below, your program should print the following.
“city1.txt” “city2.txt” “city3.txt”
V1 V2 V3 V1 V2 V3 |
|
V2 V3 V1 V3 V3 V3 |
V1 V2 V2 V2 V3 V2 |
Total vaccine counts across 3 cities:
v1 = 4
v2 = 7
v3 = 7
Additional Requirements
- The program should create 21 threads, each thread should process a different input file.
- Your program must read the files from a directory
o Do not assume the input files are in the current directory.
o The directory and file names must be hard-coded into the program. Do NOT prompt the user for this information.
- Assuming error-free execution, the only output the program should produce is the cumulative unit count for each vaccine brand. Do NOT print out the individual counts for each file.
- The program must use appropriate data structures and loops to avoid redundant code. Code that replicates something 21 times (such as 21 pthread_create calls) are not allowed.
- Global variables are not permitted! Properly pass parameters into the thread function and use pthread_join to return the tally from each file. Global variables are nor allowed
- You must use Pthreads to implement the threading. You are not permitted to use the threading features present in C++ 11.
- No makefile is required for this assignment.
Error Checking
- If a pthread function returns an error, abort the program with an error message.
Assumptions
- Each input file will contain at least one line. Beyond this, you cannot make any assumptions on how long the input file is.
- You may assume that each line only contains one of the three names noted in the description
Trending now
This is a popular solution!
Step by step
Solved in 9 steps