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:   PetscScalar v;
 17:   Mat         lMatA;
 18:   PetscInt    locallines;
 19:   PetscInt    d_nnz[3] = {0, 0, 0};
 20:   PetscInt    o_nnz[3] = {0, 0, 0};

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

 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++) MatSetValues(C, 1, &i, 1, &i, &v, ADD_VALUES);
 57:   MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY);
 58:   MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY);
 59:   MatSetOption(C, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE);
 60:   MatSetOption(C, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
 61:   MatView(C, PETSC_VIEWER_STDOUT_WORLD);
 62:   MatConvert(C, MATSAME, MAT_INITIAL_MATRIX, &lMatA);
 63:   MatView(lMatA, PETSC_VIEWER_STDOUT_WORLD);

 65:   MatShift(lMatA, -1.0);

 67:   MatDestroy(&lMatA);
 68:   MatDestroy(&C);
 69:   PetscFinalize();
 70:   return 0;
 71: }

 73: /*TEST

 75:    test:
 76:       nsize: 2

 78: TEST*/