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

Update distributedmatrix.cpp

parent 7688fd0a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -54,14 +54,14 @@ int DistributedMatrix::numCols() const { ...@@ -54,14 +54,14 @@ int DistributedMatrix::numCols() const {
double DistributedMatrix::get(int i, int j) const { double DistributedMatrix::get(int i, int j) const {
if (j < startCol || j >= startCol + localCols) { if (j < startCol || j >= startCol + localCols) {
throw std::out_of_range("Attempt to access non-local column in get()"); throw std::out_of_range("Out of range.");
} }
return localData.get(i, j - startCol); return localData.get(i, j - startCol);
} }
void DistributedMatrix::set(int i, int j, double value) { void DistributedMatrix::set(int i, int j, double value) {
if (j < startCol || j >= startCol + localCols) { if (j < startCol || j >= startCol + localCols) {
throw std::out_of_range("Attempt to access non-local column in set()"); throw std::out_of_range("Out of range.)");
} }
localData.set(i, j - startCol, value); localData.set(i, j - startCol, value);
} }
...@@ -79,16 +79,17 @@ int DistributedMatrix::localColIndex(int globalColIndex) const { ...@@ -79,16 +79,17 @@ int DistributedMatrix::localColIndex(int globalColIndex) const {
} }
int DistributedMatrix::ownerProcess(int globalColIndex) const { int DistributedMatrix::ownerProcess(int globalColIndex) const {
int remainingCols = globalCols % numProcesses; std::vector<int> localStartProcesses(numProcesses);
for (int p = 0; p < numProcesses; ++p) { MPI_Allgather(&startCol, 1, MPI_INT, localStartProcesses.data(), 1, MPI_INT, MPI_COMM_WORLD);
int start = p * localCols + min(p, remainingCols);
int cols = localCols + (p < remainingCols ? 1 : 0); for (int p = 1; p < numProcesses; ++p) {
if (globalColIndex >= start && globalColIndex < start + cols) { if (globalColIndex >= localStartProcesses[p-1] && globalColIndex < localStartProcesses[p]) {
return p; return p - 1;
} }
} }
return 0; return numProcesses - 1;
} }
const Matrix& DistributedMatrix::getLocalData() const { const Matrix& DistributedMatrix::getLocalData() const {
...@@ -240,7 +241,6 @@ Matrix DistributedMatrix::multiplyTransposed(const DistributedMatrix &other) con ...@@ -240,7 +241,6 @@ Matrix DistributedMatrix::multiplyTransposed(const DistributedMatrix &other) con
} }
void sync_matrix(Matrix *matrix, int rank, int src) { void sync_matrix(Matrix *matrix, int rank, int src) {
// Utiliser const_cast pour supprimer le qualificatif const, car MPI_Bcast nécessite un void*
MPI_Bcast(const_cast<double*>(matrix->getData().data()), matrix->numRows() * matrix->numCols(), MPI_DOUBLE, src, MPI_COMM_WORLD); MPI_Bcast(const_cast<double*>(matrix->getData().data()), matrix->numRows() * matrix->numCols(), MPI_DOUBLE, src, MPI_COMM_WORLD);
} }
......
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