Newer
Older
#include "distributedmatrix.hpp"
#include "matrix.hpp"
#include "mlp_sgd_distributed.cpp"
#include <mpi.h>
#include <iostream>
#include <cassert>
#include <cmath>
#include <functional>
// Fonction utilitaire pour vérifier si deux doubles sont proches
bool approxEqual(double a, double b, double epsilon = 1e-10) {
return std::abs(a - b) < epsilon;
}
// Fonction utilitaire pour vérifier si deux matrices sont égales
bool matricesEqual(const Matrix& a, const Matrix& b, double epsilon = 1e-10) {
if (a.numRows() != b.numRows() || a.numCols() != b.numCols()) {
return false;
}
for (int i = 0; i < a.numRows(); i++) {
for (int j = 0; j < a.numCols(); j++) {
if (!approxEqual(a.get(i, j), b.get(i, j), epsilon)) {
return false;
}
}
}
// Test multiplyTransposed avec NVTX pour marquage et analyse des performances
void testMultiplyTransposed() {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
Matrix matrix2Full(1024, 1024);
for (int i = 0; i < 1024; i++) {
for (int j = 0; j < 1024; j++) {
for (int i = 0; i < 1024; i++) {
for (int j = 0; j < 1024; j++) {
int numProcs;
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
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
// Profilage du calcul (avant l'opération)
nvtxRangePushA("DistributedMatrix::multiplyTransposed");
// Exécuter A * B^T
Matrix result = matrix1.multiplyTransposed(matrix2);
nvtxRangePop(); // Fin de l'opération multiplyTransposed
nvtxRangePop(); // Fin de l'initialisation MPI
if (rank == 0) {
std::cout << "MultiplyTransposed test passed!" << std::endl;
}
}
int initialized;
MPI_Initialized(&initialized);
if (!initialized) {
MPI_Init(&argc, &argv);
}
if (rank == 0) {
std::cout << "Starting DistributedMatrix tests..." << std::endl;
}
if (rank == 0) {
std::cout << "All tests passed successfully!" << std::endl;
}
}
catch (std::exception& e) {
if (rank == 0) {
std::cerr << "Test failed with exception: " << e.what() << std::endl;
}
MPI_Abort(MPI_COMM_WORLD, 1);
}