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 #ifndef _RELEASE_
54  PushCallStack("SuperLUMatrix<Real>::SuperLUMatrix");
55 #endif
56  ptrData = NULL;
57 #ifndef _RELEASE_
58  PopCallStack();
59 #endif
60 } // ----- end of method SuperLUMatrix<Real>::SuperLUMatrix -----
61 
62 
63 inline SuperLUMatrix<Real>::SuperLUMatrix ( const SuperLUGrid<Real>& g, const SuperLUOptions& opt )
64 {
65 #ifndef _RELEASE_
66  PushCallStack("SuperLUMatrix<Real>::SuperLUMatrix");
67 #endif
68  ptrData = new RealSuperLUData(g,opt);
69 #ifndef _RELEASE_
70  PopCallStack();
71 #endif
72 } // ----- end of method SuperLUMatrix<Real>::SuperLUMatrix -----
73 
74 inline SuperLUMatrix<Real>::~SuperLUMatrix ( )
75 {
76 #ifndef _RELEASE_
77  PushCallStack("SuperLUMatrix<Real>::~SuperLUMatrix");
78 #endif
79  if( ptrData != NULL )
80  delete ptrData;
81 #ifndef _RELEASE_
82  PopCallStack();
83 #endif
84 } // ----- end of method SuperLUMatrix<Real>::~SuperLUMatrix -----
85 
86 inline void
87 SuperLUMatrix<Real>::Setup ( const SuperLUGrid<Real>& g, const SuperLUOptions& opt )
88 {
89 #ifndef _RELEASE_
90  PushCallStack("SuperLUMatrix<Real>::Setup");
91 #endif
92  if( ptrData == NULL ){
93  ptrData = new RealSuperLUData(g,opt);
94  }
95  else{
96  throw std::logic_error("SuperLUMatrix has been set up before.");
97  }
98 #ifndef _RELEASE_
99  PopCallStack();
100 #endif
101  return;
102 } // ----- end of method SuperLUMatrix<Real>::Setup -----
103 
104 
105 
106 inline Int SuperLUMatrix<Real>::m ( ) const
107 {
108  return ptrData->m();
109 } // ----- end of method SuperLUMatrix<Real>::m -----
110 
111 
112 
113 inline Int SuperLUMatrix<Real>::n ( ) const
114 {
115  return ptrData->n();
116 } // ----- end of method SuperLUMatrix<Real>::n -----
117 
118 inline void
120 {
121 #ifndef _RELEASE_
122  PushCallStack( "SuperLUMatrix<Real>::DistSparseMatrixToSuperMatrixNRloc" );
123 #endif
124  ptrData->DistSparseMatrixToSuperMatrixNRloc(sparseA );
125 #ifndef _RELEASE_
126  PopCallStack();
127 #endif
128  return;
129 } // ----- end of method SuperLUMatrix<Real>::DistSparseMatrixToSuperMatrixNRloc -----
130 
131 
132 inline void
134 {
135 #ifndef _RELEASE_
136  PushCallStack("SuperLUMatrix<Real>::DestroyAOnly");
137 #endif
138  ptrData->DestroyAOnly();
139 #ifndef _RELEASE_
140  PopCallStack();
141 #endif
142 
143  return ;
144 } // ----- end of method SuperLUMatrix<Real>::DestroyAOnly -----
145 
146 inline void
148 {
149 #ifndef _RELEASE_
150  PushCallStack("SuperLUMatrix<Real>::SymbolicFactorize");
151 #endif
152  ptrData->SymbolicFactorize();
153 #ifndef _RELEASE_
154  PopCallStack();
155 #endif
156 
157  return ;
158 } // ----- end of method SuperLUMatrix<Real>::SymbolicFactorize -----
159 
160 
161 inline void
163 {
164 #ifndef _RELEASE_
165  PushCallStack("SuperLUMatrix<Real>::Distribute");
166 #endif
167  ptrData->Distribute();
168 #ifndef _RELEASE_
169  PopCallStack();
170 #endif
171 
172  return ;
173 } // ----- end of method SuperLUMatrix<Real>::Distribute -----
174 
175 
176 inline void
178 {
179 #ifndef _RELEASE_
180  PushCallStack("SuperLUMatrix<Real>::NumericalFactorize");
181 #endif
182  ptrData->NumericalFactorize();
183 #ifndef _RELEASE_
184  PopCallStack();
185 #endif
186 
187  return ;
188 } // ----- end of method SuperLUMatrix<Real>::NumericalFactorize -----
189 
190 
191 inline void
193 {
194 #ifndef _RELEASE_
195  PushCallStack("SuperLUMatrix<Real>::ConvertNRlocToNC");
196 #endif
197  ptrData->ConvertNRlocToNC(AGlobal.ptrData);
198 #ifndef _RELEASE_
199  PopCallStack();
200 #endif
201 
202  return ;
203 } // ----- end of method SuperLUMatrix<Real>::ConvertNRlocToNC -----
204 
205 inline void
207 {
208 #ifndef _RELEASE_
209  PushCallStack("SuperLUMatrix<Real>::MultiplyGlobalMultiVector");
210 #endif
211  ptrData->MultiplyGlobalMultiVector(xGlobal, bGlobal);
212 #ifndef _RELEASE_
213  PopCallStack();
214 #endif
215 
216  return ;
217 } // ----- end of method SuperLUMatrix<Real>::MultiplyGlobalMultiVector -----
218 
219 
220 inline void
222 {
223 #ifndef _RELEASE_
224  PushCallStack("SuperLUMatrix<Real>::DistributeGlobalMultiVector");
225 #endif
226  ptrData->DistributeGlobalMultiVector(xGlobal, xLocal );
227 #ifndef _RELEASE_
228  PopCallStack();
229 #endif
230 
231  return ;
232 } // ----- end of method SuperLUMatrix<Real>::DistributeGlobalMultiVector -----
233 
234 
236 {
237 #ifndef _RELEASE_
238  PushCallStack("SuperLUMatrix<Real>::GatherDistributedMultiVector");
239 #endif
240  ptrData->GatherDistributedMultiVector(xGlobal, xLocal );
241 #ifndef _RELEASE_
242  PopCallStack();
243 #endif
244 
245  return ;
246 } // ----- end of method SuperLUMatrix<Real>::GatherDistributedMultiVector -----
247 
248 
249 inline void
251 {
252 #ifndef _RELEASE_
253  PushCallStack("SuperLUMatrix<Real>::SolveDistMultiVector");
254 #endif
255  ptrData->SolveDistMultiVector(bLocal, berr );
256 #ifndef _RELEASE_
257  PopCallStack();
258 #endif
259 
260  return ;
261 } // ----- end of method SuperLUMatrix<Real>::SolveDistMultiVector -----
262 
263 
264 inline void
266 {
267 #ifndef _RELEASE_
268  PushCallStack("SuperLUMatrix<Real>::CheckErrorDistMultiVector");
269 #endif
270  ptrData->CheckErrorDistMultiVector(xLocal, xTrueLocal );
271 #ifndef _RELEASE_
272  PopCallStack();
273 #endif
274 
275  return ;
276 } // ----- end of method SuperLUMatrix<Real>::CheckErrorDistMultiVector -----
277 
278 
279 inline void
281 {
282 #ifndef _RELEASE_
283  PushCallStack("SuperLUMatrix<Real>::LUstructToPMatrix");
284 #endif
285  ptrData->LUstructToPMatrix(PMloc);
286 #ifndef _RELEASE_
287  PopCallStack();
288 #endif
289 
290  return ;
291 } // ----- end of method SuperLUMatrix<Real>::LUstructToPMatrix -----
292 
293 
294 
295 inline void
297 {
298 #ifndef _RELEASE_
299  PushCallStack("SuperLUMatrix<Real>::SymbolicToSuperNode");
300 #endif
301  ptrData->SymbolicToSuperNode(super);
302 #ifndef _RELEASE_
303  PopCallStack();
304 #endif
305 
306  return ;
307 } // ----- end of method SuperLUMatrix<Real>::SymbolicToSuperNode -----
308 
309 }
310 
311 namespace PEXSI{
312 
313 inline SuperLUMatrix<Complex>::SuperLUMatrix ( )
314 {
315 #ifndef _RELEASE_
316  PushCallStack("SuperLUMatrix<Complex>::SuperLUMatrix");
317 #endif
318  ptrData = NULL;
319 #ifndef _RELEASE_
320  PopCallStack();
321 #endif
322 } // ----- end of method SuperLUMatrix<Complex>::SuperLUMatrix -----
323 
324 
325 inline SuperLUMatrix<Complex>::SuperLUMatrix ( const SuperLUGrid<Complex>& g, const SuperLUOptions& opt )
326 {
327 #ifndef _RELEASE_
328  PushCallStack("SuperLUMatrix<Complex>::SuperLUMatrix");
329 #endif
330  ptrData = new ComplexSuperLUData(g,opt);
331 #ifndef _RELEASE_
332  PopCallStack();
333 #endif
334 } // ----- end of method SuperLUMatrix<Complex>::SuperLUMatrix -----
335 
336 inline SuperLUMatrix<Complex>::~SuperLUMatrix ( )
337 {
338 #ifndef _RELEASE_
339  PushCallStack("SuperLUMatrix<Complex>::~SuperLUMatrix");
340 #endif
341  if( ptrData != NULL )
342  delete ptrData;
343 #ifndef _RELEASE_
344  PopCallStack();
345 #endif
346 } // ----- end of method SuperLUMatrix<Complex>::~SuperLUMatrix -----
347 
348 
349 inline void
350 SuperLUMatrix<Complex>::Setup ( const SuperLUGrid<Complex>& g, const SuperLUOptions& opt )
351 {
352 #ifndef _RELEASE_
353  PushCallStack("SuperLUMatrix<Complex>::Setup");
354 #endif
355  if( ptrData == NULL ){
356  ptrData = new ComplexSuperLUData(g,opt);
357  }
358  else{
359  throw std::logic_error("SuperLUMatrix has been set up before.");
360  }
361 #ifndef _RELEASE_
362  PopCallStack();
363 #endif
364 } // ----- end of method SuperLUMatrix<Complex>::Setup -----
365 
366 
367 inline Int SuperLUMatrix<Complex>::m ( ) const
368 {
369 return ptrData->m();
370 } // ----- end of method SuperLUMatrix<Complex>::m -----
371 
372 inline Int SuperLUMatrix<Complex>::n ( ) const
373 {
374  return ptrData->n();
375 } // ----- end of method SuperLUMatrix<Complex>::n -----
376 
377 inline void
379 {
380 #ifndef _RELEASE_
381  PushCallStack( "SuperLUMatrix<Complex>::DistSparseMatrixToSuperMatrixNRloc" );
382 #endif
383  ptrData->DistSparseMatrixToSuperMatrixNRloc(sparseA );
384 #ifndef _RELEASE_
385  PopCallStack();
386 #endif
387  return;
388 } // ----- end of method SuperLUMatrix<Complex>::DistSparseMatrixToSuperMatrixNRloc -----
389 
390 inline void
392 {
393 #ifndef _RELEASE_
394  PushCallStack("SuperLUMatrix<Complex>::DestroyAOnly");
395 #endif
396  ptrData->DestroyAOnly();
397 #ifndef _RELEASE_
398  PopCallStack();
399 #endif
400 
401  return ;
402 } // ----- end of method SuperLUMatrix<Complex>::DestroyAOnly -----
403 
404 inline void
406 {
407 #ifndef _RELEASE_
408  PushCallStack("SuperLUMatrix<Complex>::SymbolicFactorize");
409 #endif
410  ptrData->SymbolicFactorize();
411 #ifndef _RELEASE_
412  PopCallStack();
413 #endif
414 
415  return ;
416 } // ----- end of method SuperLUMatrix<Complex>::SymbolicFactorize -----
417 
418 inline void
420 {
421 #ifndef _RELEASE_
422  PushCallStack("SuperLUMatrix<Complex>::Distribute");
423 #endif
424  ptrData->Distribute();
425 #ifndef _RELEASE_
426  PopCallStack();
427 #endif
428 
429  return ;
430 } // ----- end of method SuperLUMatrix<Complex>::Distribute -----
431 
432 inline void
434 {
435 #ifndef _RELEASE_
436  PushCallStack("SuperLUMatrix<Complex>::NumericalFactorize");
437 #endif
438  ptrData->NumericalFactorize();
439 #ifndef _RELEASE_
440  PopCallStack();
441 #endif
442 
443  return ;
444 } // ----- end of method SuperLUMatrix<Complex>::NumericalFactorize -----
445 
446 inline void
448 {
449 #ifndef _RELEASE_
450  PushCallStack("SuperLUMatrix<Complex>::ConvertNRlocToNC");
451 #endif
452  ptrData->ConvertNRlocToNC(AGlobal.ptrData);
453 #ifndef _RELEASE_
454  PopCallStack();
455 #endif
456 
457  return ;
458 } // ----- end of method SuperLUMatrix<Complex>::ConvertNRlocToNC -----
459 
460 inline void
462 {
463 #ifndef _RELEASE_
464  PushCallStack("SuperLUMatrix<Complex>::MultiplyGlobalMultiVector");
465 #endif
466  ptrData->MultiplyGlobalMultiVector(xGlobal, bGlobal);
467 #ifndef _RELEASE_
468  PopCallStack();
469 #endif
470 
471  return ;
472 } // ----- end of method SuperLUMatrix<Complex>::MultiplyGlobalMultiVector -----
473 
474 inline void
476 {
477 #ifndef _RELEASE_
478  PushCallStack("SuperLUMatrix<Complex>::DistributeGlobalMultiVector");
479 #endif
480  ptrData->DistributeGlobalMultiVector(xGlobal, xLocal );
481 #ifndef _RELEASE_
482  PopCallStack();
483 #endif
484 
485  return ;
486 } // ----- end of method SuperLUMatrix<Complex>::DistributeGlobalMultiVector -----
487 
489 {
490 #ifndef _RELEASE_
491  PushCallStack("SuperLUMatrix<Complex>::GatherDistributedMultiVector");
492 #endif
493  ptrData->GatherDistributedMultiVector(xGlobal, xLocal );
494 #ifndef _RELEASE_
495  PopCallStack();
496 #endif
497 
498  return ;
499 } // ----- end of method SuperLUMatrix<Complex>::GatherDistributedMultiVector -----
500 
501 inline void
503 {
504 #ifndef _RELEASE_
505  PushCallStack("SuperLUMatrix<Complex>::SolveDistMultiVector");
506 #endif
507  ptrData->SolveDistMultiVector(bLocal, berr );
508 #ifndef _RELEASE_
509  PopCallStack();
510 #endif
511 
512  return ;
513 } // ----- end of method SuperLUMatrix<Complex>::SolveDistMultiVector -----
514 
515 inline void
517 {
518 #ifndef _RELEASE_
519  PushCallStack("SuperLUMatrix<Complex>::CheckErrorDistMultiVector");
520 #endif
521  ptrData->CheckErrorDistMultiVector(xLocal, xTrueLocal );
522 #ifndef _RELEASE_
523  PopCallStack();
524 #endif
525 
526  return ;
527 } // ----- end of method SuperLUMatrix<Complex>::CheckErrorDistMultiVector -----
528 
529 inline void
531 {
532 #ifndef _RELEASE_
533  PushCallStack("SuperLUMatrix<Complex>::LUstructToPMatrix");
534 #endif
535  ptrData->LUstructToPMatrix(PMloc);
536 #ifndef _RELEASE_
537  PopCallStack();
538 #endif
539 
540  return ;
541 } // ----- end of method SuperLUMatrix<Complex>::LUstructToPMatrix -----
542 
543 inline void
545 {
546 #ifndef _RELEASE_
547  PushCallStack("SuperLUMatrix<Complex>::SymbolicToSuperNode");
548 #endif
549  ptrData->SymbolicToSuperNode(super);
550 #ifndef _RELEASE_
551  PopCallStack();
552 #endif
553 
554  return ;
555 } // ----- end of method SuperLUMatrix<Complex>::SymbolicToSuperNode -----
556 
557 }
558 
559 #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:221
void SymbolicToSuperNode(SuperNodeType &super)
SymbolicToSuperNode converts the symbolic information to SuperNode structure in SelInv.
Definition: SuperLUMatrix.hpp:232
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:122
void DistributeGlobalMultiVector(NumMat< T > &xGlobal, NumMat< T > &xLocal)
DistributeGlobalMultiVector distributes a global multivector into a local multivector according to th...
Definition: SuperLUMatrix.hpp:204
void NumericalFactorize()
Performs LU factorization numerically.
Definition: SuperLUMatrix.hpp:183
void SymbolicFactorize()
Factorizes the superlu matrix symbolically.
Definition: SuperLUMatrix.hpp:168
void SolveDistMultiVector(NumMat< T > &bLocal, DblNumVec &berr)
Solve A x = b with b overwritten by x for distributed multivector.
Definition: SuperLUMatrix.hpp:213
An thin interface to keep the main code insulated from the source code of SuperLU.
Definition: SuperLUMatrix.hpp:108
void DestroyAOnly()
Releases the data in A but keeps other data, such as LUstruct.
Definition: SuperLUMatrix.hpp:157
void ConvertNRlocToNC(SuperLUMatrix< T > &AGlobal)
ConvertNRlocToNC converts a distributed compressed sparse row matrix to a global compressed sparse co...
Definition: SuperLUMatrix.hpp:189
Numerical matrix.
Definition: NumMat.hpp:61
void DistSparseMatrixToSuperMatrixNRloc(DistSparseMatrix< T > &sparseA)
Convert a distributed sparse matrix in compressed sparse column format into the SuperLU compressed ro...
Definition: SuperLUMatrix.hpp:146
void Distribute()
Distribute redistrbutes the SuperMatrix in parallel so that it is ready for the numerical factorizati...
Definition: SuperLUMatrix.hpp:175
void LUstructToPMatrix(PMatrix< T > &PMloc)
LUstructToPMatrix converts the data in LUstruct to PMatrix.
Definition: SuperLUMatrix.hpp:226
void MultiplyGlobalMultiVector(NumMat< T > &xGlobal, NumMat< T > &bGlobal)
MultiplyGlobalMultiVector computes b = A * x.
Definition: SuperLUMatrix.hpp:197