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.\n\n";

 5:  #include petscmat.h

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

 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,&A);
 41:   MatDestroy(C);
 42:   MatDestroy(A);
 43: #endif
 44:   PetscFinalize();
 45:   return 0;
 46: }