[petsc-users] A compilation error about VecGetValues

Mark Adams mfadams at lbl.gov
Sun May 22 07:40:24 CDT 2022


The last two arguments, other than the error code, to
https://petsc.org/main/docs/manualpages/Vec/VecGetValues/ are arrays not
scalars.
PETSc started emabling type checking after 3.8.

https://petsc.org/main/src/vec/vec/tutorials/ex2f.F.html does this.
This is a terrible example of code. It should be removed.
Why does this example work?
It has 'implicit none'
You might add that to see if that fixes this problem, but this is a
terrible "tutorial".

Mark

On Sun, May 22, 2022 at 12:17 AM wang yuqi <yu1299885905 at outlook.com> wrote:

>
>
>
>
> 从 Windows 版邮件 <https://go.microsoft.com/fwlink/?LinkId=550986>发送
>
> Hi, Dear developer:
>
> I had compilation problems when using VecGetValues. My procedure is as
> follows:
>
> program main
>
> #include <petsc/finclude/petscvec.h>
>
> use petscvec
>
>       Vec     x
>
>       PetscInt N,i,ione
>
>       PetscErrorCode ierr
>
>       PetscMPIInt rank
>
>       PetscScalar  one
>
>
>
>       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
>
>       if (ierr .ne. 0) then
>
>         print*,'PetscInitialize failed'
>
>         stop
>
>       endif
>
>       one   = 1.0
>
>       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
>
>       N = rank + 1
>
>       call VecCreateMPI(PETSC_COMM_WORLD,N,PETSC_DECIDE,x,ierr)
>
>       call VecGetSize(x,N,ierr)
>
>       call VecSet(x,one,ierr)
>
>       ione = 1
>
>       do 100 i=0,N-rank-1
>
>          call VecSetValues(x,ione,i,one,ADD_VALUES,ierr)
>
>  100  continue
>
> call VecAssemblyBegin(x,ierr)
>
>       call VecAssemblyEnd(x,ierr)
>
>
>
>       if (rank .eq. 0) then
>
>         ione = 0
>
>         call VecGetValues(x,ione,i,one,ierr)
>
>       endif
>
>       call VecView(x,PETSC_VIEWER_STDOUT_WORLD,ierr)
>
>       call VecDestroy(x,ierr)
>
>
>
>       call PetscFinalize(ierr)
>
> end PROGRAM main
>
>
>
> The compilation error is as follows:
>
> mpif90  -I/root/soft/petsc/3.8.0/include  -o ex2f.o ex2f.F90
>
> ex2f.F90(62): error #8284: If the actual argument is scalar, the dummy
> argument shall be scalar unless the actual argument is of type character or
> is an element of an array that is not assumed shape, pointer, or
> polymorphic.   [C]
>
>         call VecGetValues(x,ione,i,one,ierr)
>
> -------------^
>
> ex2f.F90(62): error #8284: If the actual argument is scalar, the dummy
> argument shall be scalar unless the actual argument is of type character or
> is an element of an array that is not assumed shape, pointer, or
> polymorphic.   [D]
>
>         call VecGetValues(x,ione,i,one,ierr)
>
> -------------^
>
> compilation aborted for ex2f.F90 (code 1)
>
> And this error only appears when the Petsc version is higher than 3.8.
>
> I look forward to hearing from you.
>
> Thanks!
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220522/076b5a2e/attachment.html>


More information about the petsc-users mailing list