KASKADE 7 development version
clapack_to_stdlapack.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2016 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12#ifndef __CLAPACK_TO_STDLAPACK__
13#define __CLAPACK_TO_STDLAPACK__
14
15#include <algorithm>
16#include <cstdio>
17#include <vector>
18
19#if defined(__CYGWIN__) || defined(StdLAPACK)
20#define __CLPK_integer int
21extern "C" {
22int ilaenv_(int*,char*,int,char*,int,int*,int*,int*,int*);
23}
24#endif
25
26#ifdef DEBUG
27#define VDEBUG 1
28#else
29#define VDEBUG 0
30#endif
31
32int clapack_dgetrf(const enum CBLAS_ORDER Order, int mA, int nA, double *a, int ldaA, int *ipiv)
33{
34 __CLPK_integer m=mA, n=nA, lda=ldaA, info;
35 dgetrf_( &m, &n, a, &lda, ipiv, &info );
36 return info;
37};
38
39int clapack_dgetri(const enum CBLAS_ORDER Order, int nA, double *a, int ldaA, int *ipiv)
40{
41 __CLPK_integer n=nA, lda=ldaA, info;
42 int minusOne=-1, one=1;
43#if defined(__CYGWIN__) || defined(StdLAPACK)
44 __CLPK_integer lwork = n* (__CLPK_integer) ilaenv_( &one, "dgetri",6, "",0, (int*) &n, &minusOne, &minusOne, &minusOne );
45#else
46 __CLPK_integer lwork = n* (__CLPK_integer) ilaenv_( &one, "dgetri", "", (int*) &n, &minusOne, &minusOne, &minusOne );
47#endif
48 std::vector<double> work(lwork);
49 if (VDEBUG) printf("*** entering dgetri ***\n");
50 dgetri_( &n, a, &lda, ipiv, &work[0], &lwork, &info );
51 if (VDEBUG) printf("***dgetri finished***\n");
52 return info;
53};
54
55int clapack_sgetrf(const enum CBLAS_ORDER Order, int mA, int nA, float *a, int ldaA, int *ipiv)
56{
57 __CLPK_integer m=mA, n=nA, lda=ldaA,info;
58 sgetrf_( &m, &n, a, &lda, ipiv, &info );
59 return info;
60};
61
62int clapack_sgetri(const enum CBLAS_ORDER Order, int nA, float *a, int ldaA, int *ipiv)
63{
64 __CLPK_integer n=nA, lda=ldaA, info;
65 int minusOne=-1, one=1;
66#if defined(__CYGWIN__) || defined(StdLAPACK)
67 __CLPK_integer lwork = n* (__CLPK_integer) ilaenv_( &one, "sgetri",6, "",0, (int*) &n, &minusOne, &minusOne, &minusOne );
68#else
69 __CLPK_integer lwork = n* (__CLPK_integer) ilaenv_( &one, "sgetri", "", (int*) &n, &minusOne, &minusOne, &minusOne );
70#endif
71 std::vector<float> work(lwork);
72 if (VDEBUG) printf("*** entering sgetri ***\n");
73 sgetri_( &n, a, &lda, ipiv, &work[0], &lwork, &info );
74 if (VDEBUG) printf("***sgetri finished***\n");
75 return info;
76};
77
78int clapack_dgesv(const enum CBLAS_ORDER Order, int nA, int nrhsA, double *a, int ldaA, int *pivA, double *b, int ldbA)
79{
80 __CLPK_integer n=nA, nrhs=nrhsA, lda=ldaA, *ipiv=pivA, ldb=ldbA;
81 __CLPK_integer info;
82 if (VDEBUG) printf("*** entering dgesv ***\n");
83 dgesv_(&n,&nrhs,a,&lda,ipiv,b,&ldb,&info);
84 if (VDEBUG) printf("***dgesv finished***\n");
85 return info;
86};
87
88int clapack_dgels(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE trans, int mA, int nA, int nrhsA, double *a, int ldaA, double *b, int ldbA)
89{
90 __CLPK_integer m=mA, n=nA, nrhs=nrhsA, lda=ldaA, ldb=ldbA, info;
91 __CLPK_integer mn = std::min(m,n);
92 __CLPK_integer lwork = std::max( 1, mn + std::max( mn, nrhs )*n );
93 char transc;
94 if ( trans == CblasNoTrans ) transc = 'N';
95 if ( trans == CblasTrans ) transc = 'T';
96 std::vector<double> work(lwork);
97 if (VDEBUG) printf("*** entering dgels ***\n");
98 dgels_(&transc,&m,&n,&nrhs,a,&lda,b,&ldb,&work[0],&lwork,&info);
99 if (VDEBUG) printf("***dgels finished***\n");
100 return info;
101};
102
103// example for a new placeholder routine - use copy/paste, then adapt the name and parameter list,
104// and uncomment the code
105//
106// int clapack_sgetrf(const enum CBLAS_ORDER Order, int mA, int nA, float *a, int ldaA, int *ipiv)
107// {
108// printf("*** clapack_sgetrf: Please supply mapping routine to standard LAPACK routine sgetrf_ ***\n");
109// printf("*** by editing this routine in header file linalg/clapack_to_mac.hh\n");
110// printf("*** Execution of program aborted! ***\n");
111// exit(10);
112// };
113//
114
115#endif
int clapack_dgetrf(const enum CBLAS_ORDER Order, int mA, int nA, double *a, int ldaA, int *ipiv)
int clapack_dgesv(const enum CBLAS_ORDER Order, int nA, int nrhsA, double *a, int ldaA, int *pivA, double *b, int ldbA)
int clapack_dgels(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE trans, int mA, int nA, int nrhsA, double *a, int ldaA, double *b, int ldbA)
int clapack_sgetrf(const enum CBLAS_ORDER Order, int mA, int nA, float *a, int ldaA, int *ipiv)
int clapack_dgetri(const enum CBLAS_ORDER Order, int nA, double *a, int ldaA, int *ipiv)
int clapack_sgetri(const enum CBLAS_ORDER Order, int nA, float *a, int ldaA, int *ipiv)
#define VDEBUG
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Definition: fixdune.hh:110
Dune::FieldVector< T, n > min(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise minimum.
Definition: fixdune.hh:122
void dgetrf_(int *m, int *n, double *a, int *lda, int *ipiv, int *info)