Skip to content

Matrices multiplication with threads synchronisation using producer-consumer model (java , C)

Notifications You must be signed in to change notification settings

BigBr41n/Operating-system-Threads-synchronisation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Matrix Multiplication with Multithreading

This Java program performs matrix multiplication using multithreading. It utilizes threads to multiply matrices concurrently, enhancing the performance for larger matrices.

Files

  • Main.java: Contains the main method to generate matrices, perform matrix multiplication, and display the results.
  • IndexesOfThreadsData.java: Defines a class to hold thread-related indexes and data.
  • MatrixMultiplier.java: Class responsible for matrix multiplication using multithreading.

Classes

Main.java

The Main class handles the execution flow, matrix generation, and result display.

  • main(String[] args): Entry point of the program. Generates random matrices, performs matrix multiplication, and prints the resulting matrix.
  • generateMatrix(): Generates a random matrix with specified dimensions and random values.
  • printMatrix(int[][] matrix): Prints the given matrix to the console.

IndexesOfThreadsData.java

This class defines the data structure to hold thread-related indexes and data used in the matrix multiplication process.

  • int row: Holds the row index.
  • int column: Holds the column index.
  • int data: Holds the computed data during the multiplication.

MatrixMultiplier.java

This class handles matrix multiplication using multithreading.

  • MatrixMultiplier(int[][] matrixA, int[][] matrixB): Constructor initializes matrices and sets buffer size based on matrix dimensions.
  • multiplyMatrices(): Method to perform matrix multiplication with multithreading and return the resulting matrix.
  • generateIndexVector(): Generates an index vector for threads based on matrix dimensions.
  • producer(IndexesOfThreadsData args): Performs matrix multiplication for each thread and places the result in the buffer.

How to Use

To use this code:

  1. Compile the Java files: javac Main.java
  2. Run the compiled program: java Main

About

Matrices multiplication with threads synchronisation using producer-consumer model (java , C)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%