10 #ifndef __MATRIXMARKET_TPETRA_NEW_HPP
11 #define __MATRIXMARKET_TPETRA_NEW_HPP
32 template <
typename global_ordinal_type,
typename scalar_type>
34 Teuchos::RCP<Distribution<global_ordinal_type,scalar_type> >
36 std::string &distribution,
40 const Teuchos::ParameterList ¶ms,
41 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm
48 int me = comm->getRank();
50 using basedist_t = Distribution<global_ordinal_type,scalar_type>;
53 bool randomize =
false;
55 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"randomize");
57 randomize = pe->getValue<
bool>(&randomize);
60 std::string partitionFile =
"";
62 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"partitionFile");
64 partitionFile = pe->getValue<std::string>(&partitionFile);
67 if (distribution ==
"2D") {
68 if (partitionFile !=
"") {
70 TEUCHOS_TEST_FOR_EXCEPTION(randomize, std::logic_error,
71 "Randomization not available for 2DVec distributions.");
72 Distribution2DVec<global_ordinal_type,scalar_type> *dist =
73 new Distribution2DVec<global_ordinal_type, scalar_type>(
74 nRow, comm, params, partitionFile);
75 retval =
dynamic_cast<basedist_t *
>(dist);
79 Distribution2DRandom<global_ordinal_type,scalar_type> *dist =
80 new Distribution2DRandom<global_ordinal_type,scalar_type>(
82 retval =
dynamic_cast<basedist_t *
>(dist);
87 Distribution2DLinear<global_ordinal_type,scalar_type> *dist =
88 new Distribution2DLinear<global_ordinal_type,scalar_type>(
90 retval =
dynamic_cast<basedist_t *
>(dist);
93 else if (distribution ==
"1D") {
94 if (partitionFile !=
"") {
96 Distribution1DVec<global_ordinal_type,scalar_type> *dist =
97 new Distribution1DVec<global_ordinal_type,scalar_type>(
98 nRow, comm, params, partitionFile);
99 retval =
dynamic_cast<basedist_t*
>(dist);
101 else if (randomize) {
103 Distribution1DRandom<global_ordinal_type,scalar_type> *dist =
104 new Distribution1DRandom<global_ordinal_type,scalar_type>(
106 retval =
dynamic_cast<basedist_t *
>(dist);
110 Distribution1DLinear<global_ordinal_type,scalar_type> *dist =
111 new Distribution1DLinear<global_ordinal_type,scalar_type>(
113 retval =
dynamic_cast<basedist_t *
>(dist);
116 else if (distribution ==
"LowerTriangularBlock") {
117 if (randomize && me == 0) {
118 std::cout <<
"WARNING: Randomization not available for "
119 <<
"LowerTriangularBlock distributions." << std::endl;
122 DistributionLowerTriangularBlock<global_ordinal_type,scalar_type> *dist =
123 new DistributionLowerTriangularBlock<global_ordinal_type,scalar_type>(
125 retval =
dynamic_cast<basedist_t*
>(dist);
127 else if (distribution ==
"MMFile") {
129 if (randomize && me == 0) {
130 std::cout <<
"WARNING: Randomization not available for MMFile "
131 <<
"distributions." << std::endl;
133 DistributionMMFile<global_ordinal_type,scalar_type> *dist =
134 new DistributionMMFile<global_ordinal_type,scalar_type>(
136 retval =
dynamic_cast<basedist_t*
>(dist);
140 std::cout <<
"ERROR: Invalid distribution method " << distribution
144 return Teuchos::rcp<basedist_t>(retval);
150 const std::string &filename,
151 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
152 const Teuchos::ParameterList ¶ms,
155 typename Distribution<global_ordinal_type,scalar_type>::LocalNZmap_t &localNZ,
156 Teuchos::RCP<Distribution<global_ordinal_type,scalar_type> > &dist
159 bool useTimers =
false;
161 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"useTimers");
163 useTimers = pe->getValue<
bool>(&useTimers);
166 Teuchos::RCP<Teuchos::TimeMonitor> timer = Teuchos::null;
168 timer = rcp(
new Teuchos::TimeMonitor(
169 *Teuchos::TimeMonitor::getNewTimer(
"RMM parameterSetup")));
171 int me = comm->getRank();
173 bool verbose =
false;
175 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"verbose");
177 verbose = pe->getValue<
bool>(&verbose);
180 size_t chunkSize = 500000;
182 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"chunkSize");
184 chunkSize = pe->getValue<
size_t>(&chunkSize);
187 bool symmetrize =
false;
189 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"symmetrize");
191 symmetrize = pe->getValue<
bool>(&symmetrize);
194 bool transpose =
false;
196 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"transpose");
198 transpose = pe->getValue<
bool>(&transpose);
201 std::string diagonal =
"";
205 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"diagonal");
207 diagonal = pe->getValue<std::string>(&diagonal);
209 bool ignoreDiagonal = (diagonal ==
"exclude");
210 bool requireDiagonal = (diagonal ==
"require");
212 std::string distribution =
"1D";
214 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"distribution");
216 distribution = pe->getValue<std::string>(&distribution);
220 timer = Teuchos::null;
221 timer = rcp(
new Teuchos::TimeMonitor(
222 *Teuchos::TimeMonitor::getNewTimer(
"RMM header")));
225 if (verbose && me == 0)
226 std::cout <<
"Reading matrix market file... " << filename << std::endl;
229 size_t dim[3] = {0,0,0};
234 fp = fopen(filename.c_str(),
"r");
237 std::cout <<
"Error: cannot open file " << filename << std::endl;
241 if (mm_read_banner(fp, &mmcode) != 0) {
242 std::cout <<
"Error: bad MatrixMarket banner " << std::endl;
246 if (!mm_is_valid(mmcode) ||
247 mm_is_dense(mmcode) || mm_is_array(mmcode) ||
248 mm_is_complex(mmcode) ||
249 mm_is_skew(mmcode) || mm_is_hermitian(mmcode)) {
250 std::cout <<
"Error: matrix type is not supported by this reader\n "
251 <<
"This reader supports sparse, coordinate, "
252 <<
"real, pattern, integer, symmetric, general"
257 if (mm_read_mtx_crd_size(fp, &dim[0], &dim[1], &dim[2]) != 0) {
258 std::cout <<
"Error: bad matrix dimensions " << std::endl;
259 dim[0] = dim[1] = dim[2] = 0;
269 Teuchos::broadcast<int, size_t>(*comm, 0, 3, dim);
270 if (dim[0] == 0 || dim[1] == 0) {
271 throw std::runtime_error(
"Error: bad matrix header information");
273 Teuchos::broadcast<int, char>(*comm, 0,
sizeof(MM_typecode), mmcode);
278 TEUCHOS_TEST_FOR_EXCEPTION(nRow != nCol, std::logic_error,
279 "This overload of readSparseFile requires nRow == nCol "
280 <<
"(nRow = " << nRow <<
", nCol = " << nCol <<
"); "
281 <<
"For now, use a different overload of readSparseFile until this "
282 <<
"overload is fixed to read rectangular matrices. "
283 <<
"See Trilinos github issues #7045 and #8472.");
286 bool patternInput = mm_is_pattern(mmcode);
287 bool symmetricInput = mm_is_symmetric(mmcode);
288 if (symmetricInput) symmetrize =
true;
290 if (verbose && me == 0)
291 std::cout <<
"Matrix market file... "
292 <<
"\n symmetrize = " << symmetrize
293 <<
"\n transpose = " << transpose
294 <<
"\n change diagonal = " << diagonal
295 <<
"\n distribution = " << distribution
299 timer = Teuchos::null;
300 timer = rcp(
new Teuchos::TimeMonitor(
301 *Teuchos::TimeMonitor::getNewTimer(
"RMM distribution")));
305 dist = buildDistribution<global_ordinal_type,scalar_type>(distribution,
309 timer = Teuchos::null;
310 timer = rcp(
new Teuchos::TimeMonitor(
311 *Teuchos::TimeMonitor::getNewTimer(
"RMM readChunks")));
314 std::set<global_ordinal_type> diagset;
320 typename Distribution<global_ordinal_type,scalar_type>::NZindex_t;
323 const int maxLineLength = 81;
324 char *buffer =
new char[chunkSize*maxLineLength+1];
330 auto timerRead = Teuchos::TimeMonitor::getNewTimer(
"RMM readNonzeros");
331 auto timerSelect = Teuchos::TimeMonitor::getNewTimer(
"RMM selectNonzeros");
333 Teuchos::RCP<Teuchos::TimeMonitor> innerTimer = Teuchos::null;
334 while (nRead < nNz) {
336 innerTimer = rcp(
new Teuchos::TimeMonitor(*timerRead));
338 if (nNz-nRead > chunkSize) nChunk = chunkSize;
339 else nChunk = (nNz - nRead);
345 for (
size_t i = 0; i < nChunk; i++) {
346 eof = fgets(&buffer[rlen],maxLineLength,fp);
348 std::cout <<
"Unexpected end of matrix file." << std::endl;
352 rlen += strlen(&buffer[rlen]);
358 Teuchos::broadcast<int, size_t>(*comm, 0, 1, &rlen);
359 Teuchos::broadcast<int, char>(*comm, 0, rlen, buffer);
361 buffer[rlen++] =
'\0';
364 innerTimer = Teuchos::null;
365 innerTimer = rcp(
new Teuchos::TimeMonitor(*timerSelect));
368 char *lineptr = buffer;
369 for (rlen = 0; rlen < nChunk; rlen++) {
371 char *next = strchr(lineptr,
'\n');
372 global_ordinal_type I = atol(strtok(lineptr,
" \t\n"))
374 global_ordinal_type J = atol(strtok(NULL,
" \t\n"))
377 scalar_type V = (patternInput ? -1. : atof(strtok(NULL,
" \t\n")));
381 if ((I == J) && ignoreDiagonal)
continue;
383 if (transpose) std::swap<global_ordinal_type>(I,J);
388 if (dist->Mine(I,J,
int(V))) {
389 nzindex_t idx = std::make_pair(I,J);
391 if (requireDiagonal && (I == J)) diagset.insert(I);
397 if (symmetrize && (I != J) && dist->Mine(J,I,
int(V))) {
400 nzindex_t idx = std::make_pair(J,I);
407 if (nRead / 1000000 > nMillion) {
409 if (me == 0) std::cout << nMillion <<
"M ";
413 innerTimer = Teuchos::null;
416 if (verbose && me == 0)
417 std::cout << std::endl << nRead <<
" nonzeros read " << std::endl;
419 if (fp != NULL) fclose(fp);
423 timer = Teuchos::null;
424 timer = rcp(
new Teuchos::TimeMonitor(
425 *Teuchos::TimeMonitor::getNewTimer(
"RMM diagonal")));
430 if (requireDiagonal) {
431 if (dist->DistType() == MMFile) {
435 size_t localss = diagset.size();
437 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
438 &localss, &globalss);
439 TEUCHOS_TEST_FOR_EXCEPTION(globalss != nRow, std::logic_error,
440 "File-based nonzero distribution requires all diagonal "
441 <<
"entries to be present in the file. \n"
442 <<
"Number of diagonal entries in file = " << globalss <<
"\n"
443 <<
"Number of matrix rows = " << nRow <<
"\n");
446 for (global_ordinal_type i = 0;
447 i < static_cast<global_ordinal_type>(nRow); i++)
449 if (dist->Mine(i,i)) {
450 if (diagset.find(i) == diagset.end()) {
451 nzindex_t idx = std::make_pair(i,i);
459 std::set<global_ordinal_type>().swap(diagset);
462 timer = Teuchos::null;
517 const std::string &filename,
518 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
519 const Teuchos::ParameterList ¶ms,
522 typename Distribution<global_ordinal_type,scalar_type>::LocalNZmap_t &localNZ,
523 Teuchos::RCP<Distribution<global_ordinal_type,scalar_type> > &dist
527 int me = comm->getRank();
529 bool verbose =
false;
531 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"verbose");
533 verbose = pe->getValue<
bool>(&verbose);
536 size_t chunkSize = 500000;
538 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"chunkSize");
540 chunkSize = pe->getValue<
size_t>(&chunkSize);
543 bool symmetrize =
false;
545 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"symmetrize");
547 symmetrize = pe->getValue<
bool>(&symmetrize);
550 bool transpose =
false;
552 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"transpose");
554 transpose = pe->getValue<
bool>(&transpose);
557 std::string diagonal =
"";
561 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"diagonal");
563 diagonal = pe->getValue<std::string>(&diagonal);
565 bool ignoreDiagonal = (diagonal ==
"exclude");
566 bool requireDiagonal = (diagonal ==
"require");
568 std::string distribution =
"1D";
570 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"distribution");
572 distribution = pe->getValue<std::string>(&distribution);
575 if (verbose && me == 0)
576 std::cout <<
"Reading binary file... " << filename << std::endl;
579 size_t dim[3] = {0,0,0};
583 fp = fopen(filename.c_str(),
"rb");
586 std::cout <<
"Error: cannot open file " << filename << std::endl;
591 unsigned long long ne = 0;
592 if (fread(&nv,
sizeof(
unsigned int), 1, fp) != 1)
593 throw std::runtime_error(
"Error: bad number of read values.");
594 if (fread(&ne,
sizeof(
unsigned long long), 1, fp) != 1)
595 throw std::runtime_error(
"Error: bad number of read values.");
605 Teuchos::broadcast<int, size_t>(*comm, 0, 3, dim);
606 if (dim[0] == 0 || dim[1] == 0) {
607 throw std::runtime_error(
"Error: bad matrix header information");
614 if (verbose && me == 0)
615 std::cout <<
"Binary file... "
616 <<
"\n symmetrize = " << symmetrize
617 <<
"\n transpose = " << transpose
618 <<
"\n change diagonal = " << diagonal
619 <<
"\n distribution = " << distribution
623 dist = buildDistribution<global_ordinal_type,scalar_type>(distribution,
627 std::set<global_ordinal_type> diagset;
633 typename Distribution<global_ordinal_type,scalar_type>::NZindex_t;
636 unsigned int *buffer =
new unsigned int[chunkSize*2];
641 const scalar_type ONE = Teuchos::ScalarTraits<scalar_type>::one();
645 while (nRead < nNz) {
646 if (nNz-nRead > chunkSize) nChunk = chunkSize;
647 else nChunk = (nNz - nRead);
653 for (
size_t i = 0; i < nChunk; i++) {
654 ret = fread(&buffer[rlen],
sizeof(
unsigned int), 2, fp);
656 std::cout <<
"Unexpected end of matrix file." << std::endl;
665 Teuchos::broadcast<int, size_t>(*comm, 0, 1, &rlen);
666 Teuchos::broadcast<int, unsigned int>(*comm, 0, rlen, buffer);
671 for (rlen = 0; rlen < nChunk; rlen++) {
673 global_ordinal_type I = buffer[2*rlen]-1;
674 global_ordinal_type J = buffer[2*rlen+1]-1;
677 if ((I == J) && ignoreDiagonal)
continue;
679 if (transpose) std::swap<global_ordinal_type>(I,J);
684 if (dist->Mine(I,J,ONE)) {
685 nzindex_t idx = std::make_pair(I,J);
688 if (requireDiagonal && (I == J)) diagset.insert(I);
694 if (symmetrize && (I != J) && dist->Mine(J,I,ONE)) {
697 nzindex_t idx = std::make_pair(J,I);
704 if (nRead / 1000000 > nMillion) {
706 if (me == 0) std::cout << nMillion <<
"M ";
711 if (verbose && me == 0)
712 std::cout << std::endl << nRead <<
" nonzeros read " << std::endl;
714 if (fp != NULL) fclose(fp);
719 if (requireDiagonal) {
720 if (dist->DistType() == MMFile) {
724 size_t localss = diagset.size();
726 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
727 &localss, &globalss);
728 TEUCHOS_TEST_FOR_EXCEPTION(globalss != nRow, std::logic_error,
729 "File-based nonzero distribution requires all diagonal "
730 <<
"entries to be present in the file. \n"
731 <<
"Number of diagonal entries in file = " << globalss <<
"\n"
732 <<
"Number of matrix rows = " << nRow <<
"\n");
735 for (global_ordinal_type i = 0;
736 i < static_cast<global_ordinal_type>(nRow); i++)
738 if (dist->Mine(i,i)) {
739 if (diagset.find(i) == diagset.end()) {
740 nzindex_t idx = std::make_pair(i,i);
748 std::set<global_ordinal_type>().swap(diagset);
780 readPerProcessBinary(
781 const std::string &filename,
782 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
783 const Teuchos::ParameterList ¶ms,
786 typename Distribution<global_ordinal_type,scalar_type>::LocalNZmap_t &localNZ,
787 Teuchos::RCP<Distribution<global_ordinal_type,scalar_type> > &dist,
788 unsigned int* &buffer,
793 int me = comm->getRank();
795 bool verbose =
false;
797 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"verbose");
799 verbose = pe->getValue<
bool>(&verbose);
802 std::string distribution =
"1D";
804 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"distribution");
806 distribution = pe->getValue<std::string>(&distribution);
809 if (verbose && me == 0)
810 std::cout <<
"Reading per-process binary files... " << filename << std::endl;
813 std::string rankFileName = filename +
"." + std::to_string(me) +
".cooBin";
816 fp = fopen(rankFileName.c_str(),
"rb");
818 std::cout <<
"Error: cannot open file " << filename << std::endl;
819 throw std::runtime_error(
"Error: non-existing input file: " + rankFileName);
823 unsigned int globalNumRows = 0, globalNumCols = 0;
824 unsigned long long localNumNonzeros = 0;
825 if (fread(&globalNumRows,
sizeof(
unsigned int), 1, fp) != 1)
826 throw std::runtime_error(
"Error: bad number of read values.");
827 if (fread(&globalNumCols,
sizeof(
unsigned int), 1, fp) != 1)
828 throw std::runtime_error(
"Error: bad number of read values.");
829 if (fread(&localNumNonzeros,
sizeof(
unsigned long long), 1, fp) != 1)
830 throw std::runtime_error(
"Error: bad number of read values.");
832 nRow =
static_cast<size_t>(globalNumRows);
833 nCol =
static_cast<size_t>(globalNumCols);
834 nNz =
static_cast<size_t>(localNumNonzeros);
838 buffer =
new unsigned int[nNz*2];
841 size_t ret = fread(buffer,
sizeof(
unsigned int), 2*nNz, fp);
843 std::cout <<
"Unexpected end of matrix file: " << rankFileName << std::endl;
849 if (fp != NULL) fclose(fp);
853 if(verbose && me == 0)
854 std::cout <<
"All ranks finished reading their nonzeros from their individual files\n";
857 dist = buildDistribution<global_ordinal_type,scalar_type>(distribution,
865 static Teuchos::RCP<sparse_matrix_type>
867 const std::string &filename,
868 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
869 const Teuchos::ParameterList ¶ms
872 Teuchos::RCP<Distribution<global_ordinal_type,scalar_type> > dist;
873 return readSparseFile(filename, comm, params, dist);
879 static Teuchos::RCP<sparse_matrix_type>
881 const std::string &filename,
882 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
883 const Teuchos::ParameterList ¶ms,
884 Teuchos::RCP<Distribution<global_ordinal_type,scalar_type> > &dist
887 bool useTimers =
false;
889 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"useTimers");
891 useTimers = pe->getValue<
bool>(&useTimers);
894 Teuchos::RCP<Teuchos::TimeMonitor> timer = Teuchos::null;
896 timer = rcp(
new Teuchos::TimeMonitor(
897 *Teuchos::TimeMonitor::getNewTimer(
"RSF parameterSetup")));
899 int me = comm->getRank();
904 bool verbose =
false;
906 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"verbose");
908 verbose = pe->getValue<
bool>(&verbose);
911 bool callFillComplete =
true;
913 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"callFillComplete");
915 callFillComplete = pe->getValue<
bool>(&callFillComplete);
926 typename Distribution<global_ordinal_type,scalar_type>::LocalNZmap_t;
927 localNZmap_t localNZ;
931 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"binary");
933 binary = pe->getValue<
bool>(&binary);
936 bool readPerProcess =
false;
938 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"readPerProcess");
940 readPerProcess = pe->getValue<
bool>(&readPerProcess);
944 const char *timername = (binary?
"RSF readBinary":
"RSF readMatrixMarket");
945 timer = Teuchos::null;
946 timer = rcp(
new Teuchos::TimeMonitor(
947 *Teuchos::TimeMonitor::getNewTimer(timername)));
951 size_t nRow = 0, nCol = 0;
952 unsigned int *buffer=0;
size_t nNz = 0;
955 readPerProcessBinary(filename, comm, params, nRow, nCol, localNZ, dist, buffer, nNz);
957 readBinary(filename, comm, params, nRow, nCol, localNZ, dist);
960 readMatrixMarket(filename, comm, params, nRow, nCol, localNZ, dist);
962 if(readPerProcess ==
false){
967 timer = Teuchos::null;
968 timer = rcp(
new Teuchos::TimeMonitor(
969 *Teuchos::TimeMonitor::getNewTimer(
"RSF redistribute")));
972 dist->Redistribute(localNZ);
976 timer = Teuchos::null;
977 timer = rcp(
new Teuchos::TimeMonitor(
978 *Teuchos::TimeMonitor::getNewTimer(
"RSF nonzerosConstruction")));
983 if (verbose && me == 0)
984 std::cout << std::endl <<
"Constructing the matrix" << std::endl;
986 Teuchos::Array<global_ordinal_type> rowIdx;
987 Teuchos::Array<size_t> nnzPerRow;
988 Teuchos::Array<global_ordinal_type> colIdx;
989 Teuchos::Array<scalar_type> val;
990 Teuchos::Array<size_t> offsets;
993 global_ordinal_type prevI = std::numeric_limits<global_ordinal_type>::max();
994 for (
size_t it = 0; it < nNz; it++){
995 global_ordinal_type I = buffer[2*it]-1;
996 global_ordinal_type J = buffer[2*it+1]-1;
1000 nnzPerRow.push_back(0);
1003 colIdx.push_back(J);
1009 global_ordinal_type prevI = std::numeric_limits<global_ordinal_type>::max();
1010 for (
auto it = localNZ.begin(); it != localNZ.end(); it++) {
1011 global_ordinal_type I = it->first.first;
1012 global_ordinal_type J = it->first.second;
1013 scalar_type V = it->second;
1016 rowIdx.push_back(I);
1017 nnzPerRow.push_back(0);
1020 colIdx.push_back(J);
1025 localNZmap_t().swap(localNZ);
1029 offsets.resize(rowIdx.size() + 1);
1031 for (
size_t row = 0; row < static_cast<size_t>(rowIdx.size()); row++)
1032 offsets[row+1] = offsets[row] + nnzPerRow[row];
1035 timer = Teuchos::null;
1036 timer = rcp(
new Teuchos::TimeMonitor(
1037 *Teuchos::TimeMonitor::getNewTimer(
"RSF insertNonzeros")));
1041 size_t dummy = Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
1042 Teuchos::RCP<const Tpetra::Map<> > rowMap =
1045 Teuchos::RCP<sparse_matrix_type> A =
1046 rcp(
new sparse_matrix_type(rowMap, nnzPerRow()));
1049 if (verbose && me == 0)
1050 std::cout <<
"Inserting global values" << std::endl;
1053 const scalar_type ONE = Teuchos::ScalarTraits<scalar_type>::one();
1054 for (
int i = 0; i < rowIdx.size(); i++) {
1055 size_t nnz = nnzPerRow[i];
1056 size_t off = offsets[i];
1057 val.assign(nnz, ONE);
1060 A->insertGlobalValues(rowIdx[i], colIdx(off, nnz), val());
1064 for (
int i = 0; i < rowIdx.size(); i++) {
1065 size_t nnz = nnzPerRow[i];
1066 size_t off = offsets[i];
1067 A->insertGlobalValues(rowIdx[i], colIdx(off, nnz), val(off, nnz));
1072 Teuchos::Array<size_t>().swap(nnzPerRow);
1073 Teuchos::Array<size_t>().swap(offsets);
1074 Teuchos::Array<global_ordinal_type>().swap(rowIdx);
1075 Teuchos::Array<global_ordinal_type>().swap(colIdx);
1076 Teuchos::Array<scalar_type>().swap(val);
1079 timer = Teuchos::null;
1081 if (callFillComplete) {
1083 if (verbose && me == 0)
1084 std::cout <<
"Building vector maps" << std::endl;
1087 timer = Teuchos::null;
1088 timer = rcp(
new Teuchos::TimeMonitor(
1089 *Teuchos::TimeMonitor::getNewTimer(
"RSF buildVectorMaps")));
1093 Teuchos::Array<global_ordinal_type> vectorSet;
1094 for (global_ordinal_type i = 0;
1095 i < static_cast<global_ordinal_type>(nCol); i++)
1096 if (dist->VecMine(i)) vectorSet.push_back(i);
1098 dummy = Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
1099 Teuchos::RCP<const Tpetra::Map<> > domainMap =
1100 Teuchos::rcp(
new Tpetra::Map<>(dummy, vectorSet(), 0, comm));
1102 Teuchos::Array<global_ordinal_type>().swap(vectorSet);
1105 for (global_ordinal_type i = 0;
1106 i < static_cast<global_ordinal_type>(nRow); i++)
1107 if (dist->VecMine(i)) vectorSet.push_back(i);
1109 dummy = Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
1110 Teuchos::RCP<const Tpetra::Map<> > rangeMap =
1111 Teuchos::rcp(
new Tpetra::Map<>(dummy, vectorSet(), 0, comm));
1113 Teuchos::Array<global_ordinal_type>().swap(vectorSet);
1117 timer = Teuchos::null;
1118 timer = rcp(
new Teuchos::TimeMonitor(
1119 *Teuchos::TimeMonitor::getNewTimer(
"RSF fillComplete")));
1122 if (verbose && me == 0)
1123 std::cout <<
"Calling fillComplete" << std::endl;
1125 A->fillComplete(domainMap, rangeMap);
1128 timer = Teuchos::null;
1131 std::cout <<
"\nRank " << A->getComm()->getRank()
1132 <<
" nRows " << A->getLocalNumRows()
1133 <<
" minRow " << A->getRowMap()->getMinGlobalIndex()
1134 <<
" maxRow " << A->getRowMap()->getMaxGlobalIndex()
1135 <<
"\nRank " << A->getComm()->getRank()
1136 <<
" nCols " << A->getLocalNumCols()
1137 <<
" minCol " << A->getColMap()->getMinGlobalIndex()
1138 <<
" maxCol " << A->getColMap()->getMaxGlobalIndex()
1139 <<
"\nRank " << A->getComm()->getRank()
1140 <<
" nDomain " << A->getDomainMap()->getLocalNumElements()
1141 <<
" minDomain " << A->getDomainMap()->getMinGlobalIndex()
1142 <<
" maxDomain " << A->getDomainMap()->getMaxGlobalIndex()
1143 <<
"\nRank " << A->getComm()->getRank()
1144 <<
" nRange " << A->getRangeMap()->getLocalNumElements()
1145 <<
" minRange " << A->getRangeMap()->getMinGlobalIndex()
1146 <<
" maxRange " << A->getRangeMap()->getMaxGlobalIndex()
1147 <<
"\nRank " << A->getComm()->getRank()
1148 <<
" nEntries " << A->getLocalNumEntries()
A parallel distribution of indices over processes.