[petsc-users] PETSC address vector c++ access

Dave May dave.mayhem23 at gmail.com
Fri Nov 30 13:40:34 CST 2018


On Fri, 30 Nov 2018 at 14:50, RAELI ALICE via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Hi All,
> My team is working on a PETSC version of an existent code.
> In order to convert the main part of this work retaining the c++ levels of
> abstraction,
> we would access to c++ vector data structures easily.
>
> We would like to use the memory area allocated using c++ as a Petsc Vector
>
> a supposed pseudocode could be:
>
>
> *int data[] = { 1,2,3,4,5,6,7,8,9 };*
>

To avoid any confusion (or disappointment) later, I want to point out that
your pseudo code is wrong (specifically the line above) and in detail would
result in a SEGV.

A PETSc Vec object can ONLY represent PetscScalar data types.

It may well have been a typo on your part, but I think it's important to
emphasise that the Vec object does not try to mimic a C++ template with the
data type as an argument.

Thanks,
  Dave


>
>
> *unsigned int sizeVectorPetsC = data.size();Vec v(data, sizeVectorPetsC);
> (Can it exists with easy access petsc routines?)*
> *cout<< "The mapped vector v is: [";*
>
> *    PetscScalar *vecArray;*
>
>
>
>
>
>
> *PetscGetArray(v, &array);for (unsigned int i = 0; i < sizeVectorPetsC;
> i++){Informations of v are the informations of data.(same memory read by
> both data structures)}PetscRestoreArray(v,&array);*
> * cout<< "]"<< endl;*
>
>
> Is it provided this kind of duality between c++ and Petsc objects without
> a re-copy of the concerned informations?
>
> Thank you,
> Alice
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181130/c8db4a7e/attachment.html>


More information about the petsc-users mailing list