Actual source code: ex46.c
1: /*$Id: ex46.c,v 1.17 2001/08/07 03:03:07 balay Exp $*/
3: static char help[] = "Tests generating a nonsymmetric BlockSolve95 (MATMPIROWBS) matrix.nn";
5: #include petscmat.h
7: int main(int argc,char **args)
8: {
9: #if !defined(PETSC_USE_COMPLEX)
10: Mat C,A;
11: PetscScalar v;
12: int i,j,I,J,Istart,Iend,N,m = 4,n = 4,rank,size;
13: #endif
14: int ierr;
16: PetscInitialize(&argc,&args,0,help);
17: #if defined(PETSC_USE_COMPLEX)
18: SETERRQ(1,"This example does not work with complex numbers");
19: #else
20: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
21: MPI_Comm_size(PETSC_COMM_WORLD,&size);
22: PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
23: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
24: N = m*n;
26: /* Generate matrix */
27: MatCreateMPIRowbs(PETSC_COMM_WORLD,PETSC_DECIDE,N,0,0,&C);
28: MatGetOwnershipRange(C,&Istart,&Iend);
29: for (I=Istart; I<Iend; I++) {
30: v = -1.0; i = I/n; j = I - i*n;
31: if (i > 0) {J = I - n; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
32: if (j > 0) {J = I - 1; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
33: if (I != 8) {v = 4.0; MatSetValues(C,1,&I,1,&I,&v,INSERT_VALUES);}
34: }
35: MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
36: MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
38: MatConvert(C,MATMPIAIJ,&A);
39: MatDestroy(C);
40: MatDestroy(A);
41: #endif
42: PetscFinalize();
43: return 0;
44: }