xref: /petsc/src/mat/tests/ex262f.F90 (revision 5d83a8b16d06840f96948f1a43aa9c83c769a60a)
1420957c1SBarry Smith      program main
2420957c1SBarry Smith#include <petsc/finclude/petscmat.h>
3420957c1SBarry Smith      use petscmat
4420957c1SBarry Smith      implicit none
5420957c1SBarry Smith
6420957c1SBarry Smith      Mat      A,B
7420957c1SBarry Smith      PetscErrorCode ierr
8420957c1SBarry Smith      PetscScalar, pointer :: km(:,:)
9420957c1SBarry Smith      PetscInt three,one
10420957c1SBarry Smith      PetscInt idxm(1),idxmj(1),i,j
11420957c1SBarry Smith      PetscMPIInt rank,size
12420957c1SBarry Smith
13420957c1SBarry Smith      PetscCallA(PetscInitialize(ierr))
14420957c1SBarry Smith
15420957c1SBarry Smith      PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr))
16420957c1SBarry Smith      PetscCallMPIA(MPI_Comm_size(PETSC_COMM_WORLD,size,ierr))
17420957c1SBarry Smith
18420957c1SBarry Smith      PetscCallA(MatCreate(PETSC_COMM_WORLD,A,ierr))
19420957c1SBarry Smith      three = 3
20420957c1SBarry Smith      PetscCallA(MatSetSizes(A,three,three,PETSC_DECIDE,PETSC_DECIDE,ierr))
21420957c1SBarry Smith      PetscCallA(MatSetBlockSize(A,three,ierr))
22420957c1SBarry Smith      PetscCallA(MatSetUp(A,ierr))
23420957c1SBarry Smith      PetscCallA( MatDuplicate(A,MAT_DO_NOT_COPY_VALUES,B,ierr))
24420957c1SBarry Smith      one = 1
25420957c1SBarry Smith      idxm(1) = 0
26420957c1SBarry Smith      allocate (km(three,three))
27420957c1SBarry Smith      do i=1,3
28420957c1SBarry Smith        do j=1,3
29420957c1SBarry Smith           km(1,1) = i + j
30420957c1SBarry Smith           idxm(1) = i - 1 + 3*rank
31420957c1SBarry Smith           idxmj(1) = j - 1 + 3*rank
32*5d83a8b1SBarry Smith           PetscCallA(MatSetValues(B, one, idxm, one, idxmj, reshape(km, [three*three]), ADD_VALUES, ierr))
33420957c1SBarry Smith        enddo
34420957c1SBarry Smith      enddo
35420957c1SBarry Smith
36420957c1SBarry Smith      PetscCallA(MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY,ierr))
37420957c1SBarry Smith      PetscCallA(MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY,ierr))
38420957c1SBarry Smith      PetscCallA(MatView(B,PETSC_VIEWER_STDOUT_WORLD,ierr))
39420957c1SBarry Smith
40420957c1SBarry Smith      PetscCallA(MatDestroy(A,ierr))
41420957c1SBarry Smith      PetscCallA(MatDestroy(B,ierr))
42420957c1SBarry Smith
43420957c1SBarry Smith      deallocate(km)
44420957c1SBarry Smith      PetscCallA(PetscFinalize(ierr))
45420957c1SBarry Smith      end
46420957c1SBarry Smith
47420957c1SBarry Smith!/*TEST
48420957c1SBarry Smith!
49420957c1SBarry Smith!   test:
50420957c1SBarry Smith!     nsize: 2
51420957c1SBarry Smith!
52420957c1SBarry Smith!TEST*/
53