diff --git a/P2/distributedtests.cpp b/P2/distributedtests.cpp index 58ef090a6dc60659220ea1874d67d4b50cfc4c33..fa2a99f29a4a6499163d0d42772bed5b1bff214e 100644 --- a/P2/distributedtests.cpp +++ b/P2/distributedtests.cpp @@ -2,6 +2,7 @@ #include "matrix.hpp" #include "mlp_sgd_distributed.cpp" #include <mpi.h> +#include <fstream> #include <iostream> #include <cassert> #include <cmath> @@ -30,45 +31,67 @@ bool matricesEqual(const Matrix& a, const Matrix& b, double epsilon = 1e-10) { return true; } -// Test multiplyTransposed avec NVTX pour marquage et analyse des performances + void testMultiplyTransposed() { - int rank; + int sizes[] = {512, 1024, 2058}; + int rank, numProcs; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - // Créer des matrices de test - Matrix matrix1Full(1024, 1024); - Matrix matrix2Full(1024, 1024); - for (int i = 0; i < 1024; i++) { - for (int j = 0; j < 1024; j++) { - matrix1Full.set(i, j, i * 5 + j + 1); - } + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + std::ofstream csvFile; + if (rank == 0) { + csvFile.open("results.csv"); + csvFile << "MatrixSize,SequentialTime,DistributedTime,SpeedUp\n"; } - for (int i = 0; i < 1024; i++) { - for (int j = 0; j < 1024; j++) { - matrix2Full.set(i, j, i * 5 + j + 2); + + for (int s = 0; s < 3; ++s) { + int N = sizes[s]; + + // Initialisation des matrices pleines + Matrix matrix1Full(N, N); + Matrix matrix2Full(N, N); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + matrix1Full.set(i, j, i * 5 + j + 1); + matrix2Full.set(i, j, i * 5 + j + 2); + } } - } - // Créer des matrices distribuées - int numProcs; - MPI_Comm_size(MPI_COMM_WORLD, &numProcs); - DistributedMatrix matrix1(matrix1Full, numProcs); - DistributedMatrix matrix2(matrix2Full, numProcs); + // Création des matrices distribuées + DistributedMatrix matrix1(matrix1Full, numProcs); + DistributedMatrix matrix2(matrix2Full, numProcs); - // Profilage avec NVTX pour marquer les sections de calcul - nvtxRangePushA("MPI_Init"); // Début de l'initialisation MPI + // Chronométrage de l'opération distribuée + MPI_Barrier(MPI_COMM_WORLD); + double startDistributed = MPI_Wtime(); + Matrix resultDistributed = matrix1.multiplyTransposed(matrix2); + MPI_Barrier(MPI_COMM_WORLD); + double endDistributed = MPI_Wtime(); + double timeDist = endDistributed - startDistributed; - // Profilage du calcul (avant l'opération) - nvtxRangePushA("DistributedMatrix::multiplyTransposed"); + // Chronométrage de l'opération séquentielle + double timeSeq = 0.0; + if (rank == 0) { + double startSequential = MPI_Wtime(); + Matrix resultSequential = matrix1Full * matrix2Full.transpose(); + double endSequential = MPI_Wtime(); + timeSeq = endSequential - startSequential; - // Exécuter A * B^T - Matrix result = matrix1.multiplyTransposed(matrix2); + double speedUp = timeSeq / timeDist; - nvtxRangePop(); // Fin de l'opération multiplyTransposed - nvtxRangePop(); // Fin de l'initialisation MPI + std::cout << "Matrix size: " << N << "x" << N << std::endl; + std::cout << "Sequential time: " << timeSeq << " s" << std::endl; + std::cout << "Distributed time: " << timeDist << " s" << std::endl; + std::cout << "Speed up (Seq/Dist): " << speedUp << std::endl; + std::cout << "-----------------------------------------" << std::endl; + + csvFile << N << "," << timeSeq << "," << timeDist << "," << speedUp << "\n"; + } + } if (rank == 0) { - std::cout << "MultiplyTransposed test passed!" << std::endl; + csvFile.close(); + std::cout << "Results written to results.csv\n"; } } diff --git a/P2/profile1.png b/P2/profile1.png new file mode 100644 index 0000000000000000000000000000000000000000..f875bc4da819222eb0ba2164ddbf6625feb8fcec Binary files /dev/null and b/P2/profile1.png differ diff --git a/P2/profile2.png b/P2/profile2.png new file mode 100644 index 0000000000000000000000000000000000000000..e9ea16c307e64d4483290042c279f0f1e0fed4a6 Binary files /dev/null and b/P2/profile2.png differ diff --git a/P2/profile_mpi_computation.nsys-rep b/P2/profile_mpi_computation.nsys-rep index ed47663cc222cada6ee9eba0c164e8069be3537c..ab8d9f7b6cbe84179381333d1705bc2d12297109 100644 Binary files a/P2/profile_mpi_computation.nsys-rep and b/P2/profile_mpi_computation.nsys-rep differ diff --git a/P2/profile_mpi_computation.sqlite b/P2/profile_mpi_computation.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..9ca65dbccbd66a1181a0699d4699f60bc2696628 Binary files /dev/null and b/P2/profile_mpi_computation.sqlite differ