Question
CODE in C++ Given an array of numbers A and a number v, we use count(A, v) to denote the number of occurrences of v
CODE in C++
Given an array of numbers A and a number v, we use count(A, v) to denote the number of occurrences of v in A. We refer to this problem as occurrence-counting problem. In the project, you will use concurrency using processes (not threads) to solve the occurrence-counting problem by having each process scan only a portion of the array A. Your program will accept three command-line arguments: the array size s, a file name f, and the degree of concurrency d. The file f will contain array A of size s as a sequence of integers. The degree of concurrency d specifies how many processes will be used to concurrently scan the array. Your program has to be handle any errors in the command line arguments robustly. For example, if file f contains fewer than s entries or non-numeric values, then the program should print a reasonable error message and terminate. When the program is run, it shall read the array A from the file f and then spawn d worker processes using fork( ) system call. The main process will then repeatedly execute the following sequence of steps until it terminates: (a) Prompt the user to enter a number and read its value, say v. (b) Use the worker processes to concurrently count the number of occurrences of the number v in the array A. (c) Aggregate the output generated by all worker processes and print the result on the screen. To terminate the program, the user will need to type "quit" (instead of a number) at the prompt. Upon reading "quit", the main process will instruct all worker processes to terminate, collect the return status of each worker process using wait( ) system call, print the total number of queries handled on the screen, and then terminate. You must use shared memory to share the input array A among all processes (the main process as well as worker processes). You will also need a synchronization mechanism that allows: 1 (i) The main process to instruct the worker processes to either initiate the scan of their respective portions (of the array) or terminate. (ii) A worker process to report its result back to the main process.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started