/usr/include/trilinos/MLAPI_DistributedMatrix.h is in libtrilinos-ml-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | #ifndef MLAPI_DISTRIBUTEDMATRIX_H
#define MLAPI_DISTRIBUTEDMATRIX_H
/*!
\file MLAPI_DistributedMatrix.h
\brief MLAPI wrapper for Epetra_FECrsMatrix, which allows MATLAB-like syntax.
\author Marzio Sala, D-INFK/ETHZ.
\date Last updated on Mar-06.
*/
/* ******************************************************************** */
/* See the file COPYRIGHT for a complete copyright notice, contact */
/* person and disclaimer. */
/* ******************************************************************** */
#include "ml_common.h"
#include "MLAPI_Error.h"
#include "MLAPI_Operator.h"
#include "MLAPI_Space.h"
#include "MLAPI_BaseLinearCombination.h"
#include "Epetra_Map.h"
#include "Epetra_FECrsMatrix.h"
namespace MLAPI {
class DistributedMatrix : public Epetra_RowMatrix, public Operator {
public:
DistributedMatrix(const Space& RowSpace, const Space& ColSpace)
{
FillCompleted_ = false;
RowSpace_ = RowSpace;
ColSpace_ = ColSpace;
int locNumMyRows = RowSpace_.GetNumMyElements();
int locNumMyCols = ColSpace_.GetNumMyElements();
// FIXME: add MyGlobalElements()
RangeMap_ = new Epetra_Map(-1, locNumMyRows, 0, GetEpetra_Comm());
DomainMap_ = new Epetra_Map(-1, locNumMyCols, 0, GetEpetra_Comm());
Matrix_ = new Epetra_FECrsMatrix(Copy, *RangeMap_, 0);
}
virtual int NumMyRowEntries(int MyRow, int& NumEntries) const
{
ML_RETURN(Matrix_->NumMyRowEntries(MyRow, NumEntries));
}
virtual int MaxNumEntries() const
{
return(Matrix_->MaxNumEntries());
}
virtual int ExtractMyRowCopy(int MyRow, int Length, int & NumEntries,
double* Values, int* Indices) const
{
ML_RETURN(Matrix_->ExtractMyRowCopy(MyRow, Length, NumEntries,
Values, Indices));
}
virtual int ExtractDiagonalCopy(Epetra_Vector & Diagonal) const
{
ML_RETURN(Matrix_->ExtractDiagonalCopy(Diagonal));
}
virtual int Multiply(bool TransA, const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
ML_RETURN(Matrix_->Multiply(TransA, X, Y));
}
virtual int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
ML_RETURN(Matrix_->Solve(Upper, Trans, UnitDiagonal, X, Y));
}
virtual int InvRowSums(Epetra_Vector& x) const
{
ML_RETURN(Matrix_->InvRowSums(x));
}
virtual int LeftScale(const Epetra_Vector& x)
{
ML_RETURN(Matrix_->LeftScale(x));
}
virtual int InvColSums(Epetra_Vector& x) const
{
ML_RETURN(Matrix_->InvColSums(x));
}
virtual int RightScale(const Epetra_Vector& x)
{
ML_RETURN(Matrix_->RightScale(x));
}
virtual bool Filled() const
{
return(Matrix_->Filled());
}
virtual double NormInf() const
{
return(Matrix_->NormInf());
}
virtual double NormOne() const
{
return(Matrix_->NormOne());
}
#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
virtual int NumGlobalNonzeros() const
{
return(Matrix_->NumGlobalNonzeros());
}
virtual int NumGlobalRows() const
{
return(Matrix_->NumGlobalRows());
}
virtual int NumGlobalCols() const
{
return(Matrix_->NumGlobalCols());
}
virtual int NumGlobalDiagonals() const
{
return(Matrix_->NumGlobalDiagonals());
}
#endif
virtual long long NumGlobalNonzeros64() const
{
return(Matrix_->NumGlobalNonzeros64());
}
virtual long long NumGlobalRows64() const
{
return(Matrix_->NumGlobalRows64());
}
virtual long long NumGlobalCols64() const
{
return(Matrix_->NumGlobalCols64());
}
virtual long long NumGlobalDiagonals64() const
{
return(Matrix_->NumGlobalDiagonals64());
}
virtual int NumMyNonzeros() const
{
return(Matrix_->NumMyNonzeros());
}
virtual int NumMyRows() const
{
return(Matrix_->NumMyRows());
}
virtual int NumMyCols() const
{
return(Matrix_->NumMyCols());
}
virtual int NumMyDiagonals() const
{
return(Matrix_->NumMyDiagonals());
}
virtual bool LowerTriangular() const
{
return(Matrix_->LowerTriangular());
}
virtual bool UpperTriangular() const
{
return(Matrix_->UpperTriangular());
}
virtual const Epetra_Map & RowMatrixRowMap() const
{
return(Matrix_->RowMatrixRowMap());
}
virtual const Epetra_Map & RowMatrixColMap() const
{
return(Matrix_->RowMatrixColMap());
}
virtual const Epetra_Import * RowMatrixImporter() const
{
return(Matrix_->RowMatrixImporter());
}
virtual const Epetra_Map& OperatorDomainMap() const
{
return(Matrix_->OperatorDomainMap());
}
virtual const Epetra_Map& OperatorRangeMap() const
{
return(Matrix_->OperatorRangeMap());
}
virtual const Epetra_Map& Map() const
{
return(Matrix_->RowMatrixRowMap());
}
//@}
virtual int SetUseTranspose(bool what)
{
return(Matrix_->SetUseTranspose(what));
}
int Apply(const MultiVector& X, MultiVector& Y) const
{
return(Operator::Apply(X, Y));
}
virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (!IsFillCompleted())
ML_THROW("Matrix not yet FillComplete()'d", -1);
return(Matrix_->Apply(X, Y));
}
virtual int ApplyInverse(const Epetra_MultiVector& X,
Epetra_MultiVector& Y) const
{
if (!IsFillCompleted())
ML_THROW("Matrix not yet FillComplete()'d", -1);
return(Matrix_->ApplyInverse(X, Y));
}
virtual const char* Label() const
{
return(Matrix_->Label());
}
virtual bool UseTranspose() const
{
return(Matrix_->UseTranspose());
}
virtual bool HasNormInf() const
{
return(Matrix_->HasNormInf());
}
virtual const Epetra_Comm& Comm() const
{
return(Matrix_->Comm());
}
std::ostream& Print(std::ostream& os, const bool verbose = true) const;
Space GetDomainSpace() const
{
return(ColSpace_);
}
Space GetRangeSpace() const
{
return(RowSpace_);
}
inline double& operator()(const int GRID, const int GCID)
{
if (IsFillCompleted())
{
ML_THROW("Matrix already FillCompleted()'d", -1);
}
else
{
rows_.push_back(GRID);
cols_.push_back(GCID);
vals_.push_back(0.0);
return(vals_[vals_.size() - 1]);
}
}
inline void ReplaceElement(const int GRID, const int GCID,
const double value)
{
if (!IsFillCompleted())
ML_THROW("Matrix not FillCompleted()'d yet", -1);
int LRID = RangeMap_->LID(GRID);
int LCID = Matrix_->ColMap().LID(GCID);
if (Matrix_->ReplaceMyValues((int)LRID, 1, (double*)&value,
(int*)&LCID) < 0)
ML_THROW("Can only replace locally owned elements", -1);
}
void FillComplete()
{
// populate the matrix here
for (unsigned int i = 0 ; i < vals_.size() ; ++i)
{
int GRID = rows_[i];
int GCID = cols_[i];
double value = vals_[i];
if (Matrix_->ReplaceGlobalValues(1, &GRID, 1, &GCID, &value) > 0)
Matrix_->InsertGlobalValues(1, &GRID, 1, &GCID, &value);
}
rows_.resize(0);
cols_.resize(0);
vals_.resize(0);
// freeze the matrix
if (Matrix_->GlobalAssemble())
ML_THROW("Error in GlobalAssemble()", -1);
if (Matrix_->FillComplete(*DomainMap_, *RangeMap_))
ML_THROW("Error in FillComplete()", -1);
FillCompleted_ = true;
Reshape(ColSpace_, RowSpace_, Matrix_, true);
}
bool IsFillCompleted() const
{
return(FillCompleted_);
}
private:
DistributedMatrix(const DistributedMatrix& rhs)
{
}
DistributedMatrix& operator=(const DistributedMatrix& rhs)
{
return(*this);
}
mutable std::vector<int> rows_;
mutable std::vector<int> cols_;
mutable std::vector<double> vals_;
Epetra_FECrsMatrix* Matrix_;
Space ColSpace_;
Space RowSpace_;
Epetra_Map* DomainMap_;
Epetra_Map* RangeMap_;
bool FillCompleted_;
}; // class DistributedMatrix
} // namespace MLAPI
#endif // ifndef MLAPI_DISTRIBUTEDMATRIX_H
|