static char help[] = "Tests DMSLICED operations\n\n"; #include int main(int argc,char *argv[]) { char mat_type[256] = MATAIJ; /* default matrix type */ MPI_Comm comm; PetscMPIInt rank,size; DM slice; PetscInt i,bs=1,N=5,n,m,rstart,ghosts[2],*d_nnz,*o_nnz,dfill[4]={1,0,0,1},ofill[4]={1,1,1,1}; PetscReal alpha =1,K=1,rho0=1,u0=0,sigma=0.2; PetscBool useblock=PETSC_TRUE; PetscScalar *xx; Mat A; Vec x,b,lf; PetscFunctionBeginUser; PetscCall(PetscInitialize(&argc,&argv,0,help)); comm = PETSC_COMM_WORLD; PetscCallMPI(MPI_Comm_size(comm,&size)); PetscCallMPI(MPI_Comm_rank(comm,&rank)); PetscOptionsBegin(comm,0,"Options for DMSliced test",0); { PetscCall(PetscOptionsInt("-n","Global number of nodes","",N,&N,NULL)); PetscCall(PetscOptionsInt("-bs","Block size (1 or 2)","",bs,&bs,NULL)); if (bs != 1) { PetscCheck(bs == 2,PETSC_COMM_WORLD,PETSC_ERR_SUP,"Block size must be 1 or 2"); PetscCall(PetscOptionsReal("-alpha","Inverse time step for wave operator","",alpha,&alpha,NULL)); PetscCall(PetscOptionsReal("-K","Bulk modulus of compressibility","",K,&K,NULL)); PetscCall(PetscOptionsReal("-rho0","Reference density","",rho0,&rho0,NULL)); PetscCall(PetscOptionsReal("-u0","Reference velocity","",u0,&u0,NULL)); PetscCall(PetscOptionsReal("-sigma","Width of Gaussian density perturbation","",sigma,&sigma,NULL)); PetscCall(PetscOptionsBool("-block","Use block matrix assembly","",useblock,&useblock,NULL)); } PetscCall(PetscOptionsString("-sliced_mat_type","Matrix type to use (aij or baij)","",mat_type,mat_type,sizeof(mat_type),NULL)); } PetscOptionsEnd(); /* Split ownership, set up periodic grid in 1D */ n = PETSC_DECIDE; PetscCall(PetscSplitOwnership(comm,&n,&N)); rstart = 0; PetscCallMPI(MPI_Scan(&n,&rstart,1,MPIU_INT,MPI_SUM,comm)); rstart -= n; ghosts[0] = (N+rstart-1)%N; ghosts[1] = (rstart+n)%N; PetscCall(PetscMalloc2(n,&d_nnz,n,&o_nnz)); for (i=0; i 1 && (i==0 || i==n-1)) { d_nnz[i] = 2; o_nnz[i] = 1; } else { d_nnz[i] = 3; o_nnz[i] = 0; } } PetscCall(DMSlicedCreate(comm,bs,n,2,ghosts,d_nnz,o_nnz,&slice)); /* Currently does not copy X_nnz so we can't free them until after DMSlicedGetMatrix */ if (!useblock) PetscCall(DMSlicedSetBlockFills(slice,dfill,ofill)); /* Irrelevant for baij formats */ PetscCall(DMSetMatType(slice,mat_type)); PetscCall(DMCreateMatrix(slice,&A)); PetscCall(PetscFree2(d_nnz,o_nnz)); PetscCall(MatSetOption(A,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_TRUE)); PetscCall(DMCreateGlobalVector(slice,&x)); PetscCall(VecDuplicate(x,&b)); PetscCall(VecGhostGetLocalForm(x,&lf)); PetscCall(VecGetSize(lf,&m)); PetscCheck(m == (n+2)*bs,PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"size of local form %" PetscInt_FMT ", expected %" PetscInt_FMT,m,(n+2)*bs); PetscCall(VecGetArray(lf,&xx)); for (i=0; i