Dendro  5.01
Dendro in Greek language means tree. The Dendro library is a large scale (262K cores on ORNL's Titan) distributed memory adaptive octree framework. The main goal of Dendro is to perform large scale multiphysics simulations efficeiently in mordern supercomputers. Dendro consists of efficient parallel data structures and algorithms to perform variational ( finite element) methods and finite difference mthods on 2:1 balanced arbitary adaptive octrees which enables the users to perform simulations raning from black holes (binary black hole mergers) to blood flow in human body, where applications ranging from relativity, astrophysics to biomedical engineering.
lapac.h
1 //
2 // Created by milinda on 1/19/17.
3 //
4 
15 #ifndef SFCSORTBENCH_LAPAC_H
16 #define SFCSORTBENCH_LAPAC_H
17 
18 #include <cstring>
19 #include <iostream>
20 //#include "lapacke.h"
21 
22 extern "C" void dgesv_( int* n, int* nrhs, double* a, int* lda, int* ipiv,double* b, int* ldb, int* info );
23 extern "C" void dsyev_( char* jobz, char* uplo, int* n, double* a, int* lda,double* w, double* work, int* lwork, int* info);
24 
25 // LU decomoposition of a general matrix
26 extern "C" void dgetrf_(int* M, int *N, double* A, int* lda, int* IPIV, int* INFO);
27 
28 // generate inverse of a matrix given its LU decomposition
29 extern "C" void dgetri_(int* N, double* A, int* lda, int* IPIV, double* WORK, int* lwork, int* INFO);
30 
31 
32 namespace lapack
33 {
34 
46 inline void lapack_DGESV(int n , int nrhs, const double * A, int lda, double * B, double * X, int ldb, int info)
47  {
48  int * ipiv = new int [n] ;
49  //memcpy(X,B,sizeof(double)*n*nrhs);
50 
51  for(unsigned int i=0;i<nrhs;i++)
52  for(unsigned int j=0;j<n;j++)
53  X[i*n+j]=B[j*nrhs+i];
54 
55  double * L=new double[n*n];
56 
57  for(unsigned int i=0;i<n;i++)
58  for(unsigned int j=0;j<n;j++)
59  L[i*n+j] =A [j*n+i];
60 
61  dgesv_(&n,&nrhs,L,&lda,ipiv,X,&lda,&info);
62 
63  if( info > 0 ) {
64  printf( "The diagonal element of the triangular factor of A,\n" );
65  printf( "U(%i,%i) is zero, so that A is singular;\n", info, info );
66  printf( "the solution could not be computed.\n" );
67 
68  }
69 
70  memcpy(L,X,sizeof(double)*n*nrhs);
71 
72  for(unsigned int i=0;i<nrhs;i++)
73  for(unsigned int j=0;j<n;j++)
74  X[i*nrhs+j] = L[j*n+i];
75 
76 
77  /*lapack_int * ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ;
78  memcpy(X,B,sizeof(double)*n*nrhs);
79 
80  double * L=new double[n*n];
81  memcpy(L,A,sizeof(double)*n*n);
82 
83  info = LAPACKE_dgesv( LAPACK_ROW_MAJOR, n, nrhs, L, lda, ipiv, X,ldb);*/
84 
85 
86  if (info <0) {printf(" lapack linear solve failed. \n"); }
87  delete [] L;
88  delete [] ipiv;
89 
90  return ;
91  }
92 
104 inline void lapack_DSYEV(int n, const double * A, int lda, double * wr,double * vs,int info )
105 {
106 
107 
108  double * L=new double[n*n];
109 
110  for(unsigned int i=0;i<n;i++)
111  for(unsigned int j=0;j<n;j++)
112  L[i*n+j] =A [j*n+i];
113 
114  double wkopt;
115  double* work;
116  int lwork=-1;
117  dsyev_((char*) "Vectors", (char*)"Upper", (int*)&n, L, (int*)&lda, wr, &wkopt, &lwork,(int*)&info );
118  lwork = (int)wkopt;
119  work = new double[lwork];
120  /* Solve eigenproblem */
121  dsyev_( (char*)"Vectors", (char*)"Upper", (int*)&n, L, (int*)&lda, wr, work, &lwork, (int*)&info );
122 
123 
124  for(unsigned int i=0;i<n;i++)
125  for(unsigned int j=0;j<n;j++)
126  vs[i*n+j]=L[j*n+i];
127 
128  /* std::cout<<"lapack: "<<std::endl;
129 
130  for(unsigned int i=0;i<n;i++)
131  std::cout<<" i: "<<i<<" eig : "<<wr[i]<<std::endl;
132 
133  for(unsigned int i=0;i<n;i++)
134  {
135  for(unsigned int j=0;j<n;j++)
136  {
137  std::cout<<vs[i*(n)+j]<<" ";
138  }
139 
140  std::cout<<std::endl;
141  }
142 
143  memcpy(vs,A,sizeof(double)*n*n);
144  info=LAPACKE_dsyev(LAPACK_ROW_MAJOR,'V','U',n,vs,lda,wr);
145  std::cout<<"lapacke: "<<std::endl;
146  for(unsigned int i=0;i<n;i++)
147  std::cout<<" i: "<<i<<" eig : "<<wr[i]<<std::endl;
148 
149  for(unsigned int i=0;i<n;i++)
150  {
151  for(unsigned int j=0;j<n;j++)
152  {
153  std::cout<<vs[i*(n)+j]<<" ";
154  }
155 
156  std::cout<<std::endl;
157  }*/
158 
159  delete [] work;
160  delete [] L;
161  if(info!=0) std::cout<<"lapack eigen solve failed. "<<std::endl;
162  return;
163 
164 }
165 
172 inline void inverse(double* A, int N)
173 {
174  int *IPIV = new int[N+1];
175  int LWORK = N*N;
176  double *WORK = new double[LWORK];
177  int INFO;
178 
179  dgetrf_(&N,&N,A,&N,IPIV,&INFO);
180  dgetri_(&N,A,&N,IPIV,WORK,&LWORK,&INFO);
181 
182  delete IPIV;
183  delete WORK;
184 }
185 
186 
187 
188 
189 
190 }// end of namespace
191 
192 
193 #endif //SFCSORTBENCH_LAPAC_H
Definition: lapac.h:32