Amesos Package Browser (Single Doxygen Collection)  Development
Amesos_Scalapack.h
Go to the documentation of this file.
1 /*
2  TODO:
3  1) Eliminate mb_ and grid_mb_ DONE
4 
5  1) Allow user level control over whether to use a 1D or 2D data
6  distribution.
7  2) Figure out how to redistribute the vectors. (Allow no more than
8  nb vectors at a time for now). Done - I think
9  3) Move the code from software:MyExamples/TwodMap/TwoDMap.cpp in to
10  this routine (for the 2D case) Done - I think
11  4) Create the ScaLAPACK 2D dense matrix. Done - I think
12  */
13 
14 // @HEADER
15 // ***********************************************************************
16 //
17 // Amesos: Direct Sparse Solver Package
18 // Copyright (2004) Sandia Corporation
19 //
20 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
21 // license for use of this work by or on behalf of the U.S. Government.
22 //
23 // This library is free software; you can redistribute it and/or modify
24 // it under the terms of the GNU Lesser General Public License as
25 // published by the Free Software Foundation; either version 2.1 of the
26 // License, or (at your option) any later version.
27 //
28 // This library is distributed in the hope that it will be useful, but
29 // WITHOUT ANY WARRANTY; without even the implied warranty of
30 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 // Lesser General Public License for more details.
32 //
33 // You should have received a copy of the GNU Lesser General Public
34 // License along with this library; if not, write to the Free Software
35 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
36 // USA
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef _AMESOS_SCALAPACK_H_
43 #define _AMESOS_SCALAPACK_H_
44 
45 #include "Amesos_ConfigDefs.h"
46 #include "Amesos_BaseSolver.h"
47 #include "Amesos_NoCopiable.h"
48 #include "Amesos_Utils.h"
49 #include "Amesos_Time.h"
50 #include "Amesos_Status.h"
51 #include "Amesos_Control.h"
52 #include "Epetra_LinearProblem.h"
53 #include "Epetra_Time.h"
54 #ifdef EPETRA_MPI
55 #include "Epetra_MpiComm.h"
56 #else
57 #include "Epetra_Comm.h"
58 #endif
59 #include "Epetra_CrsGraph.h"
60 
62 
147  private Amesos_Time,
148  private Amesos_NoCopiable,
149  private Amesos_Utils,
150  private Amesos_Control,
151  private Amesos_Status
152  {
153 
154 public:
155 
157 
165  Amesos_Scalapack( const Epetra_LinearProblem& LinearProblem );
166 
168 
170  ~Amesos_Scalapack(void);
172 
174 
176 
183  int SymbolicFactorization() ;
184 
186 
211  int NumericFactorization() ;
212 
214 
234  int Solve();
235 
237 
239 
240 #if 0
241  char * Label() const {return(Epetra_Object::Label());};
243 #endif
244 
246  const Epetra_LinearProblem *GetProblem() const { return(Problem_); };
247 
249 
252  bool MatrixShapeOK() const ;
253 
255 
268 
270  bool UseTranspose() const {return(UseTranspose_);};
271 
273  const Epetra_Comm & Comm() const {return(GetProblem()->GetOperator()->Comm());};
274 
276 
293 
296 
299 
301  int NumSolve() const { return( Amesos_Status::NumSolve_ ); }
302 
304  void PrintTiming() const;
305 
307  void PrintStatus() const;
308 
310  void GetTiming( Teuchos::ParameterList &TimingParameterList ) const { Amesos_Time::GetTiming(TimingParameterList); }
311 
313 
314  private:
315  /*
316  RedistributeA - Convert matrix to a dense ScaLAPACK matrix
317  Preconditions:
318  Problem_ must be set
319  SetParameters()
320  ScaLAPACK1DMap and ScaLAPACK1DMatrix must either be 0 or be pointers to
321  appropriatly allocate objects. If they are non-zero, those objects
322  will be deleted and recreated.
323 
324  Postconditions:
325  nprow_, npcol_, DescA_
326  RowMatrixA_
327  ScaLAPACK1DMap_
328  ScaLAPACK1DMatrix_
329  ImportToScaLAPACK1D_
330  ImportBackToOriginal_
331 
332  */
333  int RedistributeA();
334 
335  /*
336  ConvertToScalapack - Convert matirx to form expected by Scalapack: Ai, Ap, Aval
337  Preconditions:
338  Problem_
339  Postconditions:
340  nprow_, npcol_,
341  */
342  int ConvertToScalapack();
343 
344  /*
345  PerformNumericFactorization - Call Scalapack to perform numeric factorization
346  Preconditions:
347 
348  Postconditions:
349  DenseA_, DescA_
350  */
352 
353  protected:
354 
355  int iam_; // Process number (i.e. Comm().MyPID()
356 
357  int NumGlobalElements_; // Number of rows and columns in the Problem_->GetOperator()
359 
360  //
361  // The following variables are required for the ScaLAPACK interface:
362  //
363  int nprow_ ; // number of process rows: 1 for now
364  int npcol_ ; // number of process columns
365  int ictxt_ ; // BLACS context
366  int m_per_p_; // Number of columns per process
367  int DescA_[10]; // ScaLAPACK array descriptor
368 
369  Epetra_Map *ScaLAPACK1DMap_ ; // Points to a 1D Map which matches a ScaLAPACK 1D
370  // blocked (not block cyclic) distribution
371  Epetra_CrsMatrix *ScaLAPACK1DMatrix_ ; // Points to a ScaLAPACK 1D
372  // blocked (not block cyclic) distribution
373  Epetra_Map *VectorMap_ ; // Points to a Map for vectors X and B
374  std::vector<double> DenseA_; // The data in a ScaLAPACK 1D blocked format
375  std::vector<int> Ipiv_ ; // ScaLAPACK pivot information
378 
379 
381  const Epetra_LinearProblem * Problem_;
382 
383 
384  // some timing internal to ScaLAPACK
385  double ConTime_; // time to convert to ScaLAPACKformat
386  double SymTime_; // time for symbolic factorization
387  double NumTime_; // time for numeric factorization
388  double SolTime_; // time for solution
389  double VecTime_; // time to redistribute vectors
390  double MatTime_; // time to redistribute matrix
391 
392  //
393  // Control of the data distribution
394  //
395  bool TwoD_distribution_; // True if 2D data distribution is used
396  int grid_nb_; // Row and Column blocking factor (only used in 2D distribution)
397  int mypcol_; // Process column in the ScaLAPACK2D grid
398  int myprow_; // Process row in the ScaLAPACK2D grid
399  Epetra_CrsMatrix* FatOut_;//
400 
401  //
402  // Blocking factors (For both 1D and 2D data distributions)
403  //
404  int nb_;
405  int lda_;
406 
407  Epetra_Time * Time_;
408 
409 }; // End of class Amesos_Scalapack
410 #endif /* _AMESOS_SCALAPACK_H_ */
int NumSymbolicFact_
Number of symbolic factorization phases.
Definition: Amesos_Status.h:67
int SetUseTranspose(bool UseTranspose)
SetUseTranpose(true) is more efficient in Amesos_Scalapack.
Amesos_Control: Container for some control variables.
int SymbolicFactorization()
Performs SymbolicFactorization on the matrix A.
void PrintTiming() const
Print timing information.
int NumNumericFact() const
Returns the number of numeric factorizations performed by this object.
const Epetra_LinearProblem * GetProblem() const
Get a pointer to the Problem.
int NumSolve() const
Returns the number of solves performed by this object.
int Solve()
Solves A X = B (or AT X = B)
int NumNumericFact_
Number of numeric factorization phases.
Definition: Amesos_Status.h:69
void GetTiming(Teuchos::ParameterList &list) const
Load up the current timing information into the parameter list.
Definition: Amesos_Time.h:124
Epetra_Map * VectorMap_
int NumSolve_
Number of solves.
Definition: Amesos_Status.h:71
bool UseTranspose() const
Returns the current UseTranspose setting.
Amesos_Status: Container for some status variables.
Definition: Amesos_Status.h:20
const Epetra_LinearProblem * Problem_
Amesos_Time: Container for timing information.
Definition: Amesos_Time.h:50
void GetTiming(Teuchos::ParameterList &TimingParameterList) const
Extracts timing information from the current solver and places it in the parameter list...
Epetra_Time * Time_
int NumericFactorization()
Performs NumericFactorization on the matrix A.
Epetra_CrsMatrix * FatOut_
std::vector< int > Ipiv_
int SetParameters(Teuchos::ParameterList &ParameterList)
Updates internal variables.
bool MatrixShapeOK() const
Returns true if SCALAPACK can handle this matrix shape.
int NumSymbolicFact() const
Returns the number of symbolic factorizations performed by this object.
std::vector< double > DenseA_
void PrintStatus() const
Print information about the factorization and solution phases.
Amesos_Scalapack(const Epetra_LinearProblem &LinearProblem)
Amesos_Scalapack Constructor.
Epetra_Map * ScaLAPACK1DMap_
Amesos_BaseSolver: A pure virtual class for direct solution of real-valued double-precision operators...
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this matrix.
Amesos_NoCopiable: Simple class to prevent the usage of copy constructor and operator =...
Epetra_CrsMatrix * ScaLAPACK1DMatrix_
~Amesos_Scalapack(void)
Amesos_Scalapack Destructor.
Amesos_Scalapack: A serial and parallel dense solver. For now, we implement only the unsymmetric ScaL...
Amesos_Utils: Collections of basic utilities.
Definition: Amesos_Utils.h:19