[petsc-dev] using typedef for each different memory space the variable lives in
Jed Brown
jed at jedbrown.org
Sat Dec 12 15:33:17 CST 2020
Barry Smith <bsmith at petsc.dev> writes:
> Yes, it is generally for arrays, but also makes sense for local variables inside a kernel; just makes the code clearer. For example
>
> Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(0,nx), KOKKOS_LAMBDA (const PetscInt &i)
> {
> PetscKokkosReal uvleft = eval(U,0, i, 1, .5);
> PetscKokkosReal uvright = eval(U,0, i+1, 1, -.5);
> PetscKokkosReal uwleft = eval(U,1, i, 1, .5);
> PetscKokkosReal uwright = eval(U,1, i+1, 1, -.5);
> flux(0,i, 1) = -.5*(uwleft+uwright)+.5*alpha_LF*(uvleft-uvright);
> flux(1,i, 1) = -.5*(uvleft+uvright)+.5*alpha_LF*(uwleft-uwright);
> });
>
> vs
>
> Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(0,nx), KOKKOS_LAMBDA (const PetscInt &i)
> {
> PetscReal uvleft = eval(U,0, i, 1, .5);
> PetscReal uvright = eval(U,0, i+1, 1, -.5);
> PetscReal uwleft = eval(U,1, i, 1, .5);
> PetscReal uwright = eval(U,1, i+1, 1, -.5);
> flux(0,i, 1) = -.5*(uwleft+uwright)+.5*alpha_LF*(uvleft-uvright);
> flux(1,i, 1) = -.5*(uvleft+uvright)+.5*alpha_LF*(uwleft-uwright);
> });
I don't see the benefit in this context.
> I don't think there is need for conversion between PetscKokkosReal and PetscReal. One uses the normal code for moving data between the memory spaces.
> It is different than PetscInt and PetscBLASInt.
Fine for values, but you can't just convert between device and host pointers (without unified memory and a potential performance hit).
More information about the petsc-dev
mailing list