Giter Site home page Giter Site logo

matrices_multiplication_multithreading's Introduction

Matrices_multiplication_multithreading

image

1. Overview

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:

  1. A thread computes the output C matrix i.e. without multi-threading. (A thread per matrix). A Thread per row
  2. A thread computes each row in the output C matrix. (A thread per row). A Thread per row
  3. A thread computes each element in the output C matrix. (A thread per element). A Thread per element

2. Requirements

  • Implement the multi-threaded matrix multiplication using all three methods described above.
  • Compare the three implementations according to the following:
    1. Number of threads created.
    2. 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.

How to run and compile the code:

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).

matrices_multiplication_multithreading's People

Contributors

bassantyasser043 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.