source: src/solver/dgesv.hpp@ 759a6a

Last change on this file since 759a6a was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file dgesv.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 13:09:29 2011
5 *
6 * @brief Lapack solver for general matrices.
7 *
8 */
9
10#ifndef DGESV_HPP_
11#define DGESV_HPP_
12
13#ifndef HAVE_LAPACK
14#error You need LAPACK in order to use MGDSYSV
15#endif
16
17#include <cassert>
18#include <cstddef>
19
20namespace VMG
21{
22
23extern "C" {
24
25void FC_FUNC(dgesv,DGESV) (const int* N, const int* NRHS, vmg_float* A,
26 const int* LDA, int* IPIV, vmg_float* B,
27 const int* LDB, int* INFO);
28
29void FC_FUNC(sgesv, SGESV) (const int* N, const int* NRHS, vmg_float* A,
30 const int* LDA, int* IPIV, vmg_float* B,
31 const int* LDB, int* INFO);
32
33} /* extern "C" */
34
35/* By default, assume fcs_float is double. */
36#if defined(FCS_FLOAT_IS_FLOAT)
37#define dgesv FC_FUNC(sgesv,SGESV)
38#else
39#define dgesv FC_FUNC(dgesv,DGESV)
40#endif
41
42template<class T>
43class DGESV : public T
44{
45public:
46 DGESV() :
47 T()
48 {Init();}
49
50 DGESV(int size) :
51 T(size)
52 {Init();}
53
54 virtual ~DGESV();
55
56protected:
57 void Compute();
58
59private:
60 void Init();
61 void Realloc();
62
63 int la_INFO, la_LDA, la_LDB, la_N, la_NRHS;
64 int *la_IPIV;
65 vmg_float *la_A, *la_B;
66
67 int la_cur_size, la_max_size;
68};
69
70template<class T>
71void DGESV<T>::Compute()
72{
73 // Adjust size of vectors
74 this->Realloc();
75
76 la_N = la_LDA = la_LDB = la_cur_size;
77
78 // Rewrite matrix in column-major order
79 for (int i=0; i<la_N; i++) {
80 la_B[i] = this->Rhs(i);
81 for (int j=0; j<la_N; j++)
82 la_A[i + j*la_N] = this->Mat(i,j);
83 }
84
85 // Solve system of equations
86 dgesv(&la_N, &la_NRHS, la_A, &la_LDA, la_IPIV, la_B, &la_LDB, &la_INFO);
87
88 // Assert successful exit of solver routine
89 assert(la_INFO == 0);
90
91 // Write solution back
92 for (int i=0; i<la_N; i++)
93 this->Sol(i) = la_B[i];
94}
95
96template<class T>
97void DGESV<T>::Init()
98{
99 la_cur_size = 0;
100 la_max_size = 0;
101 la_NRHS = 1;
102
103 la_IPIV = NULL;
104 la_A = NULL;
105 la_B = NULL;
106}
107
108template<class T>
109void DGESV<T>::Realloc()
110{
111 la_cur_size = this->Size();
112
113 if (la_cur_size > la_max_size) {
114
115 delete [] la_IPIV;
116 delete [] la_A;
117 delete [] la_B;
118
119 la_IPIV = new int[la_cur_size];
120 la_A = new vmg_float[la_cur_size*la_cur_size];
121 la_B = new vmg_float[la_cur_size];
122
123 la_max_size = la_cur_size;
124
125 }
126}
127
128template<class T>
129DGESV<T>::~DGESV()
130{
131 delete [] la_IPIV;
132 delete [] la_A;
133 delete [] la_B;
134}
135
136}
137
138#endif /* DGESV_HPP_ */
Note: See TracBrowser for help on using the repository browser.