On Aug 24, 2009, at 4:19 PM, tsjb00 wrote:
> Hi, there!
>
> I have a quick question on the Fortran interface of
> MatCreateSeqAIJWithArrays.
>
> The documentation indicates 'The i and j indices are 0 based'.
This means the values in i and j start with zero; it does not mean
you have to declare them as PetscInt i(0:a big number) you can declare
them either as
(0:a big number minus 1) or (1:a big number)
> Is it so when called in Fortran? Should the array be 0 based too?
That does not matter.
> Any precautions to be taken to avoid segmentation error?
This routine does NOT copy the values in the arrays. This means
that the arrays that YOU pass in, i,j,a must exist until you finish
using the matrix. If you allocate them
then don't deallocate them until you destroy the matrix. If you
declare them, for example PetscScalar a(somebignumber) then make sure
this variable does not go out of
scope until the matrix is destroyed.
>
> Another question is about the storage of vector/arrays when using
> Fortran. In the PETSc examples, say a vector X_v is created using
> DACreateXXXVector, then the values are accessed with array X_a using
> DAVecGetArray. To access individual value, the loop is coded as:
> for (k=zs; k<zs+zm; k++) {
> for (j=ys; j<ys+ym; j++) {
> for (i=xs; i<xs+xm; i++) {
> for (idof=0;idof<dof;idof++){
> X_a[k][j][i][idof]=.............
> ...............................................
> &nb sp; }
> }
> }
> }
> If in Fortran, how should the loop be structured? Please check if
> the following is right.
> do k=zs,zs+zm
> do j=ys,ys+ym
> do i=xs,xs+xm
> do iof=1,dof
> X_a(iof,i,j,k)=..............
> enddo
> .............
Yes.
Barry
>
>
> Many thanks in advance!
> ????? Windows Live Messenger ???????? ?????