Re: [petsc-users] Correct use of VecGetArray with std::vector

2020-02-28 Thread Victor Eijkhout
On , 2020Feb28, at 14:14, Jed Brown mailto:jed.br...@colorado.edu>> wrote: Can't do this because std::vector can't be wrapped around existing memory. That’s why I use gsl::span which ?will be in c++20? Victor.

Re: [petsc-users] Correct use of VecGetArray with std::vector

2020-02-28 Thread Jed Brown
Matthew Knepley writes: > On Fri, Feb 28, 2020 at 2:12 PM Zane Charles Jakobs < > zane.jak...@colorado.edu> wrote: > >> Hi PETSc devs, >> >> I'm writing some C++ code that calls PETSc, and I'd like to be able to >> place the result of VecGetArray into an std::vector and then later call >>

Re: [petsc-users] Correct use of VecGetArray with std::vector

2020-02-28 Thread Junchao Zhang via petsc-users
You can create the C++ vector vals and resize it to a proper size, get its data pointer, then pass it to PETSc, int n; Vec x; std::vector vals; vals.resize(n); /* You need to calculate n by other means */ ierr = VecCreateMPIWithArray(PETSC_COMM_WORLD,bs,n,PETSC_DECIDE,vals.data(),);CHKERRQ(ierr);

Re: [petsc-users] Correct use of VecGetArray with std::vector

2020-02-28 Thread Matthew Knepley
On Fri, Feb 28, 2020 at 2:12 PM Zane Charles Jakobs < zane.jak...@colorado.edu> wrote: > Hi PETSc devs, > > I'm writing some C++ code that calls PETSc, and I'd like to be able to > place the result of VecGetArray into an std::vector and then later call > VecRestoreArray on that data, or get the

[petsc-users] Correct use of VecGetArray with std::vector

2020-02-28 Thread Zane Charles Jakobs
Hi PETSc devs, I'm writing some C++ code that calls PETSc, and I'd like to be able to place the result of VecGetArray into an std::vector and then later call VecRestoreArray on that data, or get the same effects. It seems like the correct way to do this would be something like: Vec x;