CS 5600 Homework 2 Schedule solution




5/5 - (4 votes)

Argument parsing
Both master and worker programs should be able to parse argument passed in arbitrary order.
In case of invalid arguments, i.e., unknown argument, missing argument, etc., an appropriate error message should be printed along with a usage message.
You can use any of the standard argument parsing library functions or write your own.
Update 1 (Sept 19, 2017 2:45 AM) – Pool of workers.
The maximum number of active child worker processes should never exceed the value specified by the –num_workers flag.
In lieu of the above modification, the “sequential” and “poll” mechanisms are now optional.
For this assignment, we will implement a multi-process solution to compute exponential function using a master-worker architecture:

The master is launched using the following command:
$ ./master –worker_path ./worker –num_workers 5 –wait_mechanism MECHANISM -x 2 -n 12
The flag –worker_path is used to point to the worker binary.
The flag –num_workers specifies the maximum number of child worker processes that can be spawned using fork().
Where MECHANISM is one of sequential, select, poll, or epoll. See below for more details.
The rest of the flags indicate the values of x and n to compute ex (for n in [0..11]).
The master spawns as many child worker processes as specified by the –num_workers flag. If n is greater than the number of available worker processes, the master process waits until a worker process exits before creating a new worker process to compute the next term.
The worker should be individually testable, i.e., one should be able to run it as follows:
$ ./worker -x 2 -n 3
x^n / n! : 1.3333
It should print additional help text (e.g., x^n / n! : ) on the console if its standard-out is a terminal.
If the standard-out is a pipe, worker should simply write the result into the pipe before exiting.
Master-worker communication
Master will communicate with each worker via a separate pipe.
The write-end of the pipe is made standard-out of the worker.
The master reads the result from worker on the read-end of the pipe and prints it on the screen. Here is an example for worker 3:
worker 3: 2^3 / 3! : 1.3333
Waiting for workers
You have to implement the following mechanisms in the Master:
Sequential: first worker, followed by second, third, and so on.
Using select system call to read the workers’ output in the order it becomes available.
The above using poll system call.
The above using epoll system call.
Follow the guidelines as specified on the submission page.