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 
87 
88 
89 inline SuperLUMatrix<Real>::SuperLUMatrix(const SuperLUMatrix<Real> & g){
90 #ifndef _RELEASE_
91  PushCallStack("SuperLUMatrix<Real>::SuperLUMatrix");
92 #endif
93  if(g.ptrData==NULL){
94  ptrData=NULL;
95  }
96  else{
97  ptrData = new RealSuperLUData(*g.ptrData);
98  }
99 #ifndef _RELEASE_
100  PopCallStack();
101 #endif
102 }
103 
104 inline SuperLUMatrix<Real> & SuperLUMatrix<Real>::operator = (const SuperLUMatrix<Real> & g){
105 
106  if(this!=&g){
107  if(ptrData!=NULL){
108  delete ptrData;
109  }
110 
111  if(g.ptrData==NULL){
112  ptrData=NULL;
113  }
114  else{
115  ptrData = new RealSuperLUData(*g.ptrData);
116  }
117  }
118  return *this;
119 }
120 
121 
122 
123 
124 
125 
126 inline void
127 SuperLUMatrix<Real>::Setup ( const SuperLUGrid<Real>& g, const SuperLUOptions& opt )
128 {
129 #ifndef _RELEASE_
130  PushCallStack("SuperLUMatrix<Real>::Setup");
131 #endif
132 // if( ptrData == NULL ){
133  ptrData = new RealSuperLUData(g,opt);
134 // }
135 // else{
136 // #ifdef USE_ABORT
137 //abort();
138 //#endif
139 //throw std::logic_error("SuperLUMatrix has been set up before.");
140 // }
141 #ifndef _RELEASE_
142  PopCallStack();
143 #endif
144  return;
145 } // ----- end of method SuperLUMatrix<Real>::Setup -----
146 
147 
148 
149 inline Int SuperLUMatrix<Real>::m ( ) const
150 {
151  return ptrData->m();
152 } // ----- end of method SuperLUMatrix<Real>::m -----
153 
154 
155 
156 inline Int SuperLUMatrix<Real>::n ( ) const
157 {
158  return ptrData->n();
159 } // ----- end of method SuperLUMatrix<Real>::n -----
160 
161 inline void
163 {
164 #ifndef _RELEASE_
165  PushCallStack( "SuperLUMatrix<Real>::DistSparseMatrixToSuperMatrixNRloc" );
166 #endif
167  ptrData->DistSparseMatrixToSuperMatrixNRloc(sparseA, opt );
168 #ifndef _RELEASE_
169  PopCallStack();
170 #endif
171  return;
172 } // ----- end of method SuperLUMatrix<Real>::DistSparseMatrixToSuperMatrixNRloc -----
173 
174 
175 inline void
177 {
178 #ifndef _RELEASE_
179  PushCallStack("SuperLUMatrix<Real>::DestroyAOnly");
180 #endif
181  ptrData->DestroyAOnly();
182 #ifndef _RELEASE_
183  PopCallStack();
184 #endif
185 
186  return ;
187 } // ----- end of method SuperLUMatrix<Real>::DestroyAOnly -----
188 
189 inline void
191 {
192 #ifndef _RELEASE_
193  PushCallStack("SuperLUMatrix<Real>::SymbolicFactorize");
194 #endif
195  ptrData->SymbolicFactorize();
196 #ifndef _RELEASE_
197  PopCallStack();
198 #endif
199 
200  return ;
201 } // ----- end of method SuperLUMatrix<Real>::SymbolicFactorize -----
202 
203 
204 inline void
206 {
207 #ifndef _RELEASE_
208  PushCallStack("SuperLUMatrix<Real>::Distribute");
209 #endif
210  ptrData->Distribute();
211 #ifndef _RELEASE_
212  PopCallStack();
213 #endif
214 
215  return ;
216 } // ----- end of method SuperLUMatrix<Real>::Distribute -----
217 
218 
219 inline void
221 {
222 #ifndef _RELEASE_
223  PushCallStack("SuperLUMatrix<Real>::NumericalFactorize");
224 #endif
225  ptrData->NumericalFactorize();
226 #ifndef _RELEASE_
227  PopCallStack();
228 #endif
229 
230  return ;
231 } // ----- end of method SuperLUMatrix<Real>::NumericalFactorize -----
232 
233 
234 inline void
236 {
237 #ifndef _RELEASE_
238  PushCallStack("SuperLUMatrix<Real>::ConvertNRlocToNC");
239 #endif
240  ptrData->ConvertNRlocToNC(AGlobal.ptrData);
241 #ifndef _RELEASE_
242  PopCallStack();
243 #endif
244 
245  return ;
246 } // ----- end of method SuperLUMatrix<Real>::ConvertNRlocToNC -----
247 
248 inline void
250 {
251 #ifndef _RELEASE_
252  PushCallStack("SuperLUMatrix<Real>::MultiplyGlobalMultiVector");
253 #endif
254  ptrData->MultiplyGlobalMultiVector(xGlobal, bGlobal);
255 #ifndef _RELEASE_
256  PopCallStack();
257 #endif
258 
259  return ;
260 } // ----- end of method SuperLUMatrix<Real>::MultiplyGlobalMultiVector -----
261 
262 
263 inline void
265 {
266 #ifndef _RELEASE_
267  PushCallStack("SuperLUMatrix<Real>::DistributeGlobalMultiVector");
268 #endif
269  ptrData->DistributeGlobalMultiVector(xGlobal, xLocal );
270 #ifndef _RELEASE_
271  PopCallStack();
272 #endif
273 
274  return ;
275 } // ----- end of method SuperLUMatrix<Real>::DistributeGlobalMultiVector -----
276 
277 
279 {
280 #ifndef _RELEASE_
281  PushCallStack("SuperLUMatrix<Real>::GatherDistributedMultiVector");
282 #endif
283  ptrData->GatherDistributedMultiVector(xGlobal, xLocal );
284 #ifndef _RELEASE_
285  PopCallStack();
286 #endif
287 
288  return ;
289 } // ----- end of method SuperLUMatrix<Real>::GatherDistributedMultiVector -----
290 
291 
292 inline void
294 {
295 #ifndef _RELEASE_
296  PushCallStack("SuperLUMatrix<Real>::SolveDistMultiVector");
297 #endif
298  ptrData->SolveDistMultiVector(bLocal, berr );
299 #ifndef _RELEASE_
300  PopCallStack();
301 #endif
302 
303  return ;
304 } // ----- end of method SuperLUMatrix<Real>::SolveDistMultiVector -----
305 
306 
307 inline void
309 {
310 #ifndef _RELEASE_
311  PushCallStack("SuperLUMatrix<Real>::CheckErrorDistMultiVector");
312 #endif
313  ptrData->CheckErrorDistMultiVector(xLocal, xTrueLocal );
314 #ifndef _RELEASE_
315  PopCallStack();
316 #endif
317 
318  return ;
319 } // ----- end of method SuperLUMatrix<Real>::CheckErrorDistMultiVector -----
320 
321 
322 inline void
324 {
325 #ifndef _RELEASE_
326  PushCallStack("SuperLUMatrix<Real>::LUstructToPMatrix");
327 #endif
328  ptrData->LUstructToPMatrix(PMloc);
329 #ifndef _RELEASE_
330  PopCallStack();
331 #endif
332 
333  return ;
334 } // ----- end of method SuperLUMatrix<Real>::LUstructToPMatrix -----
335 
336 
337 
338 inline void
340 {
341 #ifndef _RELEASE_
342  PushCallStack("SuperLUMatrix<Real>::SymbolicToSuperNode");
343 #endif
344  ptrData->SymbolicToSuperNode(super);
345 #ifndef _RELEASE_
346  PopCallStack();
347 #endif
348 
349  return ;
350 } // ----- end of method SuperLUMatrix<Real>::SymbolicToSuperNode -----
351 
352 }
353 
354 namespace PEXSI{
355 
356 inline SuperLUMatrix<Complex>::SuperLUMatrix ( )
357 {
358 #ifndef _RELEASE_
359  PushCallStack("SuperLUMatrix<Complex>::SuperLUMatrix");
360 #endif
361  ptrData = NULL;
362 #ifndef _RELEASE_
363  PopCallStack();
364 #endif
365 } // ----- end of method SuperLUMatrix<Complex>::SuperLUMatrix -----
366 
367 
368 inline SuperLUMatrix<Complex>::SuperLUMatrix ( const SuperLUGrid<Complex>& g, const SuperLUOptions& opt )
369 {
370 #ifndef _RELEASE_
371  PushCallStack("SuperLUMatrix<Complex>::SuperLUMatrix");
372 #endif
373  ptrData = new ComplexSuperLUData(g,opt);
374 #ifndef _RELEASE_
375  PopCallStack();
376 #endif
377 } // ----- end of method SuperLUMatrix<Complex>::SuperLUMatrix -----
378 
379 inline SuperLUMatrix<Complex>::~SuperLUMatrix ( )
380 {
381 #ifndef _RELEASE_
382  PushCallStack("SuperLUMatrix<Complex>::~SuperLUMatrix");
383 #endif
384  if( ptrData != NULL ){
385  delete ptrData;
386  }
387 #ifndef _RELEASE_
388  PopCallStack();
389 #endif
390 } // ----- end of method SuperLUMatrix<Complex>::~SuperLUMatrix -----
391 
392 
393 inline SuperLUMatrix<Complex>::SuperLUMatrix(const SuperLUMatrix<Complex> & g){
394 #ifndef _RELEASE_
395  PushCallStack("SuperLUMatrix<Complex>::SuperLUMatrix");
396 #endif
397  if(g.ptrData==NULL){
398  ptrData=NULL;
399  }
400  else{
401  ptrData = new ComplexSuperLUData(*g.ptrData);
402  }
403 #ifndef _RELEASE_
404  PopCallStack();
405 #endif
406 }
407 
408 inline SuperLUMatrix<Complex> & SuperLUMatrix<Complex>::operator = (const SuperLUMatrix<Complex> & g){
409 
410  if(this!=&g){
411  if(ptrData!=NULL){
412  delete ptrData;
413  }
414 
415  if(g.ptrData==NULL){
416  ptrData=NULL;
417  }
418  else{
419  ptrData = new ComplexSuperLUData(*g.ptrData);
420  }
421  }
422  return *this;
423 }
424 
425 
426 
427 
428 
429 inline void
430 SuperLUMatrix<Complex>::Setup ( const SuperLUGrid<Complex>& g, const SuperLUOptions& opt )
431 {
432 #ifndef _RELEASE_
433  PushCallStack("SuperLUMatrix<Complex>::Setup");
434 #endif
435 // if( ptrData == NULL ){
436  ptrData = new ComplexSuperLUData(g,opt);
437 // }
438 // else{
439 // #ifdef USE_ABORT
440 //abort();
441 //#endif
442 //throw std::logic_error("SuperLUMatrix has been set up before.");
443 // }
444 #ifndef _RELEASE_
445  PopCallStack();
446 #endif
447 } // ----- end of method SuperLUMatrix<Complex>::Setup -----
448 
449 
450 inline Int SuperLUMatrix<Complex>::m ( ) const
451 {
452 return ptrData->m();
453 } // ----- end of method SuperLUMatrix<Complex>::m -----
454 
455 inline Int SuperLUMatrix<Complex>::n ( ) const
456 {
457  return ptrData->n();
458 } // ----- end of method SuperLUMatrix<Complex>::n -----
459 
460 inline void
462 {
463 #ifndef _RELEASE_
464  PushCallStack( "SuperLUMatrix<Complex>::DistSparseMatrixToSuperMatrixNRloc" );
465 #endif
466  ptrData->DistSparseMatrixToSuperMatrixNRloc(sparseA, opt);
467 #ifndef _RELEASE_
468  PopCallStack();
469 #endif
470  return;
471 } // ----- end of method SuperLUMatrix<Complex>::DistSparseMatrixToSuperMatrixNRloc -----
472 
473 inline void
475 {
476 #ifndef _RELEASE_
477  PushCallStack("SuperLUMatrix<Complex>::DestroyAOnly");
478 #endif
479  ptrData->DestroyAOnly();
480 #ifndef _RELEASE_
481  PopCallStack();
482 #endif
483 
484  return ;
485 } // ----- end of method SuperLUMatrix<Complex>::DestroyAOnly -----
486 
487 inline void
489 {
490 #ifndef _RELEASE_
491  PushCallStack("SuperLUMatrix<Complex>::SymbolicFactorize");
492 #endif
493  ptrData->SymbolicFactorize();
494 #ifndef _RELEASE_
495  PopCallStack();
496 #endif
497 
498  return ;
499 } // ----- end of method SuperLUMatrix<Complex>::SymbolicFactorize -----
500 
501 inline void
503 {
504 #ifndef _RELEASE_
505  PushCallStack("SuperLUMatrix<Complex>::Distribute");
506 #endif
507  ptrData->Distribute();
508 #ifndef _RELEASE_
509  PopCallStack();
510 #endif
511 
512  return ;
513 } // ----- end of method SuperLUMatrix<Complex>::Distribute -----
514 
515 inline void
517 {
518 #ifndef _RELEASE_
519  PushCallStack("SuperLUMatrix<Complex>::NumericalFactorize");
520 #endif
521  ptrData->NumericalFactorize();
522 #ifndef _RELEASE_
523  PopCallStack();
524 #endif
525 
526  return ;
527 } // ----- end of method SuperLUMatrix<Complex>::NumericalFactorize -----
528 
529 inline void
531 {
532 #ifndef _RELEASE_
533  PushCallStack("SuperLUMatrix<Complex>::ConvertNRlocToNC");
534 #endif
535  ptrData->ConvertNRlocToNC(AGlobal.ptrData);
536 #ifndef _RELEASE_
537  PopCallStack();
538 #endif
539 
540  return ;
541 } // ----- end of method SuperLUMatrix<Complex>::ConvertNRlocToNC -----
542 
543 inline void
545 {
546 #ifndef _RELEASE_
547  PushCallStack("SuperLUMatrix<Complex>::MultiplyGlobalMultiVector");
548 #endif
549  ptrData->MultiplyGlobalMultiVector(xGlobal, bGlobal);
550 #ifndef _RELEASE_
551  PopCallStack();
552 #endif
553 
554  return ;
555 } // ----- end of method SuperLUMatrix<Complex>::MultiplyGlobalMultiVector -----
556 
557 inline void
559 {
560 #ifndef _RELEASE_
561  PushCallStack("SuperLUMatrix<Complex>::DistributeGlobalMultiVector");
562 #endif
563  ptrData->DistributeGlobalMultiVector(xGlobal, xLocal );
564 #ifndef _RELEASE_
565  PopCallStack();
566 #endif
567 
568  return ;
569 } // ----- end of method SuperLUMatrix<Complex>::DistributeGlobalMultiVector -----
570 
572 {
573 #ifndef _RELEASE_
574  PushCallStack("SuperLUMatrix<Complex>::GatherDistributedMultiVector");
575 #endif
576  ptrData->GatherDistributedMultiVector(xGlobal, xLocal );
577 #ifndef _RELEASE_
578  PopCallStack();
579 #endif
580 
581  return ;
582 } // ----- end of method SuperLUMatrix<Complex>::GatherDistributedMultiVector -----
583 
584 inline void
586 {
587 #ifndef _RELEASE_
588  PushCallStack("SuperLUMatrix<Complex>::SolveDistMultiVector");
589 #endif
590  ptrData->SolveDistMultiVector(bLocal, berr );
591 #ifndef _RELEASE_
592  PopCallStack();
593 #endif
594 
595  return ;
596 } // ----- end of method SuperLUMatrix<Complex>::SolveDistMultiVector -----
597 
598 inline void
600 {
601 #ifndef _RELEASE_
602  PushCallStack("SuperLUMatrix<Complex>::CheckErrorDistMultiVector");
603 #endif
604  ptrData->CheckErrorDistMultiVector(xLocal, xTrueLocal );
605 #ifndef _RELEASE_
606  PopCallStack();
607 #endif
608 
609  return ;
610 } // ----- end of method SuperLUMatrix<Complex>::CheckErrorDistMultiVector -----
611 
612 inline void
614 {
615 #ifndef _RELEASE_
616  PushCallStack("SuperLUMatrix<Complex>::LUstructToPMatrix");
617 #endif
618  ptrData->LUstructToPMatrix(PMloc);
619 #ifndef _RELEASE_
620  PopCallStack();
621 #endif
622 
623  return ;
624 } // ----- end of method SuperLUMatrix<Complex>::LUstructToPMatrix -----
625 
626 inline void
628 {
629 #ifndef _RELEASE_
630  PushCallStack("SuperLUMatrix<Complex>::SymbolicToSuperNode");
631 #endif
632  ptrData->SymbolicToSuperNode(super);
633 #ifndef _RELEASE_
634  PopCallStack();
635 #endif
636 
637  return ;
638 } // ----- end of method SuperLUMatrix<Complex>::SymbolicToSuperNode -----
639 
640 }
641 
642 #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:165
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