[petsc-users] about Vecgetarray()
Satish Balay
balay at mcs.anl.gov
Sat Apr 17 09:42:16 CDT 2010
As matt mentioned - if you are programming in fortran - you need to
learn fortran.
On Fri, 16 Apr 2010, 陈乐平(Leping Chen) wrote:
> petsc teams,
>
> PetscOffset xx_i
> Vec x
> double precision u(6)
>
> call VecGetArray(x,u,xx_i,ierr)
> do 30 i=1,n
> u(i) = 1000.0*i
This is incorrect usage. Check the examples. It should be:
u(i+xx_i) = 1000.0*i
Or check VecGetArrayF90 as mentioned before.
Satish
> 30 continue
> call VecRestoreArray(x,u,xx_i,ierr)
>
> I don't understand why x cannot be changed when u() has been changed?
> how can I do it?
> the output are as follows,
> x vector:
> 10
> 20
> 30
> 40
> 50
> 60
> u() array
> 1000
> 2000
> 3000
> 4000
> 5000
> 6000
> thanks,
> leping
>
>
>
>
> 发件人: Matthew Knepley
> 发送时间: 2010-04-17 22:15:24
> 收件人: chenleping; PETSc users list
> 抄送:
> 主题: Re: [petsc-users] about Vecgetarray()
> 2010/4/16 陈乐平(Leping Chen) <chenleping at yahoo.cn>
>
> petsc teams,
>
> if I want create the relation between u() [array] and x [Vec] ,I can do it as follows,
>
> #define u(ib) xx_v(xx_i + (ib))
> call VecGetArray(x,xx_v,xx_i,ierr)
> do 30 i=1,n
> u(i) = 1000.0*i
> 30 continue
> call VecRestoreArray(x,xx_v,xx_i,ierr)
>
> However, I don't understand why can not I do it as follows,
>
> double precision u(1) or u(6)
> call VecGetArray(x,u,xx_i,ierr)
> do 30 i=1,n
> u(i) = 1000.0*i
> 30 continue
> call VecRestoreArray(x,u,xx_i,ierr)
>
> Why u() must be created by #define, and u() cannot be defined again,for example "double precision u(1)" or u(5).
>
>
> 1) It does not have to be #define. This is shown for convenience.
>
>
> 2) You must still declare xx_v in your first example, probably exactly as you
> declare u in your second example.
>
>
> These are not PETSc questions. They are basic Fortran programming questions.
> There are many excellent books on this.
>
>
> Matt
>
>
> By the way, if u() is a array of common blocks(fortran), how can I create the relation between u() and x?
>
> thanks,
>
> Leping
>
>
>
> 2010-04-16
>
>
>
>
>
More information about the petsc-users
mailing list