Commit 79637520 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#890 Wrappers/Petsc: MatGetRow() is now available with two prototypes. I had...

#890 Wrappers/Petsc: MatGetRow() is now available with two prototypes. I had to use internal Petsc code to avoid a crash in parallel when a line was actually empty (they handled it through a crash rather than an error code).
parent 7da032d1
......@@ -1474,6 +1474,7 @@
BEFC32DF1CB53C3B00C8903C /* RefFEltInLocalOperator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BEFC32DC1CB53C3B00C8903C /* RefFEltInLocalOperator.cpp */; };
BEFC32E01CB53C3B00C8903C /* RefFEltInLocalOperator.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BEFC32DD1CB53C3B00C8903C /* RefFEltInLocalOperator.hpp */; };
BEFC32E11CB53C3B00C8903C /* RefFEltInLocalOperator.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BEFC32DE1CB53C3B00C8903C /* RefFEltInLocalOperator.hxx */; };
BEFE4F101CBD23200087DD1F /* PetscMatPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = BEFE4F0F1CBD23200087DD1F /* PetscMatPrivate.h */; };
BEFEEB6F1AFBA1F000C6341E /* libOps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE43AD351AFB9ADB0082AF43 /* libOps.a */; };
BEFEEB7F1AFBA21500C6341E /* libOps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE43AD351AFB9ADB0082AF43 /* libOps.a */; };
BEFEEB821AFBA21E00C6341E /* libOps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE43AD351AFB9ADB0082AF43 /* libOps.a */; };
......@@ -5549,6 +5550,7 @@
BEFC32DC1CB53C3B00C8903C /* RefFEltInLocalOperator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefFEltInLocalOperator.cpp; sourceTree = "<group>"; };
BEFC32DD1CB53C3B00C8903C /* RefFEltInLocalOperator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RefFEltInLocalOperator.hpp; sourceTree = "<group>"; };
BEFC32DE1CB53C3B00C8903C /* RefFEltInLocalOperator.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RefFEltInLocalOperator.hxx; sourceTree = "<group>"; };
BEFE4F0F1CBD23200087DD1F /* PetscMatPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PetscMatPrivate.h; sourceTree = "<group>"; };
BEFF48FC1859C519005BB48A /* TestInputOutputMesh */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestInputOutputMesh; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
 
