[petsc-users] Petsc veccuda device to host copy

Wenbo Zhao zhaowenbo.npic at gmail.com
Sun Dec 7 22:03:37 CST 2025


Hi,

we are using petsc's veccuda and found that the data in the host array
obtained via VecGetArrayRead is partially updated sometime.


Vec vgpu, vcpu;

iterations:

     // ksp solve a * vgpu=b

     const PetscScalar * agpu;

      PetscScalar * acpu;

      VecGetArrayRead(vgpu, &agpu);

      VecGetArray(vcpu, &acpu);

      PetscArraycpy (acpu, agpu,size);

      // check updating

      std::cout << agpu[0] << agpu [size-1]<<std::endl;

      //  we found that agpu[0] is last iterations value, agpu[size-1]
updated from device value, randomly

      // use acpu values to  update matrix a ....




Petsc 3.21.1 is used. And manual said,

For vectors that may also have array data in GPU memory, for example,
VECCUDA, this call ensures the CPU array has the most recent array values
by copying the data from the GPU memory if needed.



Best wishes,

Wenbo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20251208/ecc49792/attachment.html>


More information about the petsc-users mailing list