![]() ![]() 4 ) PetscCallA ( VecDestroy ( x, ierr )) PetscCallA ( VecDestroy ( y, ierr )) PetscCallA ( VecDestroy ( w, ierr )) PetscCallA ( PetscFinalize ( ierr )) end !/*TEST ! ! test: ! !TEST*/ 4 ) PetscCallA ( VecAXPY ( y, three, x, ierr )) PetscCallA ( VecNorm ( y, NORM_2, norm, ierr )) write ( 6, 130 ) norm 130 format ( 'Result of axpy ', f10. 4 ) PetscCallA ( VecCopy ( x, w, ierr )) PetscCallA ( VecNorm ( w, NORM_2, norm, ierr )) write ( 6, 120 ) norm 120 format ( 'Result of copy ', f10. 4 ) PetscCallA ( VecScale ( x, two, ierr )) PetscCallA ( VecNorm ( x, NORM_2, norm, ierr )) write ( 6, 110 ) norm 110 format ( 'Result of scaling ', f10. ! PetscInt n PetscErrorCode ierr PetscBool flg PetscScalar one, two, three, dot PetscReal norm, rdot Vec x, y, w PetscOptions options n = 20 one = 1.0 two = 2.0 three = 3.0 PetscCallA ( PetscInitialize ( ierr )) PetscCallA ( PetscOptionsCreate ( options, ierr )) PetscCallA ( PetscOptionsGetInt ( options, PETSC_NULL_CHARACTER, '-n', n, flg, ierr )) PetscCallA ( PetscOptionsDestroy ( options, ierr )) ! Create a vector, then duplicate it PetscCallA ( VecCreate ( PETSC_COMM_WORLD, x, ierr )) PetscCallA ( VecSetSizes ( x, PETSC_DECIDE, n, ierr )) PetscCallA ( VecSetFromOptions ( x, ierr )) PetscCallA ( VecDuplicate ( x, y, ierr )) PetscCallA ( VecDuplicate ( x, w, ierr )) PetscCallA ( VecSet ( x, one, ierr )) PetscCallA ( VecSet ( y, two, ierr )) PetscCallA ( VecDot ( x, y, dot, ierr )) rdot = PetscRealPart ( dot ) write ( 6, 100 ) rdot 100 format ( 'Result of inner product ', f10. ! ! program main #include use petscvec implicit none ! ! This example demonstrates basic use of the PETSc Fortran interface ! to vectors. #SIMPLY FORTRAN TUTORIAL MANUAL#The following Fortran routines differ slightly from their CĬounterparts see the manual pages and previous discussion in this Routines with Different Fortran Interfaces # See Writing C/C++ or Fortran Applications. Test is assumed to be written in Fortran. Likewise, if it is called from Fortran, the KSPSetConvergenceTest() is called from C, the test argument isĪssumed to be a C function. Pointer references a routine written in the same language as the PETSc Such as the test in KSPSetConvergenceTest(), it is assumed that this When a function pointer is passed as an argument to a PETSc function, Routines, such as MatSetValues() and VecSetValues(), always use Regardless of whether C or Fortran is being used. call VecDestroyVecs ( 2, v_new, ierr ) Matrix, Vector and IS Indices #Īll matrices, vectors and IS in PETSc use zero-based indexing, call VecDuplicateVecs ( v_old, 2, v_new, ierr ) alpha = 4.3 call VecSet ( v_new ( 1 ), alpha, ierr ) alpha = 6.0 call VecSet ( v_new ( 2 ), alpha, ierr ). ![]() Vec v_old, v_new ( 2 ) PetscInt ierr PetscScalar alpha. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |