You are required to implement a multi-threaded matrix multiplication program.
The input to the program is two matrixes A(xy) and B(yz) that are read from corresponding text files. The output is a matrix C(x*z) that is written to an output text file.
A parallelized version of matrix multiplication can be done using one of these three methods:
- A thread computes the output C matrix i.e. without multi-threading. (A thread per matrix).
- A thread computes each row in the output C matrix. (A thread per row).
- A thread computes each element in the output C matrix. (A thread per element).
- Implement the multi-threaded matrix multiplication using all three methods described above.
- Compare the three implementations according to the following:
- Number of threads created.
- Execution time taken.
Your programs should do the following:
-
Your program is executed as: ./matMultp Mat1 Mat2 MatOut, where Mat1 and Mat2 are the names of the text files to read the first and second matrices, respectively, and MatOut is the prefix of the text files names to write the output matrices (each file represents one method). If the user does not enter this information, the default is a.txt and b.txt, for input matrixes A and B, and c for output matrices (of all three methods) C. The following example should clarify inputs/outputs files.
Arguments
Example: ./matMultp a b c Input files: a.txt b.txt Output files: c_per_matrix.txt c_per_row.txt c_per_element.txt
No Arguments:
Example: ./matMultp Input files: a.txt b.txt Output files: c_per_matrix.txt c_per_row.txt c_per_element.txt
Custom Arguments:
Example: ./matMultp x y z Input files: x.txt y.txt Output files: z_per_matrix.txt z_per_row.txt z_per_element.txt
-
Read the number of rows and columns of the input matrices. They are written in the first line of the file as βrow=x col=yβ. The following is an example of the format on an input file.
row=3 col=5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-
Read the input matrices from their corresponding files. Each row is on a separate line, columns are separated by spaces.
-
Use threads to calculate the matrix that results from multiplying the input two matrixes.
-
Output the resulting matrices in three files (each file represents one method). The following is an example of the format of the three output files.
c_per_matrix.txt
Method: A thread per matrix row=2 col=2 1 2 3 4
c_per_row.txt
Method: A thread per row row=2 col=2 1 2 3 4
c_per_element.txt
Method: A thread per element row=2 col=2 1 2 3 4
Of course the values of the output matrices should all be the same for all three methods.
1- Download the main files and put them in separate files from other folders.
2-inside the created file that contains main.c and tests folders, open the terminal either by choosing terminal from list appeared after right click in any place in the folder or by pressing on CTRL+ALT+t at the same time.
3- After opening the terminal, we will run the code in the file using make which will compile the code directly .
4- in case you wanna test a file without an argument just write ./matmultp and the files have to be in the same directory as the matmultp.c.
5- In case of test cases with arguments, write the following command ./main test1/a test1/b test1/c (test1 is the name of the folder ,a b are the names of the text inputs while c is the output file).