Skip to content
Extraits de code Groupes Projets
Valider 9a7e5b54 rédigé par JordanHanotiaux's avatar JordanHanotiaux
Parcourir les fichiers

Update distributedtests.cpp

parent 2ea1e08d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -32,7 +32,7 @@ bool matricesEqual(const Matrix& a, const Matrix& b, double epsilon = 1e-10) {
void testMultiplyTransposed() {
int sizes[] = {512, 1024, 2058};
int sizes[] = {256, 512, 1024};
int rank, numProcs;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
......@@ -40,51 +40,68 @@ void testMultiplyTransposed() {
std::ofstream csvFile;
if (rank == 0) {
csvFile.open("results.csv");
csvFile << "MatrixSize,SequentialTime,DistributedTime,SpeedUp\n";
csvFile << "MatrixSize,AverageSequentialTime,AverageDistributedTime,AverageSpeedUp\n";
}
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);
double totalTimeSeq = 0.0;
double totalTimeDist = 0.0;
for (int rep = 0; rep < 3; ++rep) {
// 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éation des matrices distribuées
DistributedMatrix matrix1(matrix1Full, numProcs);
DistributedMatrix matrix2(matrix2Full, numProcs);
// Création des matrices distribuées
DistributedMatrix matrix1(matrix1Full, numProcs);
DistributedMatrix matrix2(matrix2Full, numProcs);
// 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;
// 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;
}
// 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;
// Broadcast pour que tous les rangs aient les mêmes valeurs de temps
MPI_Bcast(&timeSeq, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// 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;
// Accumuler
totalTimeSeq += timeSeq;
totalTimeDist += timeDist;
}
double speedUp = timeSeq / timeDist;
// Moyennes
double avgSeq = totalTimeSeq / 3.0;
double avgDist = totalTimeDist / 3.0;
double avgSpeedUp = avgSeq / avgDist;
if (rank == 0) {
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 << "Avg sequential time: " << avgSeq << " s" << std::endl;
std::cout << "Avg distributed time: " << avgDist << " s" << std::endl;
std::cout << "Avg speed up: " << avgSpeedUp << std::endl;
std::cout << "-----------------------------------------" << std::endl;
csvFile << N << "," << timeSeq << "," << timeDist << "," << speedUp << "\n";
csvFile << N << "," << avgSeq << "," << avgDist << "," << avgSpeedUp << "\n";
}
}
......@@ -94,6 +111,7 @@ void testMultiplyTransposed() {
}
}
int main(int argc, char** argv) {
// Initialiser MPI
int initialized;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter