19 #ifdef HAVE_FEI_AZTECOO
26 #define fei_file "test_AztecWrappers.cpp"
30 #ifdef HAVE_FEI_AZTECOO
31 int compare_DMSR_contents(fei_trilinos::AztecDMSR_Matrix& matrix,
int localOffset,
32 std::vector<std::vector<int> >& colIndices,
33 std::vector<std::vector<double> >& values);
35 int fill_DMSR(fei_trilinos::AztecDMSR_Matrix& matrix,
int localOffset,
36 std::vector<std::vector<int> >& colIndices,
37 std::vector<std::vector<double> >& values,
bool sumInto);
69 #ifdef HAVE_FEI_AZTECOO
70 int localSize = 3, globalSize = localSize*
numProcs_;
74 std::vector<int> update(localSize);
75 for(i=0; i<localSize; i++) update[i] = localOffset+i;
80 fei_trilinos::AztecDMSR_Matrix* matrix =
new fei_trilinos::AztecDMSR_Matrix(map);
82 std::vector<int> elemrows(localSize);
83 std::vector<int> elemcols(globalSize);
84 double** elemcoefs =
new double*[localSize];
85 for(
int j=0; j<globalSize; ++j) elemcols[j] = j;
86 for(i=0; i<localSize; ++i) {
87 elemrows[i] = localOffset+i;
88 elemcoefs[i] =
new double[globalSize];
89 for(
int j=0; j<globalSize; ++j) {
90 elemcoefs[i][j] = (double)(localOffset+i+j);
94 std::vector<std::vector<int> > colIndices(localSize);
95 std::vector<std::vector<double> > values(localSize);
96 std::vector<int> rowLengths(localSize);
97 std::vector<int*> colPtrs(localSize);
100 for(i=0; i<localSize; i++) {
102 int row = i+localOffset;
103 for(
int j=0; j<globalSize; j++) {
105 if (col == row) diagEntry = 1;
106 colIndices[i].push_back(col);
107 values[i].push_back((
double)(row+col));
109 rowLengths[i] = colIndices[i].size() - diagEntry;
110 nnzeros += rowLengths[i] + 1;
111 colPtrs[i] = &(colIndices[i][0]);
114 matrix->allocate( &rowLengths[0] );
116 if (!(matrix->isAllocated())) {
120 if (matrix->getNumNonZeros() != nnzeros) {
124 CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values,
true) );
126 int* rowinds = &elemrows[0];
127 int* colinds = &elemcols[0];
129 CHK_ERR( matrix->sumIntoRow(localSize, rowinds, globalSize, colinds, elemcoefs) );
131 for(i=0; i<localSize; ++i) {
132 for(
int j=0; j<globalSize; ++j) values[i][j] *= 2.0;
135 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
137 for(i=0; i<localSize; ++i) {
138 for(
int j=0; j<globalSize; ++j) values[i][j] /= 2.0;
141 CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values,
false) );
143 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
145 if (matrix->writeToFile(
"A_Az_notFilled.mtx") !=
true) {
149 if (matrix->readFromFile(
"A_Az_notFilled.mtx") !=
true) {
153 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
155 matrix->fillComplete();
157 if (!(matrix->isFilled())) {
161 if (matrix->writeToFile(
"A_Az_filled.mtx") !=
true) {
165 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
167 CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values,
false) );
169 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
173 CHK_ERR( fill_DMSR(*matrix, localOffset, colIndices, values,
true) );
175 CHK_ERR( matrix->sumIntoRow(localSize, rowinds, globalSize, colinds, elemcoefs) );
177 for(i=0; i<localSize; ++i) {
178 for(
int j=0; j<globalSize; ++j) values[i][j] *= 2.0;
179 delete [] elemcoefs[i];
183 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
185 if (matrix->writeToFile(
"A_Az_filled2.mtx") !=
true) {
189 if (matrix->readFromFile(
"A_Az_filled2.mtx") !=
true) {
193 CHK_ERR( compare_DMSR_contents(*matrix, localOffset, colIndices, values) );
215 #ifdef HAVE_FEI_AZTECOO
217 int compare_DMSR_contents(fei_trilinos::AztecDMSR_Matrix& matrix,
int localOffset,
218 std::vector<std::vector<int> >& colIndices,
219 std::vector<std::vector<double> >& values)
221 int localSize = colIndices.size();
223 for(
int i=0; i<localSize; i++) {
224 int row = i+localOffset;
225 int rowLen = matrix.rowLength(row);
227 int* tempInd =
new int[rowLen];
228 double* tempVal =
new double[rowLen];
229 std::vector<int> sortedInd;
230 std::vector<double> sortedVal;
233 matrix.getRow(row, tmpLen, tempVal, tempInd);
236 for(
int j=0; j<tmpLen; j++) {
239 sortedVal.insert(sortedVal.begin()+offset, tempVal[j]);
245 std::vector<int>& colInds = colIndices[i];
246 if (sortedInd != colInds) {
249 std::vector<double>& vals = values[i];
250 if (sortedVal != vals) {
259 int fill_DMSR(fei_trilinos::AztecDMSR_Matrix& matrix,
int localOffset,
260 std::vector<std::vector<int> >& colIndices,
261 std::vector<std::vector<double> >& values,
bool sumInto)
263 int localSize = colIndices.size();
265 for(
int i=0; i<localSize; i++) {
266 int row = localOffset + i;
267 int rowLen = values[i].size();
270 CHK_ERR( matrix.sumIntoRow(row, rowLen,
271 &(values[i][0]), &(colIndices[i][0])) );
274 CHK_ERR( matrix.putRow(row, rowLen,
275 &(values[i][0]), &(colIndices[i][0])) );
int sortedListInsert(const T &item, std::vector< T > &list)
virtual ~test_AztecWrappers()
test_AztecWrappers(MPI_Comm comm)