Actual source code: ex46.c

  2: static char help[] = "Tests generating a nonsymmetric BlockSolve95 (MATMPIROWBS) matrix.\n\n";

 4:  #include petscmat.h

  8: int main(int argc,char **args)
  9: {
 10: #if !defined(PETSC_USE_COMPLEX)
 11:   Mat            C,A;
 12:   PetscScalar    v;
 13:   PetscInt       i,j,I,J,Istart,Iend,N,m = 4,n = 4;
 14:   PetscMPIInt    rank,size;
 15: #endif

 18:   PetscInitialize(&argc,&args,0,help);
 19: #if defined(PETSC_USE_COMPLEX)
 20:   SETERRQ(1,"This example does not work with complex numbers");
 21: #else
 22:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 23:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 24:   PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
 25:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
 26:   N = m*n;

 28:   /* Generate matrix */
 29:   MatCreateMPIRowbs(PETSC_COMM_WORLD,PETSC_DECIDE,N,0,0,&C);
 30:   MatGetOwnershipRange(C,&Istart,&Iend);
 31:   for (I=Istart; I<Iend; I++) {
 32:     v = -1.0; i = I/n; j = I - i*n;
 33:     if (i >  0)  {J = I - n; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
 34:     if (j >  0)  {J = I - 1; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
 35:     if (I != 8) {v = 4.0; MatSetValues(C,1,&I,1,&I,&v,INSERT_VALUES);}
 36:   }
 37:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 38:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);

 40:   MatConvert(C,MATMPIAIJ,MAT_INITIAL_MATRIX,&A);
 41:   MatDestroy(C);
 42:   MatDestroy(A);
 43: #endif
 44:   PetscFinalize();
 45:   return 0;
 46: }