<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, 30 Nov 2018 at 14:50, RAELI ALICE via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi All,<br>My team is working on a PETSC version of an existent code.<br>In order to convert the main part of this work retaining the c++ levels of abstraction,<br><div>we would access to c++ vector data structures easily.</div><div><br></div><div>We would like to use the memory area allocated using c++ as a Petsc Vector<br></div><div><br></div><div>a supposed pseudocode could be:</div><div><i><br></i></div><i>int data[] = { 1,2,3,4,5,6,7,8,9 };<br></i></div></blockquote><div><br></div><div>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.</div><div><br></div><div>A PETSc Vec object can ONLY represent PetscScalar data types.</div><div><br></div><div>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.</div><div><br></div><div>Thanks,</div><div> Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><i>unsigned int sizeVectorPetsC = data.size();<br><b>Vec v(data, sizeVectorPetsC); (Can it exists with easy access petsc routines?)</b><br></i><div><i>cout<< "The mapped vector v is: [";</i></div><div><i> PetscScalar *vecArray;<br></i></div><i>PetscGetArray(v, &array);<br>for (unsigned int i = 0; i < sizeVectorPetsC; i++)<br>{<br><u><b>Informations of v are the informations of data.(same memory read by both data structures)</b></u><br>}<br>PetscRestoreArray(v,&array);<br></i><div><i>
cout<< "]"<< endl;</i></div><div><i><br></i></div><div><i><br></i></div><div>Is it provided this kind of duality between c++ and Petsc objects without a re-copy of the concerned informations?</div><div><br></div><div>Thank you,</div><div>Alice <br><i></i></div></div>
</blockquote></div></div>