1 /**********************************************************************
2     lapack_dstegr1.c:
3 
4     lapack_dstegr1.c is a subroutine to find eigenvalues and eigenvectors
5     of tridiagonlized real matrix using lapack's routines dstegr.
6 
7     Log of lapack_dstegr1.c:
8 
9        Dec/24/2004  Released by T.Ozaki
10 
11 ***********************************************************************/
12 
13 #include <stdio.h>
14 #include <math.h>
15 #include <stdlib.h>
16 #include "openmx_common.h"
17 #include "lapack_prototypes.h"
18 #include "mpi.h"
19 
20 
lapack_dstegr1(INTEGER N,INTEGER EVmax,double * D,double * E,double * W,double ** ev)21 void lapack_dstegr1(INTEGER N, INTEGER EVmax, double *D, double *E, double *W, double **ev)
22 {
23   int i,j;
24 
25   char  *JOBZ="V";
26   char  *RANGE="A";
27 
28   double VL,VU; /* dummy */
29   INTEGER IL,IU;
30   double ABSTOL_GR=LAPACK_ABSTOL;
31   INTEGER M;
32   double *Z;
33   INTEGER LDZ;
34   INTEGER *ISUPPZ;
35   INTEGER LWORK;
36   double *WORK;
37   INTEGER *IWORK;
38   INTEGER LIWORK;
39   INTEGER INFO;
40 
41   IL = 1;
42   IU = N;
43 
44   M = IU - IL + 1;
45   LDZ = N;
46 
47   Z = (double*)malloc(sizeof(double)*LDZ*N);
48   ISUPPZ = (INTEGER*)malloc(sizeof(INTEGER)*2*M);
49 
50   LWORK = 18*N;
51   LIWORK = 10*N;
52   WORK = (double*)malloc(sizeof(double)*LWORK);
53   IWORK = (INTEGER*)malloc(sizeof(INTEGER)*LIWORK);
54 
55   F77_NAME(dstegr,DSTEGR)( JOBZ, RANGE, &N,  D, E, &VL, &VU, &IL, &IU, &ABSTOL_GR,
56            &M, W, Z, &LDZ, ISUPPZ, WORK, &LWORK, IWORK, &LIWORK, &INFO );
57 
58   /* store eigenvectors */
59 
60   for (i=0; i<N; i++) {
61     for (j=0; j<N; j++) {
62       ev[i+1][j+1]= Z[i*N+j];
63     }
64   }
65 
66   /* shift ko by 1 */
67   for (i=N; i>=1; i--){
68     W[i]= W[i-1];
69   }
70 
71   if (INFO>0) {
72     /*  printf("\n error in dstegr_, info=%d\n\n",INFO); */
73   }
74   if (INFO<0) {
75     printf("info=%d in dstegr_\n",INFO);
76     MPI_Finalize();
77     exit(0);
78   }
79 
80   free(Z);
81   free(ISUPPZ);
82   free(WORK);
83   free(IWORK);
84 }
85