[petsc-users] Use of DMDAVecGetArrayF90 and DMDAVecRestoreArrayF90

TAY wee-beng zonexo at gmail.com
Sat Nov 21 07:47:33 CST 2015


On 10/11/2015 8:47 PM, Matthew Knepley wrote:
> On Tue, Nov 10, 2015 at 6:30 AM, TAY wee-beng <zonexo at gmail.com 
> <mailto:zonexo at gmail.com>> wrote:
>
>
>     On 10/11/2015 8:27 PM, Matthew Knepley wrote:
>>     On Tue, Nov 10, 2015 at 3:27 AM, TAY wee-beng <zonexo at gmail.com
>>     <mailto:zonexo at gmail.com>> wrote:
>>
>>         Hi,
>>
>>         Inside my subroutine, I need to access the DA variable
>>         cu_types_array frequently.
>>
>>         So I need to call DMDAVecGetArrayF90 and
>>         DMDAVecRestoreArrayF90 before and after frequently.
>>
>>         Is this necessary? Can I call DMDAVecGetArrayF90 at the start
>>         and only call DMDAVecRestoreArrayF90 towards the end, where I
>>         don't need to modify the values of cu_types_array anymore?
>>
>>         Will this cause memory corruption?
>>
>>
>>     You cannot use any other vector operations before you have called
>>     Restore.
>
>     Hi,
>
>     What do you mean by vector operations? I will just be doing some
>     maths operation to change the values in cu_types_array. Is that fine?
>
>
> While you have the array, no other operation can change the values.
Hi,

Let me clarify this. I declare in this way:

DM  da_cu_types

Vec cu_types_local,cu_types_global

PetscScalar,pointer :: cu_types_array(:,:,:)

call 
DMDACreate3d(MPI_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,(end_ijk_uniform(1) 
- sta_ijk_uniform(1) + 1),(end_ijk_uniform(2) - sta_ijk_uniform(2) + 1),&

(end_ijk_uniform(3) - sta_ijk_uniform(3) + 
1),PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,stencil_width_IIB,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,da_cu_types,ierr)

call DMCreateGlobalVector(da_cu_types,cu_types_global,ierr)

call DMCreateLocalVector(da_cu_types,cu_types_local,ierr)

So when I need to change the values in DA variable cu_types, I call:

call DMDAVecGetArrayF90(da_cu_types,cu_types_local,cu_types_array,ierr)

.... math operations, changing the values of cu_types_array, such as:

cu_types_array = 0.d0

call DMDAVecRestoreArrayF90(da_cu_types,cu_types_local,cu_types_array,ierr)

1st of all, does these DMDAVecGetArrayF90 and DMDAVecRestoreArrayF90 
take a lot of time, especially if I call them many times.

Next qn is whether if I can call DMDAVecGetArrayF90 at the start, and 
DMDAVecRestoreArrayF90 after operations similar to the one above is 
finished.

Thanks.
>
>    Matt
>
>>         Also, must the array be restored using DMDAVecRestoreArrayF90
>>         before calling DMLocalToLocalBegin,DMLocalToLocalEnd?
>>
>>
>>     Yes.
>>
>>       Matt
>>
>>
>>         -- 
>>         Thank you.
>>
>>         Yours sincerely,
>>
>>         TAY wee-beng
>>
>>
>>
>>
>>     -- 
>>     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/20151121/dd7a0ce0/attachment.html>


More information about the petsc-users mailing list