// // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution. #include "parallel/PetscHelper.h" namespace AMDiS { namespace petsc_helper { using namespace std; void getMatLocalColumn(Mat mat, PetscMatCol &matCol) { PetscInt firstIndex, lastIndex; MatGetOwnershipRange(mat, &firstIndex, &lastIndex); PetscInt nCols; const PetscInt *cols; const PetscScalar *values; for (int row = firstIndex; row < lastIndex; row++) { MatGetRow(mat, row, &nCols, &cols, &values); for (int i = 0; i < nCols; i++) { if (values[i] != 0.0) { matCol[cols[i]].first.push_back(row - firstIndex); matCol[cols[i]].second.push_back(values[i]); } } MatRestoreRow(mat, row, &nCols, &cols, &values); } } void setMatLocalColumn(Mat mat, int column, Vec vec) { PetscInt firstIndex; MatGetOwnershipRange(mat, &firstIndex, PETSC_NULL); PetscInt vecSize; VecGetLocalSize(vec, &vecSize); PetscScalar *tmpValues; VecGetArray(vec, &tmpValues); for (int i = 0; i < vecSize; i++) MatSetValue(mat, firstIndex + i, column, tmpValues[i], ADD_VALUES); VecRestoreArray(vec, &tmpValues); } void getColumnVec(const SparseCol &matCol, Vec vec) { VecSet(vec, 0.0); VecSetValues(vec, matCol.first.size(), &(matCol.first[0]), &(matCol.second[0]), INSERT_VALUES); VecAssemblyBegin(vec); VecAssemblyEnd(vec); } } }