Date: 2025-03-28T21:11:23+00:00

Actual source code: ex11f.F90

      1: !
      2:       program main
      3: #include <petsc/finclude/petscvec.h>
      4:       use petscvec
      5:       implicit none

      7:       Vec               x
      8:       PetscReal         norm
      9:       PetscBool  flg
     10:       PetscMPIInt rank
     11:       PetscInt n,bs,comp
     12:       PetscErrorCode ierr
     13:       PetscScalar       one

     15:       PetscCallA(PetscInitialize(ierr))
     16:       PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr))

     18:       n   = 20
     19:       one = 1.0
     20:       PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr))

     22: !
     23: !     Create a vector, specifying only its global dimension.
     24: !     When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
     25: !     the vector format (currently parallel,
     26: !     shared, or sequential) is determined at runtime.  Also, the parallel
     27: !     partitioning of the vector is determined by PETSc at runtime.

     29:       PetscCallA(VecCreate(PETSC_COMM_WORLD,x,ierr))
     30:       PetscCallA(VecSetSizes(x,PETSC_DECIDE,n,ierr))
     31:       bs = 2
     32:       PetscCallA(VecSetBlockSize(x,bs,ierr))
     33:       PetscCallA(VecSetFromOptions(x,ierr))

     35: !
     36: !     Set the vectors to entries to a constant value.
     37: !
     38:       PetscCallA(VecSet(x,one,ierr))

     40:       PetscCallA(VecNorm(x,NORM_2,norm,ierr))
     41:       if (rank .eq. 0) then
     42:          write (6,100) norm
     43:  100     format ('L_2 Norm of entire vector ',1pe9.2)
     44:       endif

     46:       comp = 0
     47:       PetscCallA(VecStrideNorm(x,comp,NORM_2,norm,ierr))
     48:       if (rank .eq. 0) then
     49:          write (6,200) norm
     50:  200     format ('L_2 Norm of subvector 0',1pe9.2)
     51:       endif

     53:       comp = 1
     54:       PetscCallA(VecStrideNorm(x,comp,NORM_2,norm,ierr))
     55:       if (rank .eq. 0) then
     56:          write (6,300) norm
     57:  300     format ('L_2 Norm of subvector 1',1pe9.2)
     58:       endif

     60:       PetscCallA(VecStrideNorm(x,comp,NORM_1,norm,ierr))
     61:       if (rank .eq. 0) then
     62:          write (6,400) norm
     63:  400     format ('L_1 Norm of subvector 0',1pe9.2)
     64:       endif

     66:       PetscCallA(VecStrideNorm(x,comp,NORM_INFINITY,norm,ierr))
     67:       if (rank .eq. 0) then
     68:          write (6,500) norm
     69:  500     format ('L_1 Norm of subvector 1',1pe9.2)
     70:       endif

     72: !
     73: !     Free work space.  All PETSc objects should be destroyed when they
     74: !     are no longer needed.

     76:       PetscCallA(VecDestroy(x,ierr))
     77:       PetscCallA(PetscFinalize(ierr))
     78:       end

     80: !/*TEST
     81: !
     82: !     test:
     83: !       nsize: 2
     84: !
     85: !TEST*/