int setMatrixStructure() { //only set the matrix matrixGraph once. if (setMatrixStructure_) return(0); if (matrixGraph_.get() == NULL) return(-1); lookup_ = new fei::Lookup_Impl(matrixGraph_, 0); CHK_ERR( linsyscore_->setLookup(*lookup_) ); CHK_ERR( setGlobalOffsets() ); MPI_Comm comm = matrixGraph_->getRowSpace()->getCommunicator(); fei::SharedPtr<fei::SparseRowGraph> localSRGraph = matrixGraph_->createGraph(blockMatrix_); std::vector<int>& rowNumbers = localSRGraph->rowNumbers; int numLocalRows = rowNumbers.size(); int* rowOffsets = &(localSRGraph->rowOffsets[0]); int numLocalNonzeros = localSRGraph->packedColumnIndices.size(); int* nonzeros = &(localSRGraph->packedColumnIndices[0]); int numGlobalNonzeros = 0; fei::GlobalSum(comm, numLocalNonzeros, numGlobalNonzeros); std::vector<int*> colPtrs(numLocalRows); std::vector<int> ptRowsPerBlkRow(numLocalRows, 1); std::vector<int> rowLengths(numLocalRows); int* rowLengthsPtr = &rowLengths[0]; for(int i=0; i<numLocalRows; ++i) { colPtrs[i] = &(nonzeros[rowOffsets[i]]); rowLengthsPtr[i] = rowOffsets[i+1]-rowOffsets[i]; if (blockMatrix_ == true) { ptRowsPerBlkRow[i] = lookup_->getBlkEqnSize(rowNumbers[i]); } } CHK_ERR( linsyscore_->setMatrixStructure(&colPtrs[0], rowLengthsPtr, &colPtrs[0], rowLengthsPtr, &ptRowsPerBlkRow[0])); setMatrixStructure_ = true; return(0); }
int test_AztecWrappers::test1() { #ifdef HAVE_FEI_AZTECOO int localSize = 3, globalSize = localSize*numProcs_; int localOffset = localSize*localProc_; int i; std::vector<int> update(localSize); for(i=0; i<localSize; i++) update[i] = localOffset+i; fei::SharedPtr<fei_trilinos::Aztec_Map> map( new fei_trilinos::Aztec_Map(globalSize, localSize, &update[0], localOffset, comm_)); fei_trilinos::AztecDMSR_Matrix* matrix = new fei_trilinos::AztecDMSR_Matrix(map); std::vector<int> elemrows(localSize); std::vector<int> elemcols(globalSize); double** elemcoefs = new double*[localSize]; for(int j=0; j<globalSize; ++j) elemcols[j] = j; for(i=0; i<localSize; ++i) { elemrows[i] = localOffset+i; elemcoefs[i] = new double[globalSize]; for(int j=0; j<globalSize; ++j) { elemcoefs[i][j] = (double)(localOffset+i+j); } } std::vector<std::vector<int> > colIndices(localSize); std::vector<std::vector<double> > values(localSize); std::vector<int> rowLengths(localSize); std::vector<int*> colPtrs(localSize); int nnzeros = 0; for(i=0; i<localSize; i++) { int diagEntry = 0; int row = i+localOffset; for(int j=0; j<globalSize; j++) { int col = j; if (col == row) diagEntry = 1; colIndices[i].push_back(col); values[i].push_back((double)(row+col)); } rowLengths[i] = colIndices[i].size() - diagEntry; nnzeros += rowLengths[i] + 1; colPtrs[i] = &(colIndices[i][0]); } matrix->allocate( &rowLengths[0] ); if (!(matrix->isAllocated())) { ERReturn(-1); } if (matrix->getNumNonZeros() != nnzeros) { ERReturn(-1); } CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values, true) ); int* rowinds = &elemrows[0]; int* colinds = &elemcols[0]; CHK_ERR( matrix->sumIntoRow(localSize, rowinds, globalSize, colinds, elemcoefs) ); for(i=0; i<localSize; ++i) { for(int j=0; j<globalSize; ++j) values[i][j] *= 2.0; } CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); for(i=0; i<localSize; ++i) { for(int j=0; j<globalSize; ++j) values[i][j] /= 2.0; } CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values, false) ); CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); if (matrix->writeToFile("A_Az_notFilled.mtx") != true) { ERReturn(-1); } if (matrix->readFromFile("A_Az_notFilled.mtx") != true) { ERReturn(-1); } CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); matrix->fillComplete(); if (!(matrix->isFilled())) { ERReturn(-1); } if (matrix->writeToFile("A_Az_filled.mtx") != true) { ERReturn(-1); } CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values, false) ); CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); matrix->put(0.0); CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values, true) ); CHK_ERR( matrix->sumIntoRow(localSize, rowinds, globalSize, colinds, elemcoefs) ); for(i=0; i<localSize; ++i) { for(int j=0; j<globalSize; ++j) values[i][j] *= 2.0; delete [] elemcoefs[i]; } delete [] elemcoefs; CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); if (matrix->writeToFile("A_Az_filled2.mtx") != true) { ERReturn(-1); } if (matrix->readFromFile("A_Az_filled2.mtx") != true) { ERReturn(-1); } CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) ); delete matrix; #endif return(0); }
int test_Algebraic::serialtest2() { int i, numRows = 10; fei::SharedPtr<fei::VectorSpace> vspace(new fei::VectorSpace(comm_)); int idType = 0; vspace->defineIDTypes(1, &idType); std::vector<int> rowNumbers(numRows); for(i=0; i<numRows; ++i) { rowNumbers[i] = i; } CHK_ERR( vspace->addDOFs(idType, numRows, &rowNumbers[0]) ); CHK_ERR( vspace->initComplete() ); int index = -1; CHK_ERR( vspace->getGlobalIndex(idType, rowNumbers[3], index) ); if (index != 3) { ERReturn(-1); } int numDOF = vspace->getNumDegreesOfFreedom(idType, rowNumbers[3]); if (numDOF != 1) { ERReturn(-1); } std::vector<int> globalOffsets; vspace->getGlobalIndexOffsets(globalOffsets); if (globalOffsets[0] != 0) { ERReturn(-1); } if (globalOffsets[1] != numRows) { ERReturn(-1); } fei::SharedPtr<fei::VectorSpace> dummy; fei::MatrixGraph_Impl2 mgraph(vspace, dummy); std::vector<int> rowLengths(numRows); std::vector<int> packedColumnIDs(numRows); std::vector<int*> columnIDs(numRows); for(i=0; i<numRows; ++i) { rowLengths[i] = 1; packedColumnIDs[i] = i; columnIDs[i] = &(packedColumnIDs[i]); } CHK_ERR( mgraph.initConnectivity(idType, numRows, &rowNumbers[0], &rowLengths[0], &columnIDs[0]) ); CHK_ERR( mgraph.initComplete() ); fei::SharedPtr<fei::SparseRowGraph> localgraph = mgraph.createGraph(false); int mnumRows = localgraph->rowNumbers.size(); int* mrowOffsets = &(localgraph->rowOffsets[0]); int mnumNonzeros = localgraph->packedColumnIndices.size(); int* mpackedColumnIndices = &(localgraph->packedColumnIndices[0]); if (mnumRows != numRows) { ERReturn(-1); } if (mnumNonzeros != numRows) { ERReturn(-1); } for(i=0; i<numRows; ++i) { if ((mrowOffsets[i+1]-mrowOffsets[i]) != 1) { ERReturn(-1); } if (mpackedColumnIndices[i] != packedColumnIDs[i]) { ERReturn(-1); } } return(0); }