Date: 2013-07-02T14:40:16+00:00

Actual source code: ex30f.F
petsc-3.4.2 2013-07-02

      1: !
      2: !
      3: !  Tests parallel to parallel scatter where a to from index are
      4: !  duplicated
      5:       program main
      6:       implicit none

      8: #include <finclude/petscsys.h>
      9: #include <finclude/petscis.h>
     10: #include <finclude/petscvec.h>

     12:       PetscErrorCode ierr
     13:       PetscInt  nlocal, n, row
     14:       PetscInt  nlocal2,n2,eight
     15:       PetscMPIInt rank, size
     16:       PetscInt from(10), to(10)

     18:       PetscScalar num
     19:       Vec v1, v2, v3
     20:       VecScatter scat1, scat2
     21:       IS fromis, tois
     22:       n=8
     23:       nlocal=2
     24:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
     25:       call MPI_COMM_RANK(PETSC_COMM_WORLD,rank,ierr)
     26:       call MPI_COMM_SIZE(PETSC_COMM_WORLD,size,ierr)
     27:       if (size.ne.4) then
     28:          print *, 'Four processor test'
     29:          stop
     30:       end if

     32:       nlocal2 = 2*nlocal
     33:       n2      = 2*n
     34:       call VecCreateMPI(PETSC_COMM_WORLD,nlocal2,n2,v1,ierr)
     35:       call VecCreateMPI(PETSC_COMM_WORLD,nlocal,n,v2,ierr)
     36:       call VecCreateSeq(PETSC_COMM_SELF,n,v3,ierr)

     38:       num=2.0
     39:       row = 1
     40:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     41:       row = 5
     42:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     43:       row = 9
     44:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     45:       row = 13
     46:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     47:       num=1.0
     48:       row = 15
     49:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     50:       row = 3
     51:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     52:       row = 7
     53:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)
     54:       row = 11
     55:       call VecSetValue(v1,row,num,INSERT_VALUES,ierr)

     57:       call VecAssemblyBegin(v1,ierr)
     58:       call VecAssemblyEnd(v1,ierr)

     60:       num=0.0
     61:       call VecScale(v2,num,ierr)
     62:       call VecScale(v3,num,ierr)

     64:       from(1)=1
     65:       from(2)=5
     66:       from(3)=9
     67:       from(4)=13
     68:       from(5)=3
     69:       from(6)=7
     70:       from(7)=11
     71:       from(8)=15
     72:       to(1)=0
     73:       to(2)=0
     74:       to(3)=0
     75:       to(4)=0
     76:       to(5)=7
     77:       to(6)=7
     78:       to(7)=7
     79:       to(8)=7

     81:       eight = 8
     82:       call ISCreateGeneral(PETSC_COMM_SELF,eight,from,PETSC_COPY_VALUES,      &
     83:      &                     fromis,ierr)
     84:       call ISCreateGeneral(PETSC_COMM_SELF,eight,to,PETSC_COPY_VALUES,        &
     85:      &                     tois,ierr)
     86:       call VecScatterCreate(v1,fromis,v2,tois,scat1,ierr)
     87:       call VecScatterCreate(v1,fromis,v3,tois,scat2,ierr)
     88:       call ISDestroy(fromis,ierr)
     89:       call ISDestroy(tois,ierr)

     91:       call VecScatterBegin(scat1,v1,v2,ADD_VALUES,SCATTER_FORWARD,ierr)
     92:       call VecScatterEnd(scat1,v1,v2,ADD_VALUES,SCATTER_FORWARD,ierr)

     94:       call VecScatterBegin(scat2,v1,v3,ADD_VALUES,SCATTER_FORWARD,ierr)
     95:       call VecScatterEnd(scat2,v1,v3,ADD_VALUES,SCATTER_FORWARD,ierr)

     97:       call PetscObjectSetName(v1, "V1",ierr)
     98:       call VecView(v1,PETSC_VIEWER_STDOUT_WORLD,ierr)

    100:       call PetscObjectSetName(v2, "V2",ierr)
    101:       call VecView(v2,PETSC_VIEWER_STDOUT_WORLD,ierr)

    103:       if (rank.eq.0) then
    104:          call PetscObjectSetName(v3, "V3",ierr)
    105:          call VecView(v3,PETSC_VIEWER_STDOUT_SELF,ierr)
    106:       end if

    108:       call VecScatterDestroy(scat1,ierr)
    109:       call VecScatterDestroy(scat2,ierr)
    110:       call VecDestroy(v1,ierr)
    111:       call VecDestroy(v2,ierr)
    112:       call VecDestroy(v3,ierr)

    114:       call PetscFinalize(ierr)

    116:       end