You want to make a C program that uses the system call, where possible, to implement the skeleton of a system of parallel arithmetic. The project must be commented in Doxygen format, and accompanied by a script configuration tool for such a script and Makefile for compiling.
The program will read a configuration file, containing:
[login to view URL] number of processes parallel computing.
[login to view URL] data computation
The configuration file will have 'the following structure:
• The first line will contain 'an integer, which corresponds to the number of parallel processes to create, NPROC.
• The other lines will have the following format: , where:
[login to view URL] is 'the number of parallel process in which to do this, and if' greater than or equal to 1. If and 'zero indicates that the operation must' be done by the first free process. Assume that id always corresponds to a correct value.
[login to view URL] and num2 are two integers, corresponding to the data on which to perform the operation.
[login to view URL] is character representing the operation to be performed on the two numbers. Valid characters for op are: '+', '-', '*', '/', representing respectively the sum, subtraction, multiplication and division.
For example, a configuration file may be
------------------
5
3 2/9
3 234 + 653
4 3444 + 153
0 34 * 1873
3 0 - 21534
------------------
Each process will execute a routine like this:
1. Waiting on a semaphore to perform a calculation.
2. Receiving data and task to be executed by the parent process.
1. If it receives the command termination, ending his run. The command termination and 'indicated by' K '.
3. Execution of the calculation.
4. Sending the result to the father, and reporting to the father who has finished calculating.
5. Waiting on the same semaphore locking in step 1, wait for the next command.
The parent process will communicate 'with child processes using shared memory.
The parent process will perform 'in this way:
1. Setup of the simulation, reading from the configuration file the number of processors to simulate the processes for creating and creating and initializing any supporting facilities such as semaphores and shared memory. Also, will 'create an array to store the results of your actions. The length of this array will be 'derived from the number of read operations from the configuration file.
2. Entry into a cycle for each operation to be simulated does the following:
1. If the command id different from zero, waits for the process id number is free, without prejudice to the outcome of any previous calculation results in the array, and then interacts with him passing it the command to simulate. The parent process should not wait until the processor has completed the simulation of the operation passed to his son.
2. If the instruction has id 0, is the first free processor interacts with it, and if, as in step 1. Otherwise, wait for at least one processor is free, and then interacts with it as in step 1.
3. Passed all controls to their children, waits for child processes have completed all their calculations.
4. Save the array of the latest results computed results, and terminates child processes passing the termination command 'K'.
5. Expects that all children have terminated.
6. Printing to a file output all the results.
7. Free any resources.
8. Out.
It adds to the child processes and the parent process prints on the screen in order to follow the execution.
For each call to a system call, it should be checked that the function is successful.
All prints on the screen, reads and writes to the file must be made using system call (so for example you can not use printf, fprintf, scanf, fscanf, perror).