fortran basic code
Barry Smith
bsmith at mcs.anl.gov
Tue Mar 3 15:11:17 CST 2009
On Mar 3, 2009, at 2:51 PM, Damian Kaleta wrote:
> Hi
>
> I have a hard time implementing very simple program using fortran.
> The same code works perfectly for me in C.
>
> Here is a source code:
>
> program main
> implicit none
>
>
> #include "/home/damian/petsc-2.3.3-p15/include/finclude/petsc.h"
> #include "/home/damian/petsc-2.3.3-p15/include/finclude/petscpc.h"
> #include "/home/damian/petsc-2.3.3-p15/include/finclude/petscsys.h"
> #include "/home/damian/petsc-2.3.3-p15/include/finclude/petscvec.h"
> #include "/home/damian/petsc-2.3.3-p15/include/finclude/petscmat.h"
>
>
> PetscErrorCode::pierr
> Mat::zpastp
> PetscInt::s
^^^^^^^^^^
>
>
> s=3
>
> call PetscInitialize(PETSC_NULL_CHARACTER,pierr)
> call MatCreateSeqAIJ(PETSC_COMM_SELF, 10, 10, 1, PETSC_NULL_INTEGER,
> zpastp, pierr)
>
> call MatSetValue(zpastp, 2, 2, s, INSERT_VALUES,pierr)
^^^^^^^^^^^^
You are passing an integer in where a double is expected. Change
PetscInt::s to PetscScalar::s
and it will work
Or, do the smart thing and stick to C :-)
Barry
>
>
> call MatAssemblyBegin(zpastp,MAT_FINAL_ASSEMBLY,pierr)
> call MatAssemblyEnd(zpastp,MAT_FINAL_ASSEMBLY,pierr)
>
> call MatView(zpastp, PETSC_VIEWER_STDOUT_SELF, pierr)
> call MatDestroy(zpastp,pierr)
> call PetscFinalize(pierr)
>
> end
>
>
> and the result:
> [damian at utcem001 pet]$ ./ex4f
> row 0:
> row 1:
> row 2: (2, 1.4822e-323)
> row 3:
> row 4:
> row 5:
> row 6:
> row 7:
> row 8:
> row 9:
>
> why don't I get 3 ? But some number close to zero ? I build PETSc to
> use integers.
>
>
> Thanks,
> Damian
More information about the petsc-users
mailing list