27 target->getMatrixGraph()->getRowSpace();
28 MPI_Comm comm = vspace->getCommunicator();
29 int numLocal =
reducer_->getLocalReducedEqns().size();
33 if (target_core == NULL) {
34 throw std::runtime_error(
"fei::MatrixReducer ERROR, target matrix not dynamic_cast-able to fei::Matrix_core.");
47 return(
target_->parameters(paramset));
53 target_->setMatrixGraph(matrixGraph);
59 return(
target_->getMatrixGraph()->getRowSpace()->getGlobalNumIndices());
65 return(
target_->getMatrixGraph()->getRowSpace()->getNumIndices_Owned());
69{
return(
target_->putScalar(scalar)); }
76 osstr <<
"fei::MatrixReducer::getRowLength ERROR, row="<<row<<
" is a slave eqn. You can't get a slave row from the reduced matrix.";
77 throw std::runtime_error(osstr.str());
80 int reducedrow =
reducer_->translateToReducedEqn(row);
81 return(
target_->getRowLength(reducedrow, length));
89 osstr <<
"fei::MatrixReducer::copyOutRow ERROR, requested row ("<<row
90 <<
") is a slave eqn. You can't get a slave row from the reduced matrix.";
91 throw std::runtime_error(osstr.str());
94 int reducedrow =
reducer_->translateToReducedEqn(row);
95 int err =
target_->copyOutRow(reducedrow, len, coefs, indices);
96 for(
int i=0; i<len; ++i) {
97 indices[i] =
reducer_->translateFromReducedEqn(indices[i]);
104 int numCols,
const int* cols,
105 const double*
const* values,
108 int err =
reducer_->addMatrixValues(numRows, rows, numCols, cols,
109 values,
true, *
target_, format);
115 int numCols,
const int* cols,
116 const double*
const* values,
119 int err =
reducer_->addMatrixValues(numRows, rows, numCols, cols,
120 values,
false, *
target_, format);
129 const double*
const* data,
133 target_->getMatrixGraph()->getRowSpace();
135 target_->getMatrixGraph()->getColSpace();
137 unsigned fieldSize = rowSpace->getFieldSize(fieldID);
138 std::vector<int> indices(fieldSize*2);
139 int* rowIndices = &indices[0];
140 int* colIndices = rowIndices+fieldSize;
142 rowSpace->getGlobalIndices(1, &rowID, idType, fieldID, rowIndices);
143 colSpace->getGlobalIndices(1, &colID, idType, fieldID, colIndices);
146 throw std::runtime_error(
"MatrixReducer: bad format");
149 int err =
reducer_->addMatrixValues(fieldSize, rowIndices,
150 fieldSize, colIndices,
164 target_->getMatrixGraph()->getRowSpace();
166 unsigned fieldSize = rowSpace->getFieldSize(fieldID);
168 std::vector<const double*> data_2d(fieldSize);
169 for(
unsigned i=0; i<fieldSize; ++i) {
170 data_2d[i] = &data[i*fieldSize];
173 return(
sumInFieldData(fieldID, idType, rowID, colID, &data_2d[0], format));
178 const double*
const* values,
182 int numRowIndices, numColIndices, dummy;
183 matGraph->getConnectivityNumIndices(blockID, numRowIndices, numColIndices);
185 std::vector<int> indices(numRowIndices+numColIndices);
186 int* rowIndices = &indices[0];
187 int* colIndices = rowIndices+numRowIndices;
189 matGraph->getConnectivityIndices(blockID, connectivityID,
190 numRowIndices, rowIndices, dummy,
191 numColIndices, colIndices, dummy);
193 return(
sumIn(numRowIndices, rowIndices, numColIndices, colIndices,
201 return(
target_->globalAssemble());
205{
return(
target_->multiply(x, y)); }
211 return(
target_->gatherFromOverlap(accumulate));
215 bool matrixMarketFormat)
217 static char mmbanner[] =
"%%MatrixMarket matrix coordinate real general";
218 std::vector<int>& localrows =
reducer_->getLocalReducedEqns();
219 int localNumRows = localrows.size();
224 for(
int i=0; i<localNumRows; ++i) {
233 int globalNumRows = 0;
236 int globalNumCols = globalNumRows;
246 if (matrixMarketFormat) {
248 ofs <<globalNumRows<<
" " <<globalNumCols<<
" " <<globalNNZ<<
FEI_ENDL;
251 ofs <<globalNumRows<<
" " <<globalNumCols<<
FEI_ENDL;
257 outFile->precision(13);
261 std::vector<int> work_indices;
262 std::vector<double> work_data1D;
264 for(
int i=0; i<localNumRows; ++i) {
265 int row = localrows[i];
268 work_indices.resize(rowLength);
269 work_data1D.resize(rowLength);
271 int* indPtr = &work_indices[0];
272 double* coefPtr = &work_data1D[0];
276 for(
int j=0; j<rowLength; ++j) {
277 if (matrixMarketFormat) {
278 ofs << row+1 <<
" "<<indPtr[j]+1<<
" "<<coefPtr[j]<<
FEI_ENDL;
281 ofs << row <<
" "<<indPtr[j]<<
" "<<coefPtr[j]<<
FEI_ENDL;
293 bool matrixMarketFormat)
295 return(
target_->writeToStream(ostrm, matrixMarketFormat));
302{
return(
target_->changedSinceMark()); }
virtual fei::SharedPtr< fei::VectorSpace > getRowSpace()=0
bool globalAssembleCalled_
int writeToStream(FEI_OSTREAM &ostrm, bool matrixMarketFormat=true)
int putScalar(double scalar)
int getRowLength(int row, int &length) const
MatrixReducer(fei::SharedPtr< fei::Reducer > reducer, fei::SharedPtr< fei::Matrix > target)
int copyIn(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, int format=0)
void setMatrixGraph(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
int multiply(fei::Vector *x, fei::Vector *y)
int gatherFromOverlap(bool accumulate=true)
int writeToFile(const char *filename, bool matrixMarketFormat=true)
int sumIn(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, int format=0)
int copyOutRow(int row, int len, double *coefs, int *indices) const
int sumInFieldData(int fieldID, int idType, int rowID, int colID, const double *const *data, int format=0)
int getGlobalNumRows() const
int getLocalNumRows() const
fei::SharedPtr< fei::Reducer > reducer_
fei::SharedPtr< fei::MatrixGraph > getMatrixGraph() const
fei::SharedPtr< fei::Matrix > target_
int parameters(const fei::ParameterSet ¶mset)
void setEqnComm(fei::SharedPtr< fei::EqnComm > eqnComm)
MPI_Comm getCommunicator() const
#define FEI_OSTRINGSTREAM
int localProc(MPI_Comm comm)
int numProcs(MPI_Comm comm)
int GlobalSum(MPI_Comm comm, std::vector< T > &local, std::vector< T > &global)
void Barrier(MPI_Comm comm)