Actual source code: ex52.c
2: static char help[] = "Tests the vatious routines in MatMPIBAIJ format.\n";
5: #include petscmat.h
9: int main(int argc,char **args)
10: {
11: Mat A;
12: PetscInt m=2,bs=1,M,row,col,start,end,i,j,k;
14: PetscMPIInt rank,size;
15: PetscScalar data=100;
16: PetscTruth flg;
18: PetscInitialize(&argc,&args,(char *)0,help);
19: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
20: MPI_Comm_size(PETSC_COMM_WORLD,&size);
22: /* Test MatSetValues() and MatGetValues() */
23: PetscOptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);
24: PetscOptionsGetInt(PETSC_NULL,"-mat_size",&m,PETSC_NULL);
26: M = m*bs*size;
27: MatCreateMPIBAIJ(PETSC_COMM_WORLD,bs,PETSC_DECIDE,PETSC_DECIDE,M,M,PETSC_DECIDE,PETSC_NULL,PETSC_DECIDE,PETSC_NULL,&A);
29: MatGetOwnershipRange(A,&start,&end);
30: PetscOptionsHasName(PETSC_NULL,"-column_oriented",&flg);
31: if (flg) {
32: MatSetOption(A,MAT_COLUMN_ORIENTED);
33: }
35: /* inproc assembly */
36: for (row=start; row<end; row++) {
37: for (col=start; col<end; col++,data+=1) {
38: MatSetValues(A,1,&row,1,&col,&data,INSERT_VALUES);
39: }
40: }
41: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
42: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
44: /* offproc assembly */
45: data = 5.0;
46: row = (M+start-1)%M;
47: for (col=0; col<M; col++) {
48: MatSetValues(A,1,&row,1,&col,&data,ADD_VALUES);
49: }
50: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
51: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
53: /* Test MatSetValuesBlocked() */
54: PetscOptionsHasName(PETSC_NULL,"-test_setvaluesblocked",&flg);
55: if (flg) {
56: PetscScalar bval[bs*bs];
57: row /= bs;
58: col = start/bs;
59: /* PetscPrintf(PETSC_COMM_SELF,"[%d] Set offproc blockvalues, blockrow %d, blockcol: %d\n",rank,row,col); */
60: k = 1;
61: /* row oriented - defalt */
62: for (i=0; i<bs; i++){
63: for (j=0; j<bs; j++){
64: bval[i*bs+j] = (PetscScalar)k; k++;
65: }
66: }
67: MatSetValuesBlocked(A,1,&row,1,&col,bval,INSERT_VALUES);
68: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
69: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
70: }
72: MatView(A,PETSC_VIEWER_STDOUT_WORLD);
73: MatDestroy(A);
74: PetscFinalize();
75: return 0;
76: }
77: