[petsc-users] Vec is locked read only

Matthew Knepley knepley at gmail.com
Sat Apr 2 08:08:11 CDT 2016


On Sat, Apr 2, 2016 at 8:03 AM, Rongliang Chen <rl.chen at siat.ac.cn> wrote:

> Hi Matt,
>
> Many thanks for your helps. I will change the way that I used for the
> boundary condition setup.
>

I will note that we (Barry, Jed, Mark, and I at least) have adopted the
view that by and large

  a) global vectors are for solvers

  b) local vectors are for assembly

For me, that means local vectors have ghost values and boundary conditions,
but global vectors
have them removed. This is how SNES ex12 and ex62 are organized.

  Thanks,

     Matt


> Best regards,
> Rongliang
>
>
>
> On 04/02/2016 08:49 PM, Matthew Knepley wrote:
>
> On Sat, Apr 2, 2016 at 7:46 AM, Rongliang Chen <rl.chen at siat.ac.cn> wrote:
>
>> But I need to setup the boundary conditions for the solution vector X,
>> which is in FormMassTimeStep().
>>
>
> Make a copy. The solution vector is used in the solver, and you have no
> idea exactly what it is doing with it.
> Or put your boundary conditions in the initial guess to SNESSolve().
>
>    Matt
>
>
>> Best regards,
>> Rongliang
>>
>>
>> On 04/02/2016 08:37 PM, Matthew Knepley wrote:
>>
>> On Sat, Apr 2, 2016 at 7:37 AM, Rongliang Chen <rl.chen at siat.ac.cn>
>> wrote:
>>
>>> Hi Matt,
>>>
>>> How to check in the explicit method? This kind of errors does come out
>>> in the explicit method.
>>>
>>
>> You said "that is I use the explicit method with the same function
>> FormMassTimeStep(), this error disappeared"
>>
>>
>>> What do you mean "You should never be changing the input guess"? Do you
>>> mean that the value of the solution vector X in FormFunction are not
>>> allowed to be changed by the user defined function?
>>>
>>
>> Yes.
>>
>>    Matt
>>
>>
>>> Best regards,
>>> Rongliang
>>>
>>> On 04/02/2016 08:19 PM, Matthew Knepley wrote:
>>>
>>> On Sat, Apr 2, 2016 at 7:15 AM, Rongliang Chen <rl.chen at siat.ac.cn>
>>> wrote:
>>>
>>>> Hi Matt,
>>>>
>>>> That's right. The FormMassTimeStep() is inside the FormFunction() and I
>>>> call the FormFunction() in this way: SNESSetFunction(user->snes,
>>>> algebra->f, FormFunction, (void*)user). How can I know the X is read-only
>>>> or not?
>>>>
>>>
>>> Exactly that you get this error message, and it should be in the
>>> documentation.
>>>
>>>
>>>> If I do not use the SNESSolve, that is I use the explicit method with
>>>> the same function FormMassTimeStep(), this error disappeared. So it seems
>>>> that the SNESSolve locked the vector X.
>>>>
>>>
>>> Then we need to put that check in the explicit method as well. You
>>> should never be changing the input guess.
>>>
>>>   Thanks,
>>>
>>>     Matt
>>>
>>>
>>>> Best regards,
>>>> Rongliang
>>>>
>>>> On 04/02/2016 07:59 PM, Matthew Knepley wrote:
>>>>
>>>> On Sat, Apr 2, 2016 at 6:49 AM, Rongliang Chen <rl.chen at siat.ac.cn>
>>>> wrote:
>>>>
>>>>> Hi Dave,
>>>>>
>>>>> I did not call any VecGetArrary and VecGetArraryRead in function
>>>>> FormMassTimeStepFunction().
>>>>>
>>>>
>>>> It looks like you have a function FormMassTimeStep() inside your
>>>> FormFunction() method. This
>>>> has an argument X, the solution guess, which is read-only. However, you
>>>> are calling DMLocalToGlobal()
>>>> using that X, which is illegal, since its read-only. Is this right?
>>>>
>>>>    Matt
>>>>
>>>>
>>>>> Best regards,
>>>>> Rongliang
>>>>>
>>>>> On 04/02/2016 06:20 PM, Dave May wrote:
>>>>>
>>>>>
>>>>>
>>>>> On 2 April 2016 at 11:18, Rongliang Chen <rl.chen at siat.ac.cn> wrote:
>>>>>
>>>>>> Hi Shri,
>>>>>>
>>>>>> Thanks for your reply.
>>>>>>
>>>>>> Do you mean that I need to change the VecGetArrary() in
>>>>>> /home/rlchen/soft/petsc-3.6.3/src/dm/interface/dm.c to VecGetArrayRead()?
>>>>>>
>>>>>
>>>>> No - you should change it in your function FormMassTimeStepFunction().
>>>>> The input vector x passed into SNESComputeFunction() is read only.
>>>>>
>>>>>
>>>>>
>>>>>> I tried it and I got a warning when I make the petsc:
>>>>>>
>>>>>> /home/rlchen/soft/petsc-3.6.3/src/dm/interface/dm.c: In function
>>>>>> ‘DMLocalToGlobalBegin’:
>>>>>> /home/rlchen/soft/petsc-3.6.3/src/dm/interface/dm.c:1913:5: warning:
>>>>>> passing argument 2 of ‘VecGetArrayRead’ from incompatible pointer type
>>>>>> [enabled by default]
>>>>>> In file included from
>>>>>> /home/rlchen/soft/petsc-3.6.3/include/petscmat.h:6:0,
>>>>>> from /home/rlchen/soft/petsc-3.6.3/include/petscdm.h:6,
>>>>>> from /home/rlchen/soft/petsc-3.6.3/include/petsc/private/dmimpl.h:6,
>>>>>> from /home/rlchen/soft/petsc-3.6.3/src/dm/interface/dm.c:1:
>>>>>> /home/rlchen/soft/petsc-3.6.3/include/petscvec.h:420:29: note:
>>>>>> expected ‘const PetscScalar **’ but argument is of type ‘PetscScalar **’
>>>>>>
>>>>>> Best regards,
>>>>>> Rongliang
>>>>>>
>>>>>> ---------------------
>>>>>> Rongliang Chen,   PhD
>>>>>> Associate Professor
>>>>>>
>>>>>> Laboratory for Engineering and Scientific Computing
>>>>>> Shenzhen Institutes of Advanced Technology
>>>>>> Chinese Academy of Sciences
>>>>>> Address: 1068 Xueyuan Avenue, Shenzhen University Town, Shenzhen,
>>>>>> Guangdong (518055), P. R. China
>>>>>> E-mail:  rl.chen at siat.ac.cn
>>>>>> Phone: +86-755-86392312
>>>>>>
>>>>>>
>>>>>> On 04/02/2016 05:03 PM, Abhyankar, Shrirang G. wrote:
>>>>>>
>>>>>>> Use VecGetArrayRead instead of VecGetArray
>>>>>>>
>>>>>>>
>>>>>>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray
>>>>>>> Read.html
>>>>>>>
>>>>>>>
>>>>>>> Shri
>>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Rongliang Chen <rl.chen at siat.ac.cn>
>>>>>>> Date: Saturday, April 2, 2016 at 3:51 AM
>>>>>>> To: PETSc users list <petsc-users at mcs.anl.gov>, "
>>>>>>> rongliang.chan at gmail.com"
>>>>>>> <rongliang.chan at gmail.com>
>>>>>>> Subject: [petsc-users] Vec is locked read only
>>>>>>>
>>>>>>> Dear All,
>>>>>>>>
>>>>>>>> My code got the following error messages, but the code works well
>>>>>>>> for
>>>>>>>> the petsc optimized version (--with-debugging=0). Anyone can tell
>>>>>>>> me how
>>>>>>>> to fix this problem?
>>>>>>>>
>>>>>>>> Best regards,
>>>>>>>> Rongliang
>>>>>>>>
>>>>>>>>
>>>>>>>> [0]PETSC ERROR: --------------------- Error Message
>>>>>>>> --------------------------------------------------------------
>>>>>>>> [0]PETSC ERROR: Object is in wrong state
>>>>>>>> [0]PETSC ERROR:  Vec is locked read only, argument # 1
>>>>>>>> [0]PETSC ERROR: See
>>>>>>>> http://www.mcs.anl.gov/petsc/documentation/faq.html
>>>>>>>> for trouble shooting.
>>>>>>>> [0]PETSC ERROR: Petsc Release Version 3.6.3, Dec, 03, 2015
>>>>>>>> [0]PETSC ERROR: ./Nwtun on a 64bit-debug named rlchen by rlchen Sat
>>>>>>>> Apr
>>>>>>>> 2 15:40:32 2016
>>>>>>>> [0]PETSC ERROR: Configure options --download-blacs
>>>>>>>> --download-scalapack
>>>>>>>> --download-metis --download-parmetis --download-exodusii
>>>>>>>> --download-netcdf --download-hdf5
>>>>>>>> --with-mpi-dir=/home/rlchen/soft/Program/mpich2-shared
>>>>>>>> --with-debugging=1 --download-fblaslapack --download-chaco
>>>>>>>> [0]PETSC ERROR: #1 VecGetArray() line 1646 in
>>>>>>>> /home/rlchen/soft/petsc-3.6.3/src/vec/vec/interface/rvector.c
>>>>>>>> [0]PETSC ERROR: #2 DMLocalToGlobalBegin() line 1913 in
>>>>>>>> /home/rlchen/soft/petsc-3.6.3/src/dm/interface/dm.c
>>>>>>>> [0]PETSC ERROR: #3 FormMassTimeStepFunction() line 191 in
>>>>>>>>
>>>>>>>> /home/rlchen/soft/3D_fluid/FiniteVolumeMethod/PETScCodes/codefor3.6/SetupF
>>>>>>>> unctions.c
>>>>>>>> [0]PETSC ERROR: #4 FormFunction() line 46 in
>>>>>>>>
>>>>>>>> /home/rlchen/soft/3D_fluid/FiniteVolumeMethod/PETScCodes/codefor3.6/SetupF
>>>>>>>> unctions.c
>>>>>>>> [0]PETSC ERROR: #5 SNESComputeFunction() line 2067 in
>>>>>>>> /home/rlchen/soft/petsc-3.6.3/src/snes/interface/snes.c
>>>>>>>> [0]PETSC ERROR: #6 SNESSolve_NEWTONLS() line 184 in
>>>>>>>> /home/rlchen/soft/petsc-3.6.3/src/snes/impls/ls/ls.c
>>>>>>>> [0]PETSC ERROR: #7 SNESSolve() line 3906 in
>>>>>>>> /home/rlchen/soft/petsc-3.6.3/src/snes/interface/snes.c
>>>>>>>> [0]PETSC ERROR: #8 SolveTimeDependent() line 843 in
>>>>>>>>
>>>>>>>> /home/rlchen/soft/3D_fluid/FiniteVolumeMethod/PETScCodes/codefor3.6/Nwtun.
>>>>>>>> c
>>>>>>>> [0]PETSC ERROR: #9 main() line 452 in
>>>>>>>>
>>>>>>>> /home/rlchen/soft/3D_fluid/FiniteVolumeMethod/PETScCodes/codefor3.6/Nwtun.
>>>>>>>> c
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> What most experimenters take for granted before they begin their
>>>> experiments is infinitely more interesting than any results to which their
>>>> experiments lead.
>>>> -- Norbert Wiener
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> What most experimenters take for granted before they begin their
>>> experiments is infinitely more interesting than any results to which their
>>> experiments lead.
>>> -- Norbert Wiener
>>>
>>>
>>>
>>
>>
>> --
>> What most experimenters take for granted before they begin their
>> experiments is infinitely more interesting than any results to which their
>> experiments lead.
>> -- Norbert Wiener
>>
>>
>>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160402/08971d7b/attachment-0001.html>


More information about the petsc-users mailing list