KASKADE 7 development version
mumpsmpi_solve.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) 2002-2011 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
13#ifndef MUMPS_SOLVE_HH
14#define MUMPS_SOLVE_HH
15
16#include <vector>
17#include <iostream>
18#include <memory>
19
20#include "dmumps_c.h"
21#define ICNTL(I) icntl[(I)-1]
22#define JOB_INIT -1
23#define JOB_END -2
24#define USE_COMM_WORLD -987654
25
27
28namespace Kaskade
29{
30
36template <class Scalar,class SparseIndexInt=int, class DIL=int>
37class MUMPSFactorization: public Factorization<Scalar,SparseIndexInt>
38{
39public:
40
42
49 MUMPSFactorization(SparseIndexInt n_,
50 std::vector<SparseIndexInt> & ridx,
51 std::vector<SparseIndexInt> & cidx,
52 std::vector<Scalar> & values,
54 int verb = 0)
55 : N(ridx.size()), n(n_)
56 {
57 assert(cidx.size()==N && values.size()==N);
58
59 // Write debug/status output to stdcout if requested.
60 id = MPI::COMM_WORLD.Get_rank ( );
61 this->setVerbose(verb);
62 if ( (this->getVerbose()>=2) && (id == 0) )
63 {
64 const char *s = "UNKNOWN";
65 if (property==MatrixProperties::GENERAL) s = "GENERAL";
66 else if (property==MatrixProperties::SYMMETRIC) s = "SYMMETRIC";
67 else if (property==MatrixProperties::SYMMETRICSTRUCTURE) s = "SYMMETRICSTRUCTURE";
68 else if (property==MatrixProperties::POSITIVEDEFINITE) s = "POSITIVEDEFINITE";
69 std::cout << "MUMPS" << " solver, n=" << n << ", nnz=" << N << ", matrix is " << s << std::endl;
70 }
71
72 init(property);
73 analyze(&ridx[0], &cidx[0]);
74 factorize(&values[0]);
75 };
76
78
85 MUMPSFactorization(SparseIndexInt n_,
86 std::unique_ptr<std::vector<SparseIndexInt>> ridx,
87 std::unique_ptr<std::vector<SparseIndexInt>> cidx,
88 std::unique_ptr<std::vector<Scalar>> values,
90 int verb = 0)
91 : N(ridx->size()), n(n_)
92 {
93 assert(cidx->size()==N && values->size()==N);
94
95 id = MPI::COMM_WORLD.Get_rank ( );
96 this->setVerbose(verb);
97 if ( (this->getVerbose()>=2) && (id == 0) )
98 {
99 char *s = "UNKNOWN";
100 if (property==MatrixProperties::GENERAL) s = "GENERAL";
101 else if (property==MatrixProperties::SYMMETRIC) s = "SYMMETRIC";
102 else if (property==MatrixProperties::SYMMETRICSTRUCTURE) s = "SYMMETRICSTRUCTURE";
103 else if (property==MatrixProperties::POSITIVEDEFINITE) s = "POSITIVEDEFINITE";
104 std::cout << "MUMPS" << " solver, n=" << n << ", nnz=" << N << ", matrix is " << s << std::endl;
105 }
106
107 init(property);
108 analyze(&ridx[0], &cidx[0]);
109 factorize(&values[0]);
110 };
111
112
114 {
115 mumps_par.job = JOB_END;
116 mumps_par.ICNTL(3) = 0;
117 dmumps_c(&mumps_par);
118 }
119
120 void init(MatrixProperties property)
121 {
122 mumps_par.job = JOB_INIT;
123 mumps_par.par = 1;
124 switch (property)
125 {
127 mumps_par.sym = 0;
128 break;
130 mumps_par.sym = 0;
131 break;
133 mumps_par.sym = 2;
134 break;
136 mumps_par.sym = 1;
137 break;
138 }
139 mumps_par.comm_fortran = USE_COMM_WORLD;
140 dmumps_c(&mumps_par);
142 mumps_par.ICNTL(3) = 0;
143 mumps_par.ICNTL(14) += 5; // 5% additonal workspace
144 }
145
146 void analyze(SparseIndexInt *irn, SparseIndexInt *jcn)
147 {
148 mumps_par.job = 1;
149 mumps_par.n = n;
150 mumps_par.nz = N;
151 if ( id == 0 )
152 for (int k=0; k<N; k++)
153 {
154 irn[k]++;
155 jcn[k]++;
156 };
157 MPI_Barrier(MPI_COMM_WORLD);
158 mumps_par.irn = irn;
159 mumps_par.jcn = jcn;
160 dmumps_c(&mumps_par);
161 }
162
163 void factorize(Scalar *a)
164 {
165 mumps_par.job = 2;
166 mumps_par.a = a;
167 dmumps_c(&mumps_par);
168 }
169
174 void solve(std::vector<Scalar> const& b, std::vector<Scalar>& x, bool transpose=false) const
175 {
176 assert(b.size()>=n);
177 x.resize(n);
178 assert(&x != &b);
179 x = b;
180 mumps_par.job = 3;
181 mumps_par.rhs = &x[0];
182 dmumps_c(&mumps_par);
183 }
184
189 void solve(std::vector<Scalar>& b) const
190 {
191 mumps_par.job = 3;
192 mumps_par.rhs = &b[0];
193 dmumps_c(&mumps_par);
194 }
195
196private:
197 int id;
198 size_t const N;
199 size_t const n;
200 mutable DMUMPS_STRUC_C mumps_par;
201};
202
203} // namespace Kaskade
204#endif
Abstract base class for matrix factorizations.
void setVerbose(int verbose_)
void solve(std::vector< Scalar > const &b, std::vector< Scalar > &x, bool transpose=false) const
MUMPSFactorization(SparseIndexInt n_, std::unique_ptr< std::vector< SparseIndexInt > > ridx, std::unique_ptr< std::vector< SparseIndexInt > > cidx, std::unique_ptr< std::vector< Scalar > > values, MatrixProperties property=MatrixProperties::GENERAL, int verb=0)
Version of constructor, that destroys input data before factorization: more memory efficient.
void init(MatrixProperties property)
void solve(std::vector< Scalar > &b) const
void analyze(SparseIndexInt *irn, SparseIndexInt *jcn)
MUMPSFactorization(SparseIndexInt n_, std::vector< SparseIndexInt > &ridx, std::vector< SparseIndexInt > &cidx, std::vector< Scalar > &values, MatrixProperties property=MatrixProperties::GENERAL, int verb=0)
Version of constructor keeping input data in triplet format (aka coordinate format) constant.
size_t size() const
reports the dimension of the system
Definition: mumps_solve.hh:227
void analyze(MUMPS_INT *irn, MUMPS_INT *jcn)
Definition: mumps_solve.hh:131
MatrixProperties
Characterizations of sparse matrix properties.
Definition: enums.hh:76
#define JOB_END
#define JOB_INIT
#define USE_COMM_WORLD
T transpose(T x)