This Java program performs matrix multiplication using multithreading. It utilizes threads to multiply matrices concurrently, enhancing the performance for larger matrices.
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.
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.
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.
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.
To use this code:
- Compile the Java files:
javac Main.java
- Run the compiled program:
java Main