static char help[] = "Test ViennaCL Matrix Conversions"; #include int main(int argc,char **args) { PetscErrorCode ierr; PetscMPIInt rank,size; ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); /* Construct a sequential ViennaCL matrix and vector */ if (!rank) { Mat A_vcl; Vec v_vcl,r_vcl; PetscInt n = 17, m = 31,nz = 5,i,cnt,j; const PetscScalar val = 1.0; ierr = MatCreateSeqAIJViennaCL(PETSC_COMM_SELF,m,n,nz,NULL,&A_vcl);CHKERRQ(ierr); /* Add nz arbitrary entries per row in arbitrary columns */ for(i=0;i tol) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"Sequential CPU and MPI ViennaCL vector results incompatible with inf norm greater than tolerance of %g",tol); ierr = VecDestroy(&v);CHKERRQ(ierr); ierr = VecDestroy(&r);CHKERRQ(ierr); ierr = VecDestroy(&v_vcl);CHKERRQ(ierr); ierr = VecDestroy(&r_vcl);CHKERRQ(ierr); ierr = VecDestroy(&d_vcl);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); ierr = MatDestroy(&A_vcl);CHKERRQ(ierr); } /* Create a sequential AIJ matrix on rank 0 convert it inplace to a new ViennaCL matrix, and apply it to a ViennaCL vector */ if(!rank) { Mat A; Vec v,r,v_vcl,r_vcl,d_vcl; PetscInt n=17,m=31,nz=5,i,cnt,j; const PetscScalar val = 1.0; PetscReal dnorm; const PetscReal tol = 1e-5; ierr = MatCreateSeqAIJ(PETSC_COMM_SELF,m,n,nz,NULL,&A);CHKERRQ(ierr); /* Add nz arbitrary entries per row in arbitrary columns */ for(i=0;i tol) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"MPI CPU and MPI ViennaCL Vector results incompatible with inf norm greater than tolerance of %g",tol); ierr = VecDestroy(&v);CHKERRQ(ierr); ierr = VecDestroy(&r);CHKERRQ(ierr); ierr = VecDestroy(&v_vcl);CHKERRQ(ierr); ierr = VecDestroy(&r_vcl);CHKERRQ(ierr); ierr = VecDestroy(&d_vcl);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); } /* Create a parallel AIJ matrix, convert it to a new ViennaCL matrix, and apply it to a ViennaCL vector */ if (size > 1) { Mat A,A_vcl; Vec v,r,v_vcl,r_vcl,d_vcl; PetscInt N=17,M=31,nz=5,i,cnt,j,rlow,rhigh; const PetscScalar val = 1.0; PetscReal dnorm; const PetscReal tol=1e-5; ierr = MatCreateAIJ(PETSC_COMM_WORLD,PETSC_DETERMINE,PETSC_DETERMINE,M,N,nz,NULL,nz,NULL,&A);CHKERRQ(ierr); /* Add nz arbitrary entries per row in arbitrary columns */ ierr = MatGetOwnershipRange(A,&rlow,&rhigh);CHKERRQ(ierr); for(i=rlow;i tol) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"MPI CPU and MPI ViennaCL Vector results incompatible with inf norm greater than tolerance of %g",tol); ierr = VecDestroy(&v);CHKERRQ(ierr); ierr = VecDestroy(&r);CHKERRQ(ierr); ierr = VecDestroy(&v_vcl);CHKERRQ(ierr); ierr = VecDestroy(&r_vcl);CHKERRQ(ierr); ierr = VecDestroy(&d_vcl);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); ierr = MatDestroy(&A_vcl);CHKERRQ(ierr); } /* Create a parallel AIJ matrix, convert it in-place to a ViennaCL matrix, and apply it to a ViennaCL vector */ if (size > 1) { Mat A; Vec v,r,v_vcl,r_vcl,d_vcl; PetscInt N=17,M=31,nz=5,i,cnt,j,rlow,rhigh; const PetscScalar val = 1.0; PetscReal dnorm; const PetscReal tol=1e-5; ierr = MatCreateAIJ(PETSC_COMM_WORLD,PETSC_DETERMINE,PETSC_DETERMINE,M,N,nz,NULL,nz,NULL,&A);CHKERRQ(ierr); /* Add nz arbitrary entries per row in arbitrary columns */ ierr = MatGetOwnershipRange(A,&rlow,&rhigh);CHKERRQ(ierr); for(i=rlow;i tol) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"MPI CPU and MPI ViennaCL Vector results incompatible with inf norm greater than tolerance of %g",tol); ierr = VecDestroy(&v);CHKERRQ(ierr); ierr = VecDestroy(&r);CHKERRQ(ierr); ierr = VecDestroy(&v_vcl);CHKERRQ(ierr); ierr = VecDestroy(&r_vcl);CHKERRQ(ierr); ierr = VecDestroy(&d_vcl);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); } ierr = PetscFinalize(); return ierr; } /*TEST build: requires: viennacl test: output_file: output/ex204.out test: suffix: 2 nsize: 2 output_file: output/ex204.out TEST*/