Actual source code: ex52.c
1: /*$Id: ex52.c,v 1.16 2001/08/07 03:03:07 balay Exp $*/
3: static char help[] = "Tests the vatious routines in MatMPIBAIJ format.n";
6: #include petscmat.h
8: int main(int argc,char **args)
9: {
10: Mat A;
11: int m=2,ierr,bs=1,M,row,col,rank,size,start,end;
12: PetscScalar data=100;
14: PetscInitialize(&argc,&args,(char *)0,help);
15: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
16: MPI_Comm_size(PETSC_COMM_WORLD,&size);
17: /* Test MatSetValues() and MatGetValues() */
18: PetscOptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);
19: PetscOptionsGetInt(PETSC_NULL,"-mat_size",&m,PETSC_NULL);
21: M = m*bs*size;
22: MatCreateMPIBAIJ(PETSC_COMM_WORLD,bs,PETSC_DECIDE,PETSC_DECIDE,M,M,PETSC_DECIDE,PETSC_NULL,PETSC_DECIDE,PETSC_NULL,&A);
24: MatGetOwnershipRange(A,&start,&end);
25:
26: for (row=start; row<end; row++) {
27: for (col=start; col<end; col++,data+=1) {
28: MatSetValues(A,1,&row,1,&col,&data,INSERT_VALUES);
29: }
30: }
31: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
32: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
34: /* off proc assembly */
35: data = 5.0;
36: row = (M+start-1)%M;
37: for (col=0; col<M; col++) {
38: MatSetValues(A,1,&row,1,&col,&data,ADD_VALUES);
39: }
40: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
41: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
43: MatView(A,PETSC_VIEWER_STDOUT_WORLD);
45: MatDestroy(A);
46:
47: PetscFinalize();
48: return 0;
49: }
50: