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

Update distributedmatrix.cpp

parent f091e2ce
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -214,29 +214,40 @@ DistributedMatrix multiply(const Matrix& left, const DistributedMatrix& right) {
}
Matrix DistributedMatrix::multiplyTransposed(const DistributedMatrix &other) const {
Matrix local = localData * other.localData.transpose();
double *resultData = (double*) malloc(globalRows * other.globalRows * sizeof(double));
// Effectuer la réduction
MPI_Allreduce(local.getData().data(), resultData, globalRows * other.globalRows, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
// Affichage de resultData avant de le libérer
if (rank == 0) { // Print seulement sur le processus 0
std::cout << "Contenu de resultData:" << std::endl;
for (int i = 0; i < globalRows; ++i) {
for (int j = 0; j < other.globalRows; ++j) {
int index = i * other.globalRows + j;
std::cout << resultData[index] << " ";
}
std::cout << std::endl;
Matrix result = (*this).localData * other.getLocalData().transpose();
int localSize = result.numRows() * result.numCols();
std::vector<int> counts(numProcesses);
std::vector<int> displacements(numProcesses);
MPI_Allgather(&localSize, 1, MPI_INT, counts.data(), 1, MPI_INT, MPI_COMM_WORLD);
displacements[0] = 0;
for (int i = 1; i < numProcesses; ++i)
displacements[i] = displacements[i - 1] + counts[i - 1];
std::vector<double> buffer(this->globalRows * other.globalRows);
MPI_Allreduce(
result.getData().data(),
buffer.data(),
globalRows * other.globalRows,
MPI_DOUBLE,
MPI_SUM,
MPI_COMM_WORLD
);
Matrix fullMatrix(globalRows, other.globalRows);
for (int i = 0; i < globalRows; ++i) {
for (int j = 0; j < other.globalRows; ++j) {
fullMatrix.set(i, j, buffer[i * other.globalRows + j]);
}
}
// Créer le résultat final
Matrix result(globalRows, other.globalRows);
free(resultData); // Libération de la mémoire allouée
return result;
return fullMatrix;
}
......@@ -247,4 +258,3 @@ Matrix DistributedMatrix::multiplyTransposed(const DistributedMatrix &other) con
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