# source:branches/parallel/Ipopt/src/LinAlg/Parallel/IpParGenMatrix.hpp@1470

Last change on this file since 1470 was 1470, checked in by sanjeebd, 5 years ago

added expansion matrices

File size: 7.2 KB
Line
1// Copyright (C) 2009 International Business Machines and others.
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// \$Id: IpParGenMatrix.hpp 1460 2009-05-29 02:34:47Z andreasw \$
6//
7// Authors:  Sanjeeb Dash, Andreas Waechter     IBM    2009-05-29
8
9#ifndef __IPPARGENMATRIX_HPP__
10#define __IPPARGENMATRIX_HPP__
11
12#include "IpUtils.hpp"
13#include "IpParVector.hpp"
14#include "TMatrices/IpGenTMatrix.hpp"
15#include <vector>
16
17namespace Ipopt
18{
19
20  /* forward declarations */
21  class ParGenMatrixSpace;
22
23  /** Class of parallel general matrices. A ParGenMatrix consists of a matrix whose
24   *  rows are partitioned across the universe of processors (assume n in number).
25   *  Each processor is responsible for its piece of the entire matrix,
26   *  and for manipulating this piece. All ParGenMatrix functions are assumed
27   *  to be executed simultaneously at each of the n processors. This class
28   *  does not support the functionality of a matrix being partitioned across
29   *  a subset of processors. Thus if the number of rows of the ParGenMatrix is less
30   *  than n, some processor (say k) will not have any rows of the matrix.
31   *  Yet a function to be executed on a ParGenMatrix must also be executed in
32   *  processor k. As an example, if the maximum element of a column of a ParGenMatrix
33   *  is to be computed, each processor finds the maximum element of its piece of
34   *  the column, and then uses MPI calls to find the global maximum.
35   *
36   *  The rows of a ParGenMatrix have the same numbering convention as a GenTMatrix,
37   *  i.e., the rows are numbered from 1. A ParGenMatrix stores the piece of the matrix
38   *  on a processor as a GenTMatrix. Therefore the collection of row numbers on a
39   *  processor need to be passed relative to the starting row number. For example,
40   *  if the part of the matrix in a processor consists of rows 15-20, then the row
41   *  numbers 15 - 20 should be specified as row 1, 2, .., 5.
42   */
43  class ParGenMatrix : public Matrix
44  {
45  public:
46    /**@name Constructors/Destructors */
47    //@{
48    /** Constructor, given the corresponding ParGenMatrixSpace.
49     */
50    ParGenMatrix(const ParGenMatrixSpace* owner_space);
51
52    /** Default destructor */
53    virtual ~ParGenMatrix();
54    //@}
55
56    /** @name Additional public methods not in Matrix base class. */
57    //@{
58    /** Create a new ParGenMatrix from same MatrixSpace */
59    SmartPtr<ParGenMatrix> MakeNewParGenMatrix() const;
60
61    /** Obtain pointer to local matrix.
62     */
63    inline GenTMatrix* LocalMatrix()
64    {
65      ObjectChanged();
66      return GetRawPtr(local_matrix_);
67    }
68
69    /** Obtain pointer to const local matrix.
70     */
71    inline const GenTMatrix* LocalMatrix() const
72    {
73      return GetRawPtr(local_matrix_);
74    }
75
76    /* Extract the local part from a global matrix into the data of
77       this matrix. */
78    void ExtractLocalMatrix(const GenTMatrix& global_matrix);
79
80    //@}
81
82  protected:
83    /**@name Overloaded methods from Matrix base class*/
84    //@{
85    virtual void MultVectorImpl(Number alpha, const Vector &x, Number beta,
86                                Vector &y) const;
87
88    virtual void TransMultVectorImpl(Number alpha, const Vector& x,
89                                     Number beta, Vector& y) const;
90
91    /** Method for determining if all stored numbers are valid (i.e.,
92     *  no Inf or Nan). */
93    virtual bool HasValidNumbersImpl() const;
94
95    virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
96
97    virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const;
98
99    virtual void PrintImpl(const Journalist& jnlst,
100                           EJournalLevel level,
101                           EJournalCategory category,
102                           const std::string& name,
103                           Index indent,
104                           const std::string& prefix) const;
105    //@}
106
107  private:
108    /**@name Default Compiler Generated Methods
109     * (Hidden to avoid implicit creation/calling).
110     * These methods are not implemented and
111     * we do not want the compiler to implement
112     * them for us, so we declare them private
113     * and do not define them. This ensures that
114     * they will not be implicitly created/called.
115     */
116    //@{
117    /** Default Constructor */
118    ParGenMatrix();
119
120    /** Copy Constructor */
121    ParGenMatrix(const ParGenMatrix&);
122
123    /** Overloaded Equals Operator */
124    void operator=(const ParGenMatrix&);
125    //@}
126
127    /** Rank of the processor handling this vector */
128    int Rank() const;
129
130    /** Total number of processors. */
131    int NumProc() const;
132
133    /** number of rows of local matrix */
134    int LocalRows() const;
135
136    /** Copy of the owner_space ptr as a ParGenMatrixSpace instead
137     *  of a MatrixSpace
138     */
139    const ParGenMatrixSpace* owner_space_;
140
141    /** local piece of ParGenMatrix stored as a GenTMatrix */
142    SmartPtr<GenTMatrix> local_matrix_;
143  };
144
145  /** This matrix space is the matrix space for ParGenMatrix.
146   *  Before a ParGenMatrix can be created, all information relevant to
147   *  a ParGenMatrix, such as dimension of the space, and the range of
148   *  indices on the current processor have to be set in the ParGenMatrixSpace.
149   */
150  class ParGenMatrixSpace : public MatrixSpace
151  {
152  public:
153    /** @name Constructors/Destructors. */
154    //@{
155    /** Constructor, has to be given the total ndimension of the matrix space
156     *  and the local range of contiguous rows + local matrix space information */
157    ParGenMatrixSpace(SmartPtr<const ParVectorSpace> RowVectorSpace, Index nCols,
158                      Index nonZeros,
159                      const Index* iRows, const Index* jCols);
160
161
162    /** Destructor */
163    ~ParGenMatrixSpace()
164    {}
165    //@}
166
167    /** Method for creating a new matrix of this specific type. */
168    virtual ParGenMatrix* MakeNewParGenMatrix() const
169    {
170      return new ParGenMatrix(this);
171    }
172
173    /** Overloaded MakeNew method for the MatrixSpace base class.
174     */
175    virtual Matrix* MakeNew() const
176    {
177      return MakeNewParGenMatrix();
178    }
179
180    SmartPtr<const ParVectorSpace> getRowVectorSpace() const
181    {
182      return rowVectorSpace_;
183    }
184
185    SmartPtr<GenTMatrixSpace> getLocalSpace() const
186    {
187      return local_space_;
188    }
189
190    int getStartPos() const
191    {
192      return rowVectorSpace_->getStartPos();
193    }
194
195    const std::vector<int> & RecvCounts() const
196    {
197      return rowVectorSpace_->RecvCounts();
198    }
199
200    const std::vector<int> & Displs() const
201    {
202      return rowVectorSpace_->Displs();
203    }
204
205    int LocalRows() const
206    {
207      return rowVectorSpace_->LocalSize();
208    }
209
210    int Rank() const
211    {
212      return rowVectorSpace_->Rank();
213    }
214
215    int NumProc() const
216    {
217      return rowVectorSpace_->NumProc();
218    }
219
220  private:
221    SmartPtr<const ParVectorSpace> rowVectorSpace_;
222    SmartPtr<GenTMatrixSpace> local_space_;
223  };
224
225  inline
226  SmartPtr<ParGenMatrix> ParGenMatrix::MakeNewParGenMatrix() const
227  {
228    return owner_space_->MakeNewParGenMatrix();
229  }
230
231  inline
232  int ParGenMatrix::Rank() const
233  {
234    return owner_space_->Rank();
235  }
236
237  inline
238  int ParGenMatrix::NumProc() const
239  {
240    return owner_space_->NumProc();
241  }
242
243  inline
244  int ParGenMatrix::LocalRows() const
245  {
246    return owner_space_->LocalRows();
247  }
248
249} // namespace Ipopt
250
251#endif
Note: See TracBrowser for help on using the repository browser.