static char help[] = "Test LAPACK routine DSTEBZ() and DTEIN(). \n\n"; #include #include extern PetscErrorCode CkEigenSolutions(PetscInt,Mat,PetscInt,PetscInt,PetscScalar*,Vec*,PetscReal*); int main(int argc,char **args) { PetscErrorCode ierr; #if defined(PETSC_USE_COMPLEX) || defined(PETSC_MISSING_LAPACK_STEBZ) || defined(PETSC_MISSING_LAPACK_STEIN) ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP_SYS,"This example requires LAPACK routines dstebz and stien and real numbers"); #else PetscReal *work,tols[2]; PetscInt i,j; PetscBLASInt n,il=1,iu=5,*iblock,*isplit,*iwork,nevs,*ifail,cklvl=2; PetscMPIInt size; PetscBool flg; Vec *evecs; PetscScalar *evecs_array,*D,*E,*evals; Mat T; PetscReal vl=0.0,vu=4.0,tol= 1000*PETSC_MACHINE_EPSILON; PetscBLASInt nsplit,info; ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRMPI(ierr); if (size != 1) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_WRONG_MPI_SIZE,"This is a uniprocessor example only!"); n = 100; nevs = iu - il; ierr = PetscMalloc1(3*n+1,&D);CHKERRQ(ierr); E = D + n; evals = E + n; ierr = PetscMalloc1(5*n+1,&work);CHKERRQ(ierr); ierr = PetscMalloc1(3*n+1,&iwork);CHKERRQ(ierr); ierr = PetscMalloc1(3*n+1,&iblock);CHKERRQ(ierr); isplit = iblock + n; /* Set symmetric tridiagonal matrix */ for (i=0; i dot_max) dot_max = PetscAbsScalar(dot); #if defined(DEBUG_CkEigenSolutions) if (dot > tols[1]) { ierr = VecNorm(evec[i],NORM_INFINITY,&norm);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF,"|delta(%d,%d)|: %g, norm: %d\n",i,j,(double)dot,(double)norm);CHKERRQ(ierr); } #endif } } ierr = PetscPrintf(PETSC_COMM_SELF," max|(x_j^T*x_i) - delta_ji|: %g\n",(double)dot_max);CHKERRQ(ierr); case 1: norm_max = 0.0; for (i = il; i< iu; i++) { ierr = MatMult(A, evec[i], vt1);CHKERRQ(ierr); ierr = VecCopy(evec[i], vt2);CHKERRQ(ierr); tmp = -eval[i]; ierr = VecAXPY(vt1,tmp,vt2);CHKERRQ(ierr); ierr = VecNorm(vt1, NORM_INFINITY, &norm);CHKERRQ(ierr); norm = PetscAbsReal(norm); if (norm > norm_max) norm_max = norm; #if defined(DEBUG_CkEigenSolutions) if (norm > tols[0]) { ierr = PetscPrintf(PETSC_COMM_SELF," residual violation: %d, resi: %g\n",i, norm);CHKERRQ(ierr); } #endif } ierr = PetscPrintf(PETSC_COMM_SELF," max_resi: %g\n", (double)norm_max);CHKERRQ(ierr); break; default: ierr = PetscPrintf(PETSC_COMM_SELF,"Error: cklvl=%d is not supported \n",cklvl);CHKERRQ(ierr); } ierr = VecDestroy(&vt2);CHKERRQ(ierr); ierr = VecDestroy(&vt1);CHKERRQ(ierr); PetscFunctionReturn(0); }