Return to Operationg Systems home
The program named lab06e01recursive.c receives from the command line an integer value
n and, using recursion (see funcition
binary), it generates and visualizes all the binary numbers of
Transform the program from recursive to concurrent, i.e., substitute the recursive implementation with the generation (by means of a
fork()) of an adequate number of processes capable of printing the binary numbers (the order is not important).
Implement a concurrent program with
n threads that sorts an input file. The program must proceed in parallel on different files, according to the following specifications.
The program (which name
pgrm) receives 3 parameters from command line
pgrm n strA strB
nis an integer value
strAis a string that identifies the name of
ninput files of name 'strA1.txt, strA2.txt, …, strAn.txt'
strBis a string that identifies the name of
noutput files of name 'strB1.txt, strB2.txt, …, strBn.txt'
The input files
The following is an example of correct file:
5 102 99 34 234 25
The program, after the generation of the
n names of the two input and output files, activates
Note that the program implements the following precedence graph:
Mi--------- /\ | / \ | R1 R2 ... | | O1 O2 ... | | W1 W2 ... \ / \/ | Mf---------
Modify the previous program in a way that the
n sorted sequences (read from file) are merged to generate a single ordered sequence.
More in detail:
main(), after executing the threads, waits for their termination, and after the termination of one of them, it starts the merging of the data just ordered with those merged previously
The third command line parameter of the program indicates the name of the output file. For simplicity (to allocate the data structure) it is possible to suppose that all the files store the same number of values and, eventually, this number is known a priori.
Use a matrix to store the data read by the input files, and dedicate a row (or a column) to each file (or, alternatively, a vector of structures with a vector field).
Each thread manipulates exclusively its own row (or column) of the matrix (or element of the vector).
main() perform the merge of the sequences sorted in pair:
0(zero) data with
nold data with
2*nold data with
main() can make use of one or more support vector for the merging of the matrix data.