Thank you so much Matt and Dave,
we will test soon. I think they are what we were searching for.

Alice

On Fri, 30 Nov 2018 19:40:34 +0000
 Dave May <[email protected]> wrote:
On Fri, 30 Nov 2018 at 14:50, RAELI ALICE via petsc-users <
[email protected]> 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

Yes, I think you want

 
https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecCreateSeqWithArray.html
 
https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecCreateMPIWithArray.html#VecCreateMPIWithArray

and you can even do advanced things with the storage

 
https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecPlaceArray.html#VecPlaceArray

but you need to be more careful.

Let me know if this does not do what you wanted.

 Thanks,

    Matt


  Thank you,
Alice

Reply via email to