static char help[] = "Tests the use of MatZeroRowsColumns() for parallel matrices.\n\ Contributed-by: Stephan Kramer \n\n"; #include int main(int argc,char **args) { Mat A; Vec x, rhs, y; PetscInt i,j,k,b,m = 3,n,nlocal=2,bs=1,Ii,J; PetscInt *boundary_nodes, nboundary_nodes, *boundary_indices; PetscMPIInt rank,size; PetscErrorCode ierr; PetscScalar v,v0,v1,v2,a0=0.1,a,rhsval, *boundary_values,diag = 1.0; PetscReal norm; char convname[64]; PetscBool upwind = PETSC_FALSE, nonlocalBC = PETSC_FALSE, zerorhs = PETSC_TRUE, convert = PETSC_FALSE; ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRMPI(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRMPI(ierr); n = nlocal*size; ierr = PetscOptionsGetInt(NULL,NULL, "-bs", &bs, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetBool(NULL,NULL, "-nonlocal_bc", &nonlocalBC, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetScalar(NULL,NULL, "-diag", &diag, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetString(NULL,NULL,"-convname",convname,sizeof(convname),&convert);CHKERRQ(ierr); ierr = PetscOptionsGetBool(NULL,NULL, "-zerorhs", &zerorhs, NULL);CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr); ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m*n*bs,m*n*bs);CHKERRQ(ierr); ierr = MatSetFromOptions(A);CHKERRQ(ierr); ierr = MatSetUp(A);CHKERRQ(ierr); ierr = MatCreateVecs(A, NULL, &rhs);CHKERRQ(ierr); ierr = VecSetFromOptions(rhs);CHKERRQ(ierr); ierr = VecSetUp(rhs);CHKERRQ(ierr); rhsval = 0.0; for (i=0; i0) {J = Ii - n*bs; ierr = MatSetValues(A,1,&Ii,1,&J,&v,ADD_VALUES);CHKERRQ(ierr);} if (i0) {J = Ii - 1*bs; ierr = MatSetValues(A,1,&Ii,1,&J,&v,ADD_VALUES);CHKERRQ(ierr);} if (j2) { J = Ii-2*bs; v2 = 0.5*a; v1 = -2.0*a; v0 = 1.5*a; ierr = MatSetValues(A,1,&Ii,1,&J,&v2,ADD_VALUES);CHKERRQ(ierr); } else { /* fall back to 1st order upwind */ v1 = -1.0*a; v0 = 1.0*a; }; if (j>1) {J = Ii-1*bs; ierr = MatSetValues(A,1,&Ii,1,&J,&v1,ADD_VALUES);CHKERRQ(ierr);} ierr = MatSetValues(A,1,&Ii,1,&Ii,&v0,ADD_VALUES);CHKERRQ(ierr); a /= 10.; /* use a different velocity for the next component */ /* add a coupling to the previous and next components */ v = 0.5; if (b>0) {J = Ii - 1; ierr = MatSetValues(A,1,&Ii,1,&J,&v,ADD_VALUES);CHKERRQ(ierr);} if (bm ? nlocal : m-size+nlocal; ierr = PetscMalloc1(nboundary_nodes,&boundary_nodes);CHKERRQ(ierr); k = 0; for (i=size; i=rank*m*nlocal && Ii<(rank+1)*m*nlocal) boundary_nodes[k++] = Ii; } for (i=1; i=rank*m*nlocal && Ii<(rank+1)*m*nlocal) boundary_nodes[k++] = Ii; } nboundary_nodes = k; } ierr = VecDuplicate(rhs, &x);CHKERRQ(ierr); ierr = VecZeroEntries(x);CHKERRQ(ierr); ierr = PetscMalloc2(nboundary_nodes*bs,&boundary_indices,nboundary_nodes*bs,&boundary_values);CHKERRQ(ierr); for (k=0; k 1.0e-10) { ierr = PetscPrintf(PETSC_COMM_WORLD, "*** Difference between rhs and y, inf-norm: %f\n", (double)norm);CHKERRQ(ierr); ierr = VecView(y,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Bug in MatZeroRowsColumns"); } ierr = PetscFree(boundary_nodes);CHKERRQ(ierr); ierr = PetscFree2(boundary_indices,boundary_values);CHKERRQ(ierr); ierr = VecDestroy(&x);CHKERRQ(ierr); ierr = VecDestroy(&y);CHKERRQ(ierr); ierr = VecDestroy(&rhs);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; } /*TEST test: diff_args: -j suffix: 0 test: diff_args: -j suffix: 1 nsize: 2 test: diff_args: -j suffix: 10 nsize: 2 args: -bs 2 -nonlocal_bc test: diff_args: -j suffix: 11 nsize: 7 args: -bs 2 -nonlocal_bc test: diff_args: -j suffix: 12 args: -bs 2 -nonlocal_bc -mat_type baij test: diff_args: -j suffix: 13 nsize: 2 args: -bs 2 -nonlocal_bc -mat_type baij test: diff_args: -j suffix: 14 nsize: 7 args: -bs 2 -nonlocal_bc -mat_type baij test: diff_args: -j suffix: 2 nsize: 7 test: diff_args: -j suffix: 3 args: -mat_type baij test: diff_args: -j suffix: 4 nsize: 2 args: -mat_type baij test: diff_args: -j suffix: 5 nsize: 7 args: -mat_type baij test: diff_args: -j suffix: 6 args: -bs 2 -mat_type baij test: diff_args: -j suffix: 7 nsize: 2 args: -bs 2 -mat_type baij test: diff_args: -j suffix: 8 nsize: 7 args: -bs 2 -mat_type baij test: diff_args: -j suffix: 9 args: -bs 2 -nonlocal_bc test: diff_args: -j suffix: 15 args: -bs 2 -nonlocal_bc -convname shell test: diff_args: -j suffix: 16 nsize: 2 args: -bs 2 -nonlocal_bc -convname shell test: diff_args: -j suffix: 17 args: -bs 2 -nonlocal_bc -convname dense testset: diff_args: -j suffix: full nsize: {{1 3}separate output} args: -diag {{0.12 -0.13}separate output} -convname {{aij shell baij}separate output} -zerorhs 0 test: diff_args: -j requires: cuda suffix: cusparse_1 nsize: 1 args: -diag {{0.12 -0.13}separate output} -convname {{seqaijcusparse mpiaijcusparse}separate output} -zerorhs 0 -mat_type {{seqaijcusparse mpiaijcusparse}separate output} test: diff_args: -j requires: cuda suffix: cusparse_3 nsize: 3 args: -diag {{0.12 -0.13}separate output} -convname mpiaijcusparse -zerorhs 0 -mat_type mpiaijcusparse TEST*/