tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
tensor_blas.h
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef TENSOR_TENSOR_BLAS_H
21 #define TENSOR_TENSOR_BLAS_H
22 
23 #include <tensor/config.h>
24 #include <tensor/tensor.h>
25 
26 #ifdef TENSOR_USE_MKL
27 # include <mkl_cblas.h>
28 # include <mkl_lapack.h>
29 # define F77NAME(x) x
30 #endif
31 
32 #ifdef TENSOR_USE_ACML
33 # include <acml.h>
34 #endif
35 
36 #ifdef TENSOR_USE_VECLIB
37 # if defined(HAVE_VECLIB_CBLAS_H)
38 # include <vecLib/cblas.h>
39 # include <vecLib/clapack.h>
40 # else
41 # error "Missing cblas.h"
42 # endif
43 # define F77NAME(x) x##_
44 #endif
45 
46 #ifdef TENSOR_USE_ATLAS
47 extern "C" {
48 # ifdef HAVE_ATLAS_CBLAS_H
49 # include <atlas/cblas.h>
50 # include <atlas/clapack.h>
51 # elif defined(HAVE_CBLAS_H)
52 # include <cblas.h>
53 # include <clapack.h>
54 # else
55 # error "Header cblas.h not found"
56 # endif
57 }
58 # define F77NAME(x) x##_
59 #endif
60 
61 #ifdef TENSOR_USE_CBLAPACK
62 # include <cblapack.h>
63 # define F77NAME(x) x##_
64 #endif
65 
66 #ifdef TENSOR_USE_ESSL
67 # include <essl.h>
68 # define F77NAME(x) x
69 #endif
70 
71 #if !defined(TENSOR_USE_VECLIB) && !defined(TENSOR_USE_ATLAS) && !defined(TENSOR_USE_MKL) && !defined(TENSOR_USE_ESSL) && !defined(TENSOR_USE_CBLAPACK) && !defined(TENSOR_USE_ACML)
72 # error "We need to use one of these libraries: VecLib, Atlas, MKL, ESSL, CBLAPACK"
73 #endif
74 
75 namespace blas {
76 
77 #ifdef TENSOR_USE_VECLIB
78  typedef __CLPK_integer integer;
79  typedef __CLPK_doublecomplex cdouble;
80 #endif
81 #ifdef TENSOR_USE_ATLAS
82  typedef int integer;
83  typedef struct { double re, im; } cdouble;
84  typedef int __CLPK_integer;
85  typedef double __CLPK_doublereal;
86  typedef cdouble __CLPK_doublecomplex;
87 #endif
88 #ifdef TENSOR_USE_MKL
89  typedef MKL_INT integer;
90  typedef MKL_Complex16 cdouble;
91 #endif
92 #ifdef TENSOR_USE_ACML
93  typedef int integer;
94  typedef doublecomplex cdouble;
95  typedef int __CLPK_integer;
96  typedef double __CLPK_doublereal;
97  typedef cdouble __CLPK_doublecomplex;
98 #endif
99 #ifdef TENSOR_USE_ESSL
100  typedef _ESVINT integer;
101  typedef _ESVCOM cdouble;
102  typedef _ESVINT __CLPK_integer;
103  typedef double __CLPK_doublereal;
104  typedef _ESVCOM __CLPK_doublecomplex;
105 #endif
106 #ifdef TENSOR_USE_CBLAPACK
107  typedef integer integer;
108  typedef doublecomplex cdouble;
109  typedef integer __CLPK_integer;
110  typedef double __CLPK_doublereal;
111  typedef cdouble __CLPK_doublecomplex;
112 #endif
113 
114 #if defined(TENSOR_USE_VECLIB) || defined(TENSOR_USE_ATLAS) || defined(TENSOR_USE_MKL) || defined(TENSOR_USE_CBLAPACK)
115  inline CBLAS_TRANSPOSE char_to_op(char op)
116  {
117  if (op == 'T')
118  return CblasTrans;
119  if (op == 'C')
120  return CblasConjTrans;
121  return CblasNoTrans;
122  }
123 #endif
124 
125  inline const double *tensor_pointer(const tensor::RTensor &A) {
126  return static_cast<const double*>(A.begin());
127  }
128 
129  inline const cdouble *tensor_pointer(const tensor::CTensor &A) {
130  return static_cast<const cdouble *>((void*)A.begin());
131  }
132 
133  inline double *tensor_pointer(tensor::RTensor &A) {
134  return static_cast<double*>(A.begin());
135  }
136 
137  inline cdouble *tensor_pointer(tensor::CTensor &A) {
138  return static_cast<cdouble *>((void*)A.begin());
139  }
140 
141  inline double real(cdouble &z) {
142  return tensor::real(*static_cast<tensor::cdouble *>((void*)&z));
143  }
144 
145 }
146 
147 #endif // TENSOR_TENSOR_BLAS_H
Real Tensor with elements of type "double".
Definition: tensor.h:349
iterator begin()
Iterator at the beginning.
Definition: tensor.h:256
Complex Tensor with elements of type "cdouble".
Definition: tensor.h:435