package sspr1;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Введите размер матрицы: ");
        int size = scanner.nextInt();
        scanner.close();

        int[][] matrix = MatrixGeneration.generateMatrix(size);

        // Запись матрицы в файл
        MatrixGeneration.writeMatrixToFile(matrix, "matrix.txt");
        System.out.println("Матрица записана в файл matrix.txt");

        // Однопоточный алгоритм
        long startTime = System.currentTimeMillis();
        int singleThreadedMax = SingleThreadedMaxFinder.findMax(matrix);
        long endTime = System.currentTimeMillis();
        System.out.println("Single-threaded max: " + singleThreadedMax + ", Time: " + (endTime - startTime) + " ms");

        // Многопоточный алгоритм с ThreadPoolExecutor
        startTime = System.currentTimeMillis();
        int threadPoolMax = ThreadPoolMaxFinder.findMax(matrix, Runtime.getRuntime().availableProcessors());
        endTime = System.currentTimeMillis();
        System.out.println("ThreadPool max: " + threadPoolMax + ", Time: " + (endTime - startTime) + " ms");

        // Многопоточный алгоритм с ForkJoinPool
        startTime = System.currentTimeMillis();
        int forkJoinMax = ForkJoinMaxFinder.findMax(matrix);
        endTime = System.currentTimeMillis();
        System.out.println("ForkJoin max: " + forkJoinMax + ", Time: " + (endTime - startTime) + " ms");
    }
}