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};
22: PetscInitialize(&argc,&args,(char*)0,help);
23: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
24: MPI_Comm_size(PETSC_COMM_WORLD,&size);
27: MatCreate(PETSC_COMM_WORLD,&C);
29: #ifdef SET_2nd_PROC_TO_HAVE_NO_LOCAL_LINES
30: if (0 == rank) {
31: locallines = m;
32: d_nnz[0] = 1;
33: d_nnz[1] = 1;
34: d_nnz[2] = 1;
35: } else {
36: locallines = 0;
37: }
38: #else
39: if (0 == rank) {
40: locallines = m-1;
41: d_nnz[0] = 1;
42: d_nnz[1] = 1;
43: } else {
44: locallines = 1;
45: d_nnz[0] = 1;
46: }
47: #endif
49: MatSetSizes(C,locallines,locallines,m,m);
50: MatSetFromOptions(C);
51: MatXAIJSetPreallocation(C,1,d_nnz,o_nnz,NULL,NULL);
53: v = 2;
54: /* Assembly on the diagonal: */
55: for (i=0; i<m; i++) {
56: MatSetValues(C,1,&i,1,&i,&v,ADD_VALUES);
57: }
58: MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
59: MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
60: MatSetOption(C,MAT_NEW_NONZERO_LOCATION_ERR,PETSC_TRUE);
61: MatSetOption(C, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE);
62: MatView(C,PETSC_VIEWER_STDOUT_WORLD);
63: MatConvert(C,MATSAME, MAT_INITIAL_MATRIX, &lMatA);
64: MatView(lMatA,PETSC_VIEWER_STDOUT_WORLD);
66: MatShift(lMatA,-1.0);
68: MatDestroy(&lMatA);
69: MatDestroy(&C);
70: PetscFinalize();
71: return 0;
72: }
74: /*TEST
76: test:
77: nsize: 2
79: TEST*/