Actual source code: ex3f.F
1: !
2: !
3: ! Description: Displays a vector visually.
4: !
5: ! -----------------------------------------------------------------------
7: program main
8: #include <petsc/finclude/petscvec.h>
9: use petscvec
10: implicit none
12: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13: ! Beginning of program
14: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16: Vec x
17: PetscViewer viewer
18: PetscScalar v
19: PetscInt :: i,istart,iend
20: PetscInt, parameter :: ione = 1, n = 50
21: PetscErrorCode ierr
22: PetscBool flg
24: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
25: if (ierr /= 0) then
26: print*,'PetscInitialize failed'
27: stop
28: endif
29: call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER, &
30: & '-n',n,flg,ierr)
32: ! Create a vector, specifying only its global dimension.
33: ! When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
34: ! the vector format (currently parallel
35: ! or sequential) is determined at runtime. Also, the parallel
36: ! partitioning of the vector is determined by PETSc at runtime.
37: call VecCreate(PETSC_COMM_WORLD,x,ierr)
38: call VecSetSizes(x,PETSC_DECIDE,n,ierr)
39: call VecSetFromOptions(x,ierr)
41: ! Currently, all PETSc parallel vectors are partitioned by
42: ! contiguous chunks of rows across the processors. Determine
43: ! which vector are locally owned.
44: call VecGetOwnershipRange(x,istart,iend,ierr)
46: ! Set the vector elements.
47: ! - Always specify global locations of vector entries.
48: ! - Each processor needs to insert only elements that it owns locally.
49: do 100 i=istart,iend-1
50: v = 1.0*real(i)
51: call VecSetValues(x,ione,i,v,INSERT_VALUES,ierr)
52: 100 continue
54: ! Assemble vector, using the 2-step process:
55: ! VecAssemblyBegin(), VecAssemblyEnd()
56: ! Computations can be done while messages are in transition
57: ! by placing code between these two statements.
58: call VecAssemblyBegin(x,ierr)
59: call VecAssemblyEnd(x,ierr)
61: ! Open an X-window viewer. Note that we specify the same communicator
62: ! for the viewer as we used for the distributed vector (PETSC_COMM_WORLD).
63: ! - Helpful runtime option:
64: ! -draw_pause <pause> : sets time (in seconds) that the
65: ! program pauses after PetscDrawPause() has been called
66: ! (0 is default, -1 implies until user input).
68: call PetscViewerDrawOpen(PETSC_COMM_WORLD,PETSC_NULL_CHARACTER, &
69: & PETSC_NULL_CHARACTER,0,0,300,300,viewer,ierr)
71: ! View the vector
72: call VecView(x,viewer,ierr)
74: ! Free work space. All PETSc objects should be destroyed when they
75: ! are no longer needed.
77: call PetscViewerDestroy(viewer,ierr)
78: call VecDestroy(x,ierr)
80: call PetscFinalize(ierr)
81: end
83: !/*TEST
84: !
85: ! test:
86: ! nsize: 2
87: !
88: !TEST*/