Skip to content
Snippets Groups Projects
Commit 423a8b02 authored by Sebastien Blaise's avatar Sebastien Blaise
Browse files

Faster linearSystemPETScBlock by removing transpose

parent 13036385
No related branches found
No related tags found
No related merge requests found
// Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle // Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle
// //
// See the LICENSE.txt file for license information. Please report all // ee the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@geuz.org>. // bugs and problems to the public mailing list <gmsh@geuz.org>.
#include "GmshConfig.h" #include "GmshConfig.h"
...@@ -35,35 +35,19 @@ void linearSystemPETSc<fullMatrix<double> >::addToMatrix(int row, int col, ...@@ -35,35 +35,19 @@ void linearSystemPETSc<fullMatrix<double> >::addToMatrix(int row, int col,
{ {
if (!_entriesPreAllocated) if (!_entriesPreAllocated)
preAllocateEntries(); preAllocateEntries();
PetscInt i = row, j = col;
#ifdef PETSC_USE_COMPLEX #ifdef PETSC_USE_COMPLEX
fullMatrix<std::complex<double> > modval(val.size1(), val.size2()); fullMatrix<std::complex<double> > modval(val.size1(), val.size2());
for (int ii = 0; ii < val.size1(); ii++) { for (int ii = 0; ii < val.size1(); ii++) {
for (int jj = 0; jj < val.size1(); jj++) { for (int jj = 0; jj < val.size1(); jj++) {
modval(ii, jj) = val (jj, ii); modval(ii, jj) = val (ii, jj);
modval(jj, ii) = val (ii, jj);
} }
} }
MatSetValuesBlocked(_a, 1, &i, 1, &j, modval.getDataPtr(), ADD_VALUES);
#else #else
fullMatrix<double> &modval = *const_cast<fullMatrix<double> *>(&val); MatSetValuesBlocked(_a, 1, &i, 1, &j, val.getDataPtr(), ADD_VALUES);
for (int ii = 0; ii < val.size1(); ii++) {
for (int jj = 0; jj < ii; jj++) {
PetscScalar buff = modval(ii, jj);
modval(ii, jj) = modval (jj, ii);
modval(jj, ii) = buff;
}
}
#endif
PetscInt i = row, j = col;
MatSetValuesBlocked(_a, 1, &i, 1, &j, &modval(0,0), ADD_VALUES);
//transpose back so that the original matrix is not modified
#ifndef PETSC_USE_COMPLEX
for (int ii = 0; ii < val.size1(); ii++)
for (int jj = 0; jj < ii; jj++) {
PetscScalar buff = modval(ii,jj);
modval(ii, jj) = modval (jj,ii);
modval(jj, ii) = buff;
}
#endif #endif
_valuesNotAssembled = true; _valuesNotAssembled = true;
} }
......
...@@ -86,7 +86,7 @@ class linearSystemPETSc : public linearSystem<scalar> { ...@@ -86,7 +86,7 @@ class linearSystemPETSc : public linearSystem<scalar> {
void insertInSparsityPattern (int i, int j); void insertInSparsityPattern (int i, int j);
bool isAllocated() const { return _isAllocated; } bool isAllocated() const { return _isAllocated; }
void preAllocateEntries(); void preAllocateEntries();
void allocate(int nbRows); virtual void allocate(int nbRows);
void print(); void print();
void clear(); void clear();
void getFromMatrix(int row, int col, scalar &val) const; void getFromMatrix(int row, int col, scalar &val) const;
...@@ -100,7 +100,7 @@ class linearSystemPETSc : public linearSystem<scalar> { ...@@ -100,7 +100,7 @@ class linearSystemPETSc : public linearSystem<scalar> {
void zeroRightHandSide(); void zeroRightHandSide();
void zeroSolution(); void zeroSolution();
void printMatlab(const char *filename) const; void printMatlab(const char *filename) const;
int systemSolve(); virtual int systemSolve();
Mat &getMatrix(){ return _a; } Mat &getMatrix(){ return _a; }
//std::vector<scalar> getData(); //std::vector<scalar> getData();
//std::vector<int> getRowPointers(); //std::vector<int> getRowPointers();
...@@ -133,7 +133,7 @@ class linearSystemPETSc : public linearSystem<scalar> { ...@@ -133,7 +133,7 @@ class linearSystemPETSc : public linearSystem<scalar> {
void zeroRightHandSide() {} void zeroRightHandSide() {}
void zeroSolution() {} void zeroSolution() {}
void printMatlab(const char *filename) const{}; void printMatlab(const char *filename) const{};
int systemSolve() { return 0; } virtual int systemSolve() { return 0; }
double normInfRightHandSide() const{return 0;} double normInfRightHandSide() const{return 0;}
}; };
#endif #endif
......
...@@ -156,6 +156,7 @@ void linearSystemPETSc<scalar>::allocate(int nbRows) ...@@ -156,6 +156,7 @@ void linearSystemPETSc<scalar>::allocate(int nbRows)
else { else {
MatSetType(_a, MATSEQBAIJ); MatSetType(_a, MATSEQBAIJ);
} }
MatSetOption(_a, MAT_ROW_ORIENTED, PETSC_FALSE);
} }
// override the default options with the ones from the option // override the default options with the ones from the option
// database (if any) // database (if any)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment