Actual source code: ex300.c


  2: static char help[] = "Show MatShift BUG happening after copying a matrix with no rows on a process";
  3: /*
  4:    Contributed by: Eric Chamberland
  5: */
  6: #include <petscmat.h>

  8: /* DEFINE this to turn on/off the bug: */
  9: #define SET_2nd_PROC_TO_HAVE_NO_LOCAL_LINES

 11: int main(int argc,char **args)
 12: {
 13:   Mat               C;
 14:   PetscInt          i,m = 3;
 15:   PetscMPIInt       rank,size;
 16:   PetscErrorCode    ierr;
 17:   PetscScalar       v;
 18:   Mat               lMatA;
 19:   PetscInt          locallines;
 20:   PetscInt          d_nnz[3] = {0,0,0};
 21:   PetscInt          o_nnz[3] = {0,0,0};

 23:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 24:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 25:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 27:   if (2 != size) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"Relevant with 2 processes only");
 28:   MatCreate(PETSC_COMM_WORLD,&C);

 30: #ifdef SET_2nd_PROC_TO_HAVE_NO_LOCAL_LINES
 31:   if (0 == rank) {
 32:     locallines = m;
 33:     d_nnz[0] = 1;
 34:     d_nnz[1] = 1;
 35:     d_nnz[2] = 1;
 36:   } else {
 37:    locallines = 0;
 38:   }
 39: #else
 40:   if (0 == rank) {
 41:     locallines = m-1;
 42:     d_nnz[0] = 1;
 43:     d_nnz[1] = 1;
 44:   } else {
 45:     locallines = 1;
 46:     d_nnz[0] = 1;
 47:   }
 48: #endif

 50:   MatSetSizes(C,locallines,locallines,m,m);
 51:   MatSetFromOptions(C);
 52:   MatXAIJSetPreallocation(C,1,d_nnz,o_nnz,NULL,NULL);

 54:   v = 2;
 55:   /* Assembly on the diagonal: */
 56:   for (i=0; i<m; i++) {
 57:      MatSetValues(C,1,&i,1,&i,&v,ADD_VALUES);
 58:   }
 59:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 60:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
 61:   MatSetOption(C,MAT_NEW_NONZERO_LOCATION_ERR,PETSC_TRUE);
 62:   MatSetOption(C, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
 63:   MatView(C,PETSC_VIEWER_STDOUT_WORLD);
 64:   MatConvert(C,MATSAME, MAT_INITIAL_MATRIX, &lMatA);
 65:   MatView(lMatA,PETSC_VIEWER_STDOUT_WORLD);

 67:   MatShift(lMatA,-1.0);

 69:   MatDestroy(&lMatA);
 70:   MatDestroy(&C);
 71:   PetscFinalize();
 72:   return ierr;
 73: }

 75: /*TEST

 77:    test:
 78:       nsize: 2

 80: TEST*/