......@@ -9349,6 +9351,7 @@
isa = PBXGroup;
children = (
BEC1FC7118C470C500A4EB89 /* PetscMat.hpp */,
BEFE4F0F1CBD23200087DD1F /* PetscMatPrivate.h */,
BEC1FC7218C470C500A4EB89 /* PetscSnes.hpp */,
BEC1FC7318C470C500A4EB89 /* PetscSys.hpp */,
BEC1FC7418C470C500A4EB89 /* PetscVec.hpp */,
......@@ -10667,6 +10670,7 @@
BE90E1D21A2492AA00CCAFDE /* Seldon.hpp in Headers */,
BE5674191C722F3F00B2BBAD /* VariationalFormulation.hxx in Headers */,
BE90E1B31A24929A00CCAFDE /* AccessVectorContent.hpp in Headers */,
BEFE4F101CBD23200087DD1F /* PetscMatPrivate.h in Headers */,
BE90E1CA1A2492AA00CCAFDE /* Parmetis.hpp in Headers */,
BE6E4EE21B2ABE8B0049BB2D /* AccessGhostContent.hpp in Headers */,
BE1E87631B8DFB710002EE64 /* PrepareDefaultEntry.hpp in Headers */,
//! \file
//
//
// Petsc.hpp
// HappyHeart
//
// Created by Sébastien Gilles on 11/10/13.
// Copyright (c) 2013 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_INCLUDE_WITHOUT_WARNING_x_PETSC_x_PETSC_MAT_PRIVATE_H_
# define HAPPY_HEART_x_THIRD_PARTY_x_INCLUDE_WITHOUT_WARNING_x_PETSC_x_PETSC_MAT_PRIVATE_H_
# include "Utilities/Pragma/Pragma.hpp"
PRAGMA_DIAGNOSTIC(push)
PRAGMA_DIAGNOSTIC(ignored "-Wsign-conversion")
PRAGMA_DIAGNOSTIC(ignored "-Wfloat-equal")
PRAGMA_DIAGNOSTIC(ignored "-Wold-style-cast")
PRAGMA_DIAGNOSTIC(ignored "-Wunused-parameter")
# ifdef __clang__
PRAGMA_DIAGNOSTIC(ignored "-Wreserved-id-macro")
# endif // __clang__
#ifdef HAPPY_HEART_GCC
PRAGMA_DIAGNOSTIC(ignored "-Wcast-qual")
#endif // HAPPY_HEART_GCC
#include "petsc/private/matimpl.h" // to get around MatGetRow() limitations.
PRAGMA_DIAGNOSTIC(pop)
#endif // HAPPY_HEART_x_THIRD_PARTY_x_INCLUDE_WITHOUT_WARNING_x_PETSC_x_PETSC_MAT_PRIVATE_H_
......@@ -11,6 +11,8 @@
#include <cassert>
#include <cmath>
#include "ThirdParty/IncludeWithoutWarning/Petsc/PetscMatPrivate.h"
#include "ThirdParty/Wrappers/Petsc/Matrix/Matrix.hpp"
#include "ThirdParty/Wrappers/Petsc/Matrix/MatrixPattern.hpp"
#include "ThirdParty/Wrappers/Petsc/Vector/Vector.hpp"
......@@ -395,41 +397,74 @@ namespace HappyHeart
void Matrix::GetRow(PetscInt row_index,
std::vector<std::pair<PetscInt, PetscScalar>>& row_content,
std::vector<PetscInt>& row_content_position_list,
std::vector<PetscScalar>& row_content_value_list,
const char* invoking_file, int invoking_line) const
{
assert(row_content.empty());
assert(row_content_position_list.empty());
assert(row_content_value_list.empty());
PetscInt Nnon_zero_cols;
const PetscInt* columns;
const PetscScalar* values;
// Petsc MatGetRow() crashed if row index is not in the interval given below, so I have added
// this very crude test to return nothing in this case.
if (row_index < Internal()->rmap->rstart || row_index > Internal()->rmap->rend)
return;
int error_code = MatGetRow(Internal(),
row_index,
&Nnon_zero_cols,
&columns,
&values);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatGetRow", invoking_file, invoking_line);
const auto size = static_cast<std::size_t>(Nnon_zero_cols);
row_content.resize(size);
row_content_position_list.resize(size);
row_content_value_list.resize(size);
for (auto i = 0ul; i < size; ++i)
row_content[i] = std::make_pair(columns[i], values[i]);
{
row_content_position_list[i] = columns[i];
row_content_value_list[i] = values[i];
}
error_code = MatRestoreRow(Internal(),
row_index,
&Nnon_zero_cols,
&columns,
&values);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatRestoreRow", invoking_file, invoking_line);
}
void Matrix::GetRow(PetscInt row_index,
std::vector<std::pair<PetscInt, PetscScalar>>& row_content,
const char* invoking_file, int invoking_line) const
{
std::vector<PetscInt> row_content_position_list;
std::vector<PetscScalar> row_content_value_list;
GetRow(row_index,
row_content_position_list,
row_content_value_list,
invoking_file, invoking_line);
const auto size = row_content_position_list.size();
assert(size == row_content_value_list.size());
row_content.reserve(size);
for (auto i = 0ul; i < size; ++i)
row_content.emplace_back(std::make_pair(row_content_position_list[i], row_content_value_list[i]));
}
void Matrix::SetFromPetscMat(Mat petsc_matrix)
{
......
......@@ -410,6 +410,28 @@ namespace HappyHeart
* one of the row handled by the current processor.
* \param[in] invoking_file File that invoked the function or class; usually __FILE__.
* \param[in] invoking_line File that invoked the function or class; usually __LINE__.
* \param[out] row_content_position_list Position of the non-zero values in the row.
* \param[out] row_content_value_list Values of non-zero values in the row. This container is the same
* size as \a row_content_position
* \todo At the moment row_content is allocated each time; it might be useful not to do this... But this
* means structure has to be kept for each line of the matrix considered.
*/
void GetRow(PetscInt row_index,
std::vector<PetscInt>& row_content_position_list,
std::vector<PetscScalar>& row_content_value_list,
const char* invoking_file, int invoking_line) const;
/*!
* \brief Get a row for the matrix.
*
* This is a wrapper over MatGetRow; it should be noticed that Petsc people hope this function is
* actually not used...
*
* \param[in] row_index Program-wise index of the row. The row MUST be
* one of the row handled by the current processor.
* \param[in] invoking_file File that invoked the function or class; usually __FILE__.
* \param[in] invoking_line File that invoked the function or class; usually __LINE__.
* \param[out] row_content Key is position of the non-zero values, value the actual value.
* \todo At the moment row_content is allocated each time; it might be useful not to do this... But this
* means structure has to be kept for each line of the matrix considered.
......@@ -419,6 +441,7 @@ namespace HappyHeart
const char* invoking_file, int invoking_line) const;
/*!
* \brief Wrapper over MatView.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment