<div dir="ltr">Ok, let me try to clarify a little bit,<div><br></div><div>I have a u0 3d array with the mentioned indices (starting from -1), im creating a dmda with the sizes in the constructor, no problem with that.</div><div><br></div><div>Next, im trying to distribute this u0 array into global and local vectors, apparently i can do that since no error comes out. </div><div><br></div><div>Now, when i get the array back with VecGetArrayF90(), the indices start now from 0, is that right? so the whole array have been shifted in its indices.</div><div><br></div><div>This changes things for me because my idea was to use the previous serial code to operate on the arrays, but this is written with indices starting from -1. There are dozens of arrays with the same structure, but they also operate with other arrays with indices starting from 1, at the same time, usually in triple nested loops which code the stencil used within them, to update and correct the velocities after solving for pressure, per example.</div><div><br></div><div>So it would be much easier to shift the indices of these arrays by one, rather than changing all the code to match the new indices starting from zero,</div><div><br></div><div>Is there a way to do this?</div><div><br></div><div>Thanks,</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 4, 2017 at 5:46 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
For DMDAVecGetArrayF90 you need to declare the "array" arguments as Fortran pointers you don't declare them like<br>
<br>
> u0(-1:IMax+2,-1:JMax+1,-1:<wbr>KMax+1)<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> On Feb 4, 2017, at 7:34 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
><br>
> On Sat, Feb 4, 2017 at 7:30 PM, Manuel Valera <<a href="mailto:mvalera@mail.sdsu.edu">mvalera@mail.sdsu.edu</a>> wrote:<br>
> Thanks, that helped a lot,<br>
><br>
> Now im a little confused with my next error, in my serial code i have several arrays with dimensions declared as:<br>
><br>
> u0(-1:IMax+2,-1:JMax+1,-1:<wbr>KMax+1)<br>
><br>
> and i create my DMDA for this array as:<br>
><br>
> call CDA3(daub,IMax+4,JMax+3,KMax+<wbr>3)<br>
> call DAs(daub,u0p,u0pl,u0)<br>
><br>
> With the subroutines as:<br>
><br>
> SUBROUTINE CDA3(da3d,dim3dx,dim3dy,<wbr>dim3dz)<br>
><br>
><br>
><br>
> DM, intent(inout) :: da3d<br>
> PetscInt, intent(in) :: dim3dx,dim3dy,dim3dz<br>
> DMBoundaryType :: bx,by,bz<br>
><br>
><br>
> bx = DM_BOUNDARY_NONE<br>
> by = DM_BOUNDARY_NONE<br>
> bz = DM_BOUNDARY_NONE<br>
><br>
> call DMDACreate3d(PETSC_COMM_WORLD,<wbr>bx,by,bz,DMDA_STENCIL_BOX,<wbr>dim3dx,dim3dy,dim3dz,PETSC_<wbr>DECIDE,PETSC_DECIDE,PETSC_<wbr>DECIDE,1,1,PETSC_NULL_INTEGER,<wbr>PETSC_NULL_INTEGER,PETSC_NULL_<wbr>INTEGER,da3d,ierr)<br>
><br>
> call DMSetFromOptions(da3d,ierr)<br>
> call DMSetUp(da3d,ierr)<br>
><br>
><br>
> END SUBROUTINE CDA3<br>
><br>
> SUBROUTINE DAs(da,globalv,localv,array)<br>
><br>
> ! use PetscObjects, only :: ierr<br>
><br>
><br>
> ! Umbrella program to update and communicate the arrays in a<br>
> ! distributed fashion using the DMDA objects from PETSc.<br>
> ! Manuel Valera 1/20/17<br>
><br>
> ! Arguments:<br>
> ! da = DMDA array either 1d,2d or 3d, already created and setup<br>
> ! globalv = global vector to be operated into<br>
> ! localv = local chunk each processor works in.<br>
> ! array = the array to be petscified. ONLY 3D ARRAYS rn.<br>
> ! just in case.<br>
><br>
> Vec,intent(inout) :: globalv,localv<br>
><br>
><br>
> PetscScalar,dimension(:,:,:) :: array<br>
> DM,intent(inout) :: da<br>
><br>
><br>
><br>
><br>
><br>
><br>
> call DMCreateGlobalVector(da,<wbr>globalv,ierr)<br>
> call DMCreateLocalVector(da,localv,<wbr>ierr)<br>
><br>
> call DMGlobalToLocalBegin(da,<wbr>globalv,INSERT_VALUES,localv,<wbr>ierr)<br>
> call DMGlobalToLocalEnd(da,globalv,<wbr>INSERT_VALUES,localv,ierr)<br>
><br>
><br>
><br>
> END SUBROUTINE DAs<br>
><br>
> Which i later open into an array to operate into it, but when i try to access u0(:,j-2,:) it gives me the following error:<br>
><br>
> Fortran runtime error: Index '-1' of dimension 2 of array 'u0' below lower bound of 0<br>
><br>
> So i'm guessing the DMDA is creating the arrays with dimensions starting at 0 instead of -1 as it should, right? what can be done in this case?<br>
><br>
> 1) The DMDA only takes sizes, not index bounds, in the constructor.<br>
><br>
> 2) Its not the DMDA you must be talking about, but the array you get from DMDAVecGetArrayF90() or VecGetArrayF90()<br>
><br>
> 3) The VecGetArrayF90() always start from 0 since it is indexed in local indices<br>
><br>
> 4) The DMDVecGetArrayF90() arrays are indexed by global indices for the patch your process owns (including ghosts if its a local vector)<br>
><br>
> Thanks,<br>
><br>
> Matt<br>
><br>
> Thanks,<br>
> Manuel<br>
><br>
> On Sat, Feb 4, 2017 at 4:18 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> See: <a href="http://www.mcs.anl.gov/petsc/documentation/changes/dev.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>documentation/changes/dev.html</a> search for DMDACreate and update your code.<br>
><br>
> Barry<br>
><br>
><br>
> > On Feb 4, 2017, at 6:02 PM, Manuel Valera <<a href="mailto:mvalera@mail.sdsu.edu">mvalera@mail.sdsu.edu</a>> wrote:<br>
> ><br>
> > Hello devs,<br>
> ><br>
> > Ive been creating the framework to distribute the arrays from my model using the global/local vectors and the DMDAs, for this i created a small subroutine that is responsible for making the necessary calls:<br>
> ><br>
> > SUBROUTINE DAs(da,globalv,localv)<br>
> ><br>
> > ! use PetscObjects, only :: ierr<br>
> ><br>
> ><br>
> > ! Umbrella program to update and communicate the arrays in a<br>
> > ! distributed fashion using the DMDA objects from PETSc.<br>
> > ! Manuel Valera 1/20/17<br>
> ><br>
> > ! Arguments:<br>
> > ! da = DMDA array either 1d,2d or 3d, already created and setup<br>
> > ! globalv = global vector to be operated into<br>
> > ! localv = local chunk each processor works in.<br>
> ><br>
> ><br>
> ><br>
> > Vec,intent(inout) :: globalv,localv<br>
> ><br>
> ><br>
> ><br>
> > DM,intent(inout) :: da<br>
> ><br>
> > call DMCreateGlobalVector(da,<wbr>globalv,ierr)<br>
> > call DMCreateLocalVector(da,localv,<wbr>ierr)<br>
> ><br>
> > call DMGlobalToLocalBegin(da,<wbr>globalv,INSERT_VALUES,localv,<wbr>ierr)<br>
> > call DMGlobalToLocalEnd(da,globalv,<wbr>INSERT_VALUES,localv,ierr)<br>
> ><br>
> ><br>
> ><br>
> > END SUBROUTINE DAs<br>
> ><br>
> ><br>
> > I call this from another program where i have declared a vector as:<br>
> ><br>
> > #include "petsc/finclude/petscdm.h"<br>
> > #include "petsc/finclude/petscdmda.h"<br>
> ><br>
> > use petsc<br>
> > use petscdm<br>
> > use petscdmda<br>
> ><br>
> > IMPLICIT NONE<br>
> ><br>
> > Vec :: xpdmda,yp,zp,xcp,ycp,zcp<br>
> > DM :: da,dac,dau,dav,daw<br>
> ><br>
> > CONTAINS<br>
> > SUBROUTINE InitGridP<br>
> ><br>
> > IMPLICIT NONE<br>
> > !PetscInt :: ierr<br>
> ><br>
> > ! CREATE DMDA:<br>
> ><br>
> > call CDA3(da,IMax-1,JMax-1,KMax-1)<br>
> ><br>
> > !xpdmda,yp,zp have the same dimensions than x,y,z<br>
> > !xpl,ypl,zpl are the local versions of xp,yp,zp<br>
> ><br>
> > !We create the global and local vectors and communicate their values:<br>
> > call DAs(da,xpdmda,xpl,x)<br>
> ><br>
> > And at this call it crashes with the following message:<br>
> ><br>
> > [0]PETSC ERROR: --------------------- Error Message ------------------------------<wbr>------------------------------<wbr>--<br>
> > [0]PETSC ERROR: Null argument, when expecting valid pointer<br>
> > [0]PETSC ERROR: Null Object: Parameter # 2<br>
> > [0]PETSC ERROR: See<br>
> > <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>documentation/faq.html</a><br>
> > for trouble shooting.<br>
> > [0]PETSC ERROR: Petsc Development GIT revision: v3.7.5-2949-gc3c607c GIT Date: 2017-01-20 17:34:16 -0600<br>
> > [0]PETSC ERROR: ./ucmsLEP on a arch-linux2-c-debug named ocean by valera Sat Feb 4 15:53:53 2017<br>
> > [0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-fblaslapack --download-mpich --download-hdf5 --download-netcdf --download-hypre --download-metis --download-parmetis --download-trillinos --with-debugging=1<br>
> > [0]PETSC ERROR: #3 VecSetLocalToGlobalMapping() line 79 in /usr/dataC/home/valera/petsc/<wbr>src/vec/vec/interface/vector.c<br>
> > [0]PETSC ERROR: #4 DMCreateGlobalVector_DA() line 41 in /usr/dataC/home/valera/petsc/<wbr>src/dm/impls/da/dadist.c<br>
> > [0]PETSC ERROR: #5 DMCreateGlobalVector() line 840 in /usr/dataC/home/valera/petsc/<wbr>src/dm/interface/dm.c<br>
> ><br>
> ><br>
> ><br>
> > So my question is, do i have to setup the vectors in any additional way? i followed the fortran DMDA examples closely and i didnt notice anything extra,<br>
> ><br>
> > Thanks,<br>
> ><br>
> > Manuel<br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
> -- Norbert Wiener<br>
<br>
</div></div></blockquote></div><br></div>