C++ program with MKL
i have written a c++ example for Matrix eigenvalue/eigenvector problem.
In the Documentation MKL all the examples are given in FORTRAN/C .
To find all the eigenvalue and optionally all the eigenvector of real symmetric matrix i have used the lapack function dsyev from MKL .
In This example i have created a matrix which correspond to 3D Tight Binding Hamiltonian. This is quit common in Condensed Matter Physics community.
icpc filename.cpp -O2 -C -Wl,--start-group /export/apps/ics_2012.0.032/ics/2012.0.032/mkl/lib/intel64/libmkl_intel_lp64.a /export/apps/ics_2012.0.032/ics/2012.0.032/mkl/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -openmp -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -mcmodel large -shared-intel -traceback
I assume that you have save this program in filename.cpp file . You should change the above linking path depending upon where you have installed the Intel libraries.
For Newer version just do this :
i have written a c++ example for Matrix eigenvalue/eigenvector problem.
In the Documentation MKL all the examples are given in FORTRAN/C .
To find all the eigenvalue and optionally all the eigenvector of real symmetric matrix i have used the lapack function dsyev from MKL .
In This example i have created a matrix which correspond to 3D Tight Binding Hamiltonian. This is quit common in Condensed Matter Physics community.
To compile this program you need to use this links .
#include
#include
#include "mkl.h"
#define dm 12
#define N dm*dm*dm
#define LDA N
int main()
{
int n = N, lda = LDA, info, lwork;
double wkopt;
double w[N];
double *a =new double [N*N];
int i,j,k,l,m,o,pd[dm];
for(i=0;ipd[i]=(i+1)%dm;
for(i=0;ifor(j=0;j a[i*N + j] =0.00;
//******Matrix :: 3D Tight Binding Hamiltonian ***************
for(i=0;ifor(j=0;j for(k=0;k {
l=i*dm*dm + j*dm + k;
m=pd[i]*dm*dm + j*dm + k;
a[l*N + m] =-1.0;
a[m*N + l] =-1.0;
m=i*dm*dm + pd[j]*dm + k;
a[l*N + m] =-1.0;
a[m*N + l] =-1.0;
m=i*dm*dm + j*dm + pd[k];
a[l*N + m] =-1.0;
a[m*N + l] =-1.0;
}
//*******************Diagonalization*************************************
lwork = -1;
dsyev( "N", "U", &n, a, &lda, w, &wkopt, &lwork, &info );
lwork = (int)wkopt;
double *work= new double[lwork];
dsyev( "N", "U", &n, a, &lda, w, work, &lwork, &info );
delete[] a;
delete[] work;
//*****************Write eigen values to a file :-------------------------
std::ofstream dfile("eigen.dat");
for(i=0;idfile << w[i] << std::endl;
dfile.close();
//************************************************************************
return 0;
}
icpc filename.cpp -O2 -C -Wl,--start-group /export/apps/ics_2012.0.032/ics/2012.0.032/mkl/lib/intel64/libmkl_intel_lp64.a /export/apps/ics_2012.0.032/ics/2012.0.032/mkl/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -openmp -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -mcmodel large -shared-intel -traceback
I assume that you have save this program in filename.cpp file . You should change the above linking path depending upon where you have installed the Intel libraries.
For Newer version just do this :
icpc filename.cpp -mkl
Comments
Post a Comment