34 lines
1.8 KiB
Java
34 lines
1.8 KiB
Java
|
public class Main{
|
||
|
public static void main(String[] args){
|
||
|
int[] sizes = {100, 300, 500};
|
||
|
|
||
|
for (int size : sizes) {
|
||
|
int[][] matrixA = MatrixGenerator.generateMatrix(size);
|
||
|
int[][] matrixB = MatrixGenerator.generateMatrix(size);
|
||
|
|
||
|
System.out.println("Размер матрицы: " + size + "x" + size);
|
||
|
System.out.println("Матрица A:");
|
||
|
MatrixPrinter.printMatrix(matrixA, 5);
|
||
|
System.out.println("Матрица B:");
|
||
|
MatrixPrinter.printMatrix(matrixB, 5);
|
||
|
|
||
|
long startSequential = System.nanoTime();
|
||
|
int[][] resultSequential = MatrixMultiplication.multiply(matrixA, matrixB, 1);
|
||
|
long endSequential = System.nanoTime();
|
||
|
System.out.println("Результат последовательного умножения:");
|
||
|
MatrixPrinter.printMatrix(resultSequential, 5);
|
||
|
System.out.println("Время последовательного умножения: " + (endSequential - startSequential) / 1_000_000 + " ms");
|
||
|
|
||
|
for (int numThreads : new int[]{2, 4, 8}) {
|
||
|
long startParallel = System.nanoTime();
|
||
|
int[][] resultParallel = MatrixMultiplication.multiply(matrixA, matrixB, numThreads);
|
||
|
long endParallel = System.nanoTime();
|
||
|
System.out.println("Результат параллельного умножения (" + numThreads + " потоков):");
|
||
|
MatrixPrinter.printMatrix(resultParallel, 5);
|
||
|
System.out.println("Время параллельного умножения: " + (endParallel - startParallel) / 1_000_000 + " ms");
|
||
|
}
|
||
|
System.out.println("--------------------------------------------------");
|
||
|
}
|
||
|
}
|
||
|
}
|