PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
SuperLUMatrix_impl.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012 The Regents of the University of California,
3  through Lawrence Berkeley National Laboratory.
4 
5 Authors: Mathias Jacquelin and Lin Lin
6 
7 This file is part of PEXSI. All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 
12 (1) Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
14 (2) Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 (3) Neither the name of the University of California, Lawrence Berkeley
18 National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
19 be used to endorse or promote products derived from this software without
20 specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 You are under no obligation whatsoever to provide any bug fixes, patches, or
34 upgrades to the features, functionality or performance of the source code
35 ("Enhancements") to anyone; however, if you choose to make your Enhancements
36 available either publicly, or directly to Lawrence Berkeley National
37 Laboratory, without imposing a separate written license agreement for such
38 Enhancements, then you hereby grant the following license: a non-exclusive,
39 royalty-free perpetual license to install, use, modify, prepare derivative
40 works, incorporate into other computer software, distribute, and sublicense
41 such enhancements or derivative works thereof, in binary and source code form.
42  */
46 #ifndef _PEXSI_SUPERLUMATRIX_IMPL_HPP_
47 #define _PEXSI_SUPERLUMATRIX_IMPL_HPP_
48 
49 namespace PEXSI{
50 
51 inline SuperLUMatrix<Real>::SuperLUMatrix ( )
52 {
53  ptrData = NULL;
54 } // ----- end of method SuperLUMatrix<Real>::SuperLUMatrix -----
55 
56 
57 inline SuperLUMatrix<Real>::SuperLUMatrix ( const SuperLUGrid<Real>& g, const SuperLUOptions& opt )
58 {
59  ptrData = new RealSuperLUData(g,opt);
60 } // ----- end of method SuperLUMatrix<Real>::SuperLUMatrix -----
61 
62 inline SuperLUMatrix<Real>::~SuperLUMatrix ( )
63 {
64  if( ptrData != NULL )
65  delete ptrData;
66 } // ----- end of method SuperLUMatrix<Real>::~SuperLUMatrix -----
67 
68 
69 
70 
71 inline SuperLUMatrix<Real>::SuperLUMatrix(const SuperLUMatrix<Real> & g){
72  if(g.ptrData==NULL){
73  ptrData=NULL;
74  }
75  else{
76  ptrData = new RealSuperLUData(*g.ptrData);
77  }
78 }
79 
80 inline SuperLUMatrix<Real> & SuperLUMatrix<Real>::operator = (const SuperLUMatrix<Real> & g){
81 
82  if(this!=&g){
83  if(ptrData!=NULL){
84  delete ptrData;
85  }
86 
87  if(g.ptrData==NULL){
88  ptrData=NULL;
89  }
90  else{
91  ptrData = new RealSuperLUData(*g.ptrData);
92  }
93  }
94  return *this;
95 }
96 
97 
98 
99 
100 
101 
102 inline void
103 SuperLUMatrix<Real>::Setup ( const SuperLUGrid<Real>& g, const SuperLUOptions& opt )
104 {
105  // if( ptrData == NULL ){
106  ptrData = new RealSuperLUData(g,opt);
107  // }
108  // else{
109  //ErrorHandling("SuperLUMatrix has been set up before.");
110  // }
111  return;
112 } // ----- end of method SuperLUMatrix<Real>::Setup -----
113 
114 
115 
116 inline Int SuperLUMatrix<Real>::m ( ) const
117 {
118  return ptrData->m();
119 } // ----- end of method SuperLUMatrix<Real>::m -----
120 
121 
122 
123 inline Int SuperLUMatrix<Real>::n ( ) const
124 {
125  return ptrData->n();
126 } // ----- end of method SuperLUMatrix<Real>::n -----
127 
128 inline void
130 {
131  ptrData->DistSparseMatrixToSuperMatrixNRloc(sparseA, opt );
132  return;
133 } // ----- end of method SuperLUMatrix<Real>::DistSparseMatrixToSuperMatrixNRloc -----
134 
135 
136 inline void
138 {
139  ptrData->DestroyAOnly();
140 
141  return ;
142 } // ----- end of method SuperLUMatrix<Real>::DestroyAOnly -----
143 
144 inline void
146 {
147  ptrData->SymbolicFactorize();
148 
149  return ;
150 } // ----- end of method SuperLUMatrix<Real>::SymbolicFactorize -----
151 
152 
153 inline void
155 {
156  ptrData->Distribute();
157 
158  return ;
159 } // ----- end of method SuperLUMatrix<Real>::Distribute -----
160 
161 
162 inline void
164 {
165  ptrData->NumericalFactorize();
166 
167  return ;
168 } // ----- end of method SuperLUMatrix<Real>::NumericalFactorize -----
169 
170 
171 inline void
173 {
174  ptrData->ConvertNRlocToNC(AGlobal.ptrData);
175 
176  return ;
177 } // ----- end of method SuperLUMatrix<Real>::ConvertNRlocToNC -----
178 
179 inline void
181 {
182  ptrData->MultiplyGlobalMultiVector(xGlobal, bGlobal);
183 
184  return ;
185 } // ----- end of method SuperLUMatrix<Real>::MultiplyGlobalMultiVector -----
186 
187 
188 inline void
190 {
191  ptrData->DistributeGlobalMultiVector(xGlobal, xLocal );
192 
193  return ;
194 } // ----- end of method SuperLUMatrix<Real>::DistributeGlobalMultiVector -----
195 
196 
198 {
199  ptrData->GatherDistributedMultiVector(xGlobal, xLocal );
200 
201  return ;
202 } // ----- end of method SuperLUMatrix<Real>::GatherDistributedMultiVector -----
203 
204 
205 inline void
207 {
208  ptrData->SolveDistMultiVector(bLocal, berr );
209 
210  return ;
211 } // ----- end of method SuperLUMatrix<Real>::SolveDistMultiVector -----
212 
213 
214 inline void
216 {
217  ptrData->CheckErrorDistMultiVector(xLocal, xTrueLocal );
218 
219  return ;
220 } // ----- end of method SuperLUMatrix<Real>::CheckErrorDistMultiVector -----
221 
222 
223 inline void
225 {
226  ptrData->LUstructToPMatrix(PMloc);
227 
228  return ;
229 } // ----- end of method SuperLUMatrix<Real>::LUstructToPMatrix -----
230 
231 
232 
233 inline void
235 {
236  ptrData->SymbolicToSuperNode(super);
237 
238  return ;
239 } // ----- end of method SuperLUMatrix<Real>::SymbolicToSuperNode -----
240 
241 }
242 
243 namespace PEXSI{
244 
245 inline SuperLUMatrix<Complex>::SuperLUMatrix ( )
246 {
247  ptrData = NULL;
248 } // ----- end of method SuperLUMatrix<Complex>::SuperLUMatrix -----
249 
250 
251 inline SuperLUMatrix<Complex>::SuperLUMatrix ( const SuperLUGrid<Complex>& g, const SuperLUOptions& opt )
252 {
253  ptrData = new ComplexSuperLUData(g,opt);
254 } // ----- end of method SuperLUMatrix<Complex>::SuperLUMatrix -----
255 
256 inline SuperLUMatrix<Complex>::~SuperLUMatrix ( )
257 {
258  if( ptrData != NULL ){
259  delete ptrData;
260  }
261 } // ----- end of method SuperLUMatrix<Complex>::~SuperLUMatrix -----
262 
263 
264 inline SuperLUMatrix<Complex>::SuperLUMatrix(const SuperLUMatrix<Complex> & g){
265  if(g.ptrData==NULL){
266  ptrData=NULL;
267  }
268  else{
269  ptrData = new ComplexSuperLUData(*g.ptrData);
270  }
271 }
272 
273 inline SuperLUMatrix<Complex> & SuperLUMatrix<Complex>::operator = (const SuperLUMatrix<Complex> & g){
274 
275  if(this!=&g){
276  if(ptrData!=NULL){
277  delete ptrData;
278  }
279 
280  if(g.ptrData==NULL){
281  ptrData=NULL;
282  }
283  else{
284  ptrData = new ComplexSuperLUData(*g.ptrData);
285  }
286  }
287  return *this;
288 }
289 
290 
291 
292 
293 
294 inline void
295 SuperLUMatrix<Complex>::Setup ( const SuperLUGrid<Complex>& g, const SuperLUOptions& opt )
296 {
297  // if( ptrData == NULL ){
298  ptrData = new ComplexSuperLUData(g,opt);
299  // }
300  // else{
301  //ErrorHandling("SuperLUMatrix has been set up before.");
302  // }
303 } // ----- end of method SuperLUMatrix<Complex>::Setup -----
304 
305 
306 inline Int SuperLUMatrix<Complex>::m ( ) const
307 {
308  return ptrData->m();
309 } // ----- end of method SuperLUMatrix<Complex>::m -----
310 
311 inline Int SuperLUMatrix<Complex>::n ( ) const
312 {
313  return ptrData->n();
314 } // ----- end of method SuperLUMatrix<Complex>::n -----
315 
316 inline void
318 {
319  ptrData->DistSparseMatrixToSuperMatrixNRloc(sparseA, opt);
320  return;
321 } // ----- end of method SuperLUMatrix<Complex>::DistSparseMatrixToSuperMatrixNRloc -----
322 
323 inline void
325 {
326  ptrData->DestroyAOnly();
327 
328  return ;
329 } // ----- end of method SuperLUMatrix<Complex>::DestroyAOnly -----
330 
331 inline void
333 {
334  ptrData->SymbolicFactorize();
335 
336  return ;
337 } // ----- end of method SuperLUMatrix<Complex>::SymbolicFactorize -----
338 
339 inline void
341 {
342  ptrData->Distribute();
343 
344  return ;
345 } // ----- end of method SuperLUMatrix<Complex>::Distribute -----
346 
347 inline void
349 {
350  ptrData->NumericalFactorize();
351 
352  return ;
353 } // ----- end of method SuperLUMatrix<Complex>::NumericalFactorize -----
354 
355 inline void
357 {
358  ptrData->ConvertNRlocToNC(AGlobal.ptrData);
359 
360  return ;
361 } // ----- end of method SuperLUMatrix<Complex>::ConvertNRlocToNC -----
362 
363 inline void
365 {
366  ptrData->MultiplyGlobalMultiVector(xGlobal, bGlobal);
367 
368  return ;
369 } // ----- end of method SuperLUMatrix<Complex>::MultiplyGlobalMultiVector -----
370 
371 inline void
373 {
374  ptrData->DistributeGlobalMultiVector(xGlobal, xLocal );
375 
376  return ;
377 } // ----- end of method SuperLUMatrix<Complex>::DistributeGlobalMultiVector -----
378 
380 {
381  ptrData->GatherDistributedMultiVector(xGlobal, xLocal );
382 
383  return ;
384 } // ----- end of method SuperLUMatrix<Complex>::GatherDistributedMultiVector -----
385 
386 inline void
388 {
389  ptrData->SolveDistMultiVector(bLocal, berr );
390 
391  return ;
392 } // ----- end of method SuperLUMatrix<Complex>::SolveDistMultiVector -----
393 
394 inline void
396 {
397  ptrData->CheckErrorDistMultiVector(xLocal, xTrueLocal );
398 
399  return ;
400 } // ----- end of method SuperLUMatrix<Complex>::CheckErrorDistMultiVector -----
401 
402 inline void
404 {
405  ptrData->LUstructToPMatrix(PMloc);
406 
407  return ;
408 } // ----- end of method SuperLUMatrix<Complex>::LUstructToPMatrix -----
409 
410 inline void
412 {
413  ptrData->SymbolicToSuperNode(super);
414 
415  return ;
416 } // ----- end of method SuperLUMatrix<Complex>::SymbolicToSuperNode -----
417 
418 }
419 
420 #endif //_PEXSI_SUPERLUMATRIX_IMPL_HPP_
void CheckErrorDistMultiVector(NumMat< T > &xLocal, NumMat< T > &xTrueLocal)
Prints out the error by direct comparison with the true solution in distributed format.
Definition: SuperLUMatrix.hpp:192
void SymbolicToSuperNode(SuperNodeType &super)
SymbolicToSuperNode converts the symbolic information to SuperNode structure in SelInv.
Definition: SuperLUMatrix.hpp:203
A thin interface for passing parameters to set the SuperLU options.
Definition: superlu_dist_internal.hpp:62
void DistSparseMatrixToSuperMatrixNRloc(DistSparseMatrix< T > &sparseA, const SuperLUOptions &options)
Convert a distributed sparse matrix in compressed sparse column format into the SuperLU compressed ro...
Definition: SuperLUMatrix.hpp:117
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:177
void DistributeGlobalMultiVector(NumMat< T > &xGlobal, NumMat< T > &xLocal)
DistributeGlobalMultiVector distributes a global multivector into a local multivector according to th...
Definition: SuperLUMatrix.hpp:175
void NumericalFactorize()
Performs LU factorization numerically.
Definition: SuperLUMatrix.hpp:154
void SymbolicFactorize()
Factorizes the superlu matrix symbolically.
Definition: SuperLUMatrix.hpp:139
void SolveDistMultiVector(NumMat< T > &bLocal, DblNumVec &berr)
Solve A x = b with b overwritten by x for distributed multivector.
Definition: SuperLUMatrix.hpp:184
An thin interface to keep the main code insulated from the source code of SuperLU.
Definition: SuperLUMatrix.hpp:75
void DestroyAOnly()
Releases the data in A but keeps other data, such as LUstruct.
Definition: SuperLUMatrix.hpp:128
void ConvertNRlocToNC(SuperLUMatrix< T > &AGlobal)
ConvertNRlocToNC converts a distributed compressed sparse row matrix to a global compressed sparse co...
Definition: SuperLUMatrix.hpp:160
Numerical matrix.
Definition: NumMat.hpp:61
void Distribute()
Distribute redistrbutes the SuperMatrix in parallel so that it is ready for the numerical factorizati...
Definition: SuperLUMatrix.hpp:146
void LUstructToPMatrix(PMatrix< T > &PMloc)
LUstructToPMatrix converts the data in LUstruct to PMatrix.
Definition: SuperLUMatrix.hpp:197
void MultiplyGlobalMultiVector(NumMat< T > &xGlobal, NumMat< T > &bGlobal)
MultiplyGlobalMultiVector computes b = A * x.
Definition: SuperLUMatrix.hpp:168