Skip to content

PetscVector not allowing raw array access after read-only operations #3493

@zachmprince

Description

@zachmprince

The following code issues an the subsequent error:

  // Just in case
  petsc_solution->restore_array();

  // Just print the vector using ::operator()
  for (numeric_index_type i = petsc_solution->first_local_index(); i < petsc_solution->last_local_index(); ++i)
    std::cout << "u(" << i << ") = " << (*petsc_solution)(i) << std::endl;

  // Get array
  PetscScalar * petsc_array = petsc_solution->get_array();

  // restore
  petsc_solution->restore_array();
  petsc_solution->close();
libMesh terminating:
PetscVector values were manually retrieved but are being automatically restored!
Stack frames: 18
0: libMesh::print_trace(std::ostream&)
1: libMesh::MacroFunctions::report_error(char const*, int, char const*, char const*, std::ostream&)
2: libMesh::PetscVector<double>::_restore_array() const
3: libMesh::PetscVector<double>::_get_array(bool) const

This operation should be allowed ::operator() should not restricting access to the raw array.

get_array() +should+ error out if:

  • There is another request that hasn't been restored yet
  • Other operations like operator() or set are being used before calling restore_array()

get_array_read() should error if:

  • There is a get_array() that hasn't been restored yet
  • Non-const operations are being performed before it's been restored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions