195 if (mxGetClassID(mxa) != mxCHAR_CLASS) {
196 throw runtime_error(
"Can't construct string from anything but a char array.");
198 rv = string(mxArrayToString(mxa));
203RCP<Xpetra_map> loadDataFromMatlab<RCP<Xpetra_map> >(
const mxArray* mxa) {
204 RCP<const Teuchos::Comm<int> > comm = rcp(
new Teuchos::SerialComm<int>());
205 int nr = mxGetM(mxa);
206 int nc = mxGetN(mxa);
208 throw std::runtime_error(
"A Xpetra::Map representation from MATLAB must be a single row vector.");
209 double* pr = mxGetPr(mxa);
212 std::vector<mm_GlobalOrd> localGIDs(numGlobalIndices);
213 for (
int i = 0; i < int(numGlobalIndices); i++) {
214 localGIDs[i] = Teuchos::as<mm_GlobalOrd>(pr[i]);
217 const Teuchos::ArrayView<const mm_GlobalOrd> localGIDs_view(&localGIDs[0], localGIDs.size());
218 RCP<Xpetra_map> map =
219 Xpetra::MapFactory<mm_LocalOrd, mm_GlobalOrd, mm_node_t>::Build(
221 Teuchos::OrdinalTraits<mm_GlobalOrd>::invalid(),
226 throw runtime_error(
"Failed to create Xpetra::Map.");
231RCP<Xpetra_ordinal_vector> loadDataFromMatlab<RCP<Xpetra_ordinal_vector> >(
const mxArray* mxa) {
232 RCP<const Teuchos::Comm<int> > comm = rcp(
new Teuchos::SerialComm<int>());
233 if (mxGetN(mxa) != 1 && mxGetM(mxa) != 1)
234 throw std::runtime_error(
"An OrdinalVector from MATLAB must be a single row or column vector.");
235 mm_GlobalOrd numGlobalIndices = mxGetM(mxa) * mxGetN(mxa);
236 RCP<Xpetra::Map<mm_LocalOrd, mm_GlobalOrd, mm_node_t> > map = Xpetra::MapFactory<mm_LocalOrd, mm_GlobalOrd, mm_node_t>::Build(Xpetra::UseTpetra, numGlobalIndices, 0, comm);
237 if (mxGetClassID(mxa) != mxINT32_CLASS)
238 throw std::runtime_error(
"Can only construct LOVector with int32 data.");
239 int* array = (
int*)mxGetData(mxa);
241 throw runtime_error(
"Failed to create map for Xpetra ordinal vector.");
242 RCP<Xpetra_ordinal_vector> loVec = Xpetra::VectorFactory<mm_LocalOrd, mm_LocalOrd, mm_GlobalOrd, mm_node_t>::Build(map,
false);
244 throw runtime_error(
"Failed to create ordinal vector with Xpetra::VectorFactory.");
245 for (
int i = 0; i < int(numGlobalIndices); i++) {
246 loVec->replaceGlobalValue(i, 0, array[i]);
252RCP<Tpetra_MultiVector_double> loadDataFromMatlab<RCP<Tpetra_MultiVector_double> >(
const mxArray* mxa) {
253 RCP<Tpetra::MultiVector<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > mv;
255 int nr = mxGetM(mxa);
256 int nc = mxGetN(mxa);
257 double* pr = mxGetPr(mxa);
258 RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
262 Teuchos::ArrayView<const double> arrView(pr, nr * nc);
263 mv = rcp(
new Tpetra::MultiVector<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t>(map, arrView,
size_t(nr),
size_t(nc)));
264 }
catch (std::exception& e) {
265 mexPrintf(
"Error constructing Tpetra MultiVector.\n");
266 std::cout << e.what() << std::endl;
272RCP<Tpetra_MultiVector_complex> loadDataFromMatlab<RCP<Tpetra_MultiVector_complex> >(
const mxArray* mxa) {
273 RCP<Tpetra::MultiVector<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > mv;
275 int nr = mxGetM(mxa);
276 int nc = mxGetN(mxa);
277 double* pr = mxGetPr(mxa);
278 double* pi = mxGetPi(mxa);
279 RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
284 for (
int n = 0; n < nc; n++) {
285 for (
int m = 0; m < nr; m++) {
286 myArr[n * nr + m] =
complex_t(pr[n * nr + m], pi[n * nr + m]);
289 Teuchos::ArrayView<complex_t> arrView(myArr, nr * nc);
290 mv = rcp(
new Tpetra::MultiVector<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t>(map, arrView, nr, nc));
291 }
catch (std::exception& e) {
292 mexPrintf(
"Error constructing Tpetra MultiVector.\n");
293 std::cout << e.what() << std::endl;
299RCP<Tpetra_CrsMatrix_double> loadDataFromMatlab<RCP<Tpetra_CrsMatrix_double> >(
const mxArray* mxa) {
300 bool success =
false;
301 RCP<Tpetra_CrsMatrix_double> A;
307 RCP<const Teuchos::Comm<int> > comm = rcp(
new Teuchos::SerialComm<int>());
309 const size_t numGlobalIndices = mxGetM(mxa);
310 RCP<const muemex_map_type> rowMap = rcp(
new muemex_map_type(numGlobalIndices, 0, comm));
311 RCP<const muemex_map_type> domainMap = rcp(
new muemex_map_type(mxGetN(mxa), 0, comm));
312 double* valueArray = mxGetPr(mxa);
313 int nc = mxGetN(mxa);
319 rowind = (
int*)mxGetIr(mxa);
320 colptr = (
int*)mxGetJc(mxa);
323 Teuchos::Array<size_t> rowCounts(numGlobalIndices);
324 for (
int i = 0; i < nc; i++) {
325 for (
int j = colptr[i]; j < colptr[i + 1]; j++) {
326 rowCounts[rowind[j]]++;
329 A = rcp(
new Tpetra::CrsMatrix<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t>(rowMap, rowCounts()));
330 for (
int i = 0; i < nc; i++) {
331 for (
int j = colptr[i]; j < colptr[i + 1]; j++) {
333 Teuchos::ArrayView<mm_GlobalOrd> cols = Teuchos::ArrayView<mm_GlobalOrd>(&i, 1);
335 Teuchos::ArrayView<double> vals = Teuchos::ArrayView<double>(&valueArray[j], 1);
336 A->insertGlobalValues(rowind[j], cols, vals);
339 A->fillComplete(domainMap, rowMap);
347 }
catch (std::exception& e) {
349 if (rowind != NULL)
delete[] rowind;
350 if (colptr != NULL)
delete[] colptr;
354 mexPrintf(
"Error while constructing Tpetra matrix:\n");
355 std::cout << e.what() << std::endl;
358 mexErrMsgTxt(
"An error occurred while setting up a Tpetra matrix.\n");
363RCP<Tpetra_CrsMatrix_complex> loadDataFromMatlab<RCP<Tpetra_CrsMatrix_complex> >(
const mxArray* mxa) {
364 RCP<Tpetra_CrsMatrix_complex> A;
367 RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
368 const Tpetra::global_size_t numGlobalIndices = mxGetM(mxa);
370 RCP<const muemex_map_type> rowMap = rcp(
new muemex_map_type(numGlobalIndices, indexBase, comm));
371 RCP<const muemex_map_type> domainMap = rcp(
new muemex_map_type(mxGetN(mxa), indexBase, comm));
372 double* realArray = mxGetPr(mxa);
373 double* imagArray = mxGetPi(mxa);
376 int nc = mxGetN(mxa);
382 rowind = (
int*)mxGetIr(mxa);
383 colptr = (
int*)mxGetJc(mxa);
386 Teuchos::Array<size_t> rowCounts(numGlobalIndices);
387 for (
int i = 0; i < nc; i++) {
388 for (
int j = colptr[i]; j < colptr[i + 1]; j++) {
389 rowCounts[rowind[j]]++;
392 A = rcp(
new Tpetra::CrsMatrix<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t>(rowMap, rowCounts()));
393 for (
int i = 0; i < nc; i++) {
394 for (
int j = colptr[i]; j < colptr[i + 1]; j++) {
397 complex_t value = std::complex<double>(realArray[j], imagArray[j]);
398 Teuchos::ArrayView<mm_GlobalOrd> cols = Teuchos::ArrayView<mm_GlobalOrd>(&i, 1);
399 Teuchos::ArrayView<complex_t> vals = Teuchos::ArrayView<complex_t>(&value, 1);
400 A->insertGlobalValues(rowind[j], cols, vals);
403 A->fillComplete(domainMap, rowMap);
408 }
catch (std::exception& e) {
409 mexPrintf(
"Error while constructing tpetra matrix:\n");
410 std::cout << e.what() << std::endl;
416RCP<Xpetra::Matrix<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > loadDataFromMatlab<RCP<Xpetra::Matrix<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(
const mxArray* mxa) {
417 RCP<Tpetra::CrsMatrix<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > tmat = loadDataFromMatlab<RCP<Tpetra::CrsMatrix<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(mxa);
418 return Xpetra::toXpetra(tmat);
422RCP<Xpetra::Matrix<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > loadDataFromMatlab<RCP<Xpetra::Matrix<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(
const mxArray* mxa) {
423 RCP<Tpetra::CrsMatrix<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > tmat = loadDataFromMatlab<RCP<Tpetra::CrsMatrix<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(mxa);
424 return Xpetra::toXpetra(tmat);
428RCP<Xpetra::MultiVector<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > loadDataFromMatlab<RCP<Xpetra::MultiVector<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(
const mxArray* mxa) {
429 RCP<Tpetra::MultiVector<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > tpetraMV = loadDataFromMatlab<RCP<Tpetra::MultiVector<double, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(mxa);
430 return Xpetra::toXpetra(tpetraMV);
434RCP<Xpetra::MultiVector<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > loadDataFromMatlab<RCP<Xpetra::MultiVector<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(
const mxArray* mxa) {
435 RCP<Tpetra::MultiVector<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > tpetraMV = loadDataFromMatlab<RCP<Tpetra::MultiVector<complex_t, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > >(mxa);
436 return Xpetra::toXpetra(tpetraMV);
440RCP<MAggregates> loadDataFromMatlab<RCP<MAggregates> >(
const mxArray* mxa) {
441 if (mxGetNumberOfElements(mxa) != 1)
442 throw runtime_error(
"Aggregates must be individual structs in MATLAB.");
443 if (!mxIsStruct(mxa))
444 throw runtime_error(
"Trying to pull aggregates from non-struct MATLAB object.");
447 const int correctNumFields = 5;
448 if (mxGetNumberOfFields(mxa) != correctNumFields)
449 throw runtime_error(
"Aggregates structure has wrong number of fields.");
451 int nVert = *(
int*)mxGetData(mxGetField(mxa, 0,
"nVertices"));
452 int nAgg = *(
int*)mxGetData(mxGetField(mxa, 0,
"nAggregates"));
455 RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
456 int myRank = comm->getRank();
457 Xpetra::UnderlyingLib lib = Xpetra::UseTpetra;
458 RCP<Xpetra::Map<mm_LocalOrd, mm_GlobalOrd, mm_node_t> > map = Xpetra::MapFactory<mm_LocalOrd, mm_GlobalOrd, mm_node_t>::Build(lib, nVert, 0, comm);
460 agg->SetNumAggregates(nAgg);
463 ArrayRCP<mm_LocalOrd> vertex2AggId = agg->GetVertex2AggId()->getDataNonConst(0);
464 ArrayRCP<mm_LocalOrd> procWinner = agg->GetProcWinner()->getDataNonConst(0);
468 mxArray* vertToAggID_in = mxGetField(mxa, 0,
"vertexToAggID");
469 int* vertToAggID_inArray = (
int*)mxGetData(vertToAggID_in);
470 mxArray* rootNodes_in = mxGetField(mxa, 0,
"rootNodes");
471 int* rootNodes_inArray = (
int*)mxGetData(rootNodes_in);
472 for (
int i = 0; i < nVert; i++) {
473 vertex2AggId[i] = vertToAggID_inArray[i];
474 procWinner[i] = myRank;
475 agg->SetIsRoot(i,
false);
477 for (
int i = 0; i < nAgg; i++)
479 agg->SetIsRoot(rootNodes_inArray[i],
true);
482 agg->ComputeAggregateSizes(
true);
483 agg->AggregatesCrossProcessors(
false);
684 Teuchos::rcp_const_cast<Xpetra_CrsGraph>(data->getCrsGraph())->computeGlobalConstants();
686 int nr = data->getGlobalNumRows();
687 int nc = data->getGlobalNumCols();
688 int nnz = data->getGlobalNumEntries();
691 RCP<Teuchos::FancyOStream> fancyStream = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
692 mat->describe(*fancyStream, Teuchos::VERB_EXTREME);
694 mxArray* mxa = createMatlabSparse<Scalar>(nr, nc, nnz);
697 for (
int i = 0; i < nc + 1; i++) {
701 size_t maxEntriesPerRow = data->getGlobalMaxNumRowEntries();
702 if (maxEntriesPerRow == Teuchos::OrdinalTraits<size_t>::invalid() || maxEntriesPerRow == 0) maxEntriesPerRow = data->getLocalMaxNumRowEntries();
704 int* rowProgress =
new int[nc];
708 if (data->isLocallyIndexed()) {
710 Teuchos::ArrayView<Scalar> rowVals(rowValArray, maxEntriesPerRow);
712 Teuchos::ArrayView<mm_LocalOrd> rowIndices(rowIndicesArray, maxEntriesPerRow);
715 data->getLocalRowCopy(m, rowIndices, rowVals, numEntries);
716 for (
mm_LocalOrd entry = 0; entry < int(numEntries); entry++)
718 jc[rowIndices[entry] + 1]++;
723 int entriesAccum = 0;
724 for (
int n = 0; n <= nc; n++) {
725 int temp = entriesAccum;
726 entriesAccum += jc[n];
730 for (
int i = 0; i < nc; i++) {
736 data->getLocalRowCopy(m, rowIndices, rowVals, numEntries);
741 sparseVals[jc[col] + rowProgress[col]] = rowVals[i];
742 ir[jc[col] + rowProgress[col]] = m;
746 delete[] rowIndicesArray;
748 Teuchos::ArrayView<const mm_GlobalOrd> rowIndices;
749 Teuchos::ArrayView<const Scalar> rowVals;
751 data->getGlobalRowView(m, rowIndices, rowVals);
753 jc[rowIndices[n] + 1]++;
759 for (
int i = 0; i < nc; i++) {
762 int entriesAccum = 0;
763 for (
int n = 0; n <= nc; n++) {
764 int temp = entriesAccum;
765 entriesAccum += jc[n];
771 data->getGlobalRowView(m, rowIndices, rowVals);
772 for (
mm_LocalOrd i = 0; i < rowIndices.size(); i++)
775 sparseVals[jc[col] + rowProgress[col]] = rowVals[i];
776 ir[jc[col] + rowProgress[col]] = m;
782 fillMatlabArray<Scalar>(sparseVals, mxa, nnz);
784 delete[] rowProgress;
793 Teuchos::rcp_const_cast<Xpetra_CrsGraph>(data->getCrsGraph())->computeGlobalConstants();
795 int nr = data->getGlobalNumRows();
796 int nc = data->getGlobalNumCols();
797 int nnz = data->getGlobalNumEntries();
799 RCP<Teuchos::FancyOStream> fancyStream = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
800 mat->describe(*fancyStream, Teuchos::VERB_EXTREME);
802 mxArray* mxa = createMatlabSparse<Scalar>(nr, nc, nnz);
805 for (
int i = 0; i < nc + 1; i++) {
808 size_t maxEntriesPerRow = data->getGlobalMaxNumRowEntries();
809 int* rowProgress =
new int[nc];
813 if (data->isLocallyIndexed()) {
815 Teuchos::ArrayView<Scalar> rowVals(rowValArray, maxEntriesPerRow);
817 Teuchos::ArrayView<mm_LocalOrd> rowIndices(rowIndicesArray, maxEntriesPerRow);
820 data->getLocalRowCopy(m, rowIndices, rowVals, numEntries);
821 for (
mm_LocalOrd entry = 0; entry < int(numEntries); entry++)
823 jc[rowIndices[entry] + 1]++;
827 int entriesAccum = 0;
828 for (
int n = 0; n <= nc; n++) {
829 int temp = entriesAccum;
830 entriesAccum += jc[n];
834 for (
int i = 0; i < nc; i++) {
840 data->getLocalRowCopy(m, rowIndices, rowVals, numEntries);
845 sparseVals[jc[col] + rowProgress[col]] = rowVals[i];
846 ir[jc[col] + rowProgress[col]] = m;
850 delete[] rowIndicesArray;
852 Teuchos::ArrayView<const mm_GlobalOrd> rowIndices;
853 Teuchos::ArrayView<const Scalar> rowVals;
855 data->getGlobalRowView(m, rowIndices, rowVals);
857 jc[rowIndices[n] + 1]++;
863 for (
int i = 0; i < nc; i++) {
866 int entriesAccum = 0;
867 for (
int n = 0; n <= nc; n++) {
868 int temp = entriesAccum;
869 entriesAccum += jc[n];
875 data->getGlobalRowView(m, rowIndices, rowVals);
876 for (
mm_LocalOrd i = 0; i < rowIndices.size(); i++)
879 sparseVals[jc[col] + rowProgress[col]] = rowVals[i];
880 ir[jc[col] + rowProgress[col]] = m;
886 fillMatlabArray<Scalar>(sparseVals, mxa, nnz);
888 delete[] rowProgress;
954 int numNodes = data->GetVertex2AggId()->getData(0).size();
955 int numAggs = data->GetNumAggregates();
957 mwSize singleton[] = {1, 1};
958 dataIn[0] = mxCreateNumericArray(2, singleton, mxINT32_CLASS, mxREAL);
959 *((
int*)mxGetData(dataIn[0])) = numNodes;
960 dataIn[1] = mxCreateNumericArray(2, singleton, mxINT32_CLASS, mxREAL);
961 *((
int*)mxGetData(dataIn[1])) = numAggs;
962 mwSize nodeArrayDims[] = {(mwSize)numNodes, 1};
963 dataIn[2] = mxCreateNumericArray(2, nodeArrayDims, mxINT32_CLASS, mxREAL);
964 int* vtaid = (
int*)mxGetData(dataIn[2]);
965 ArrayRCP<const mm_LocalOrd> vertexToAggID = data->GetVertex2AggId()->getData(0);
966 for (
int i = 0; i < numNodes; i++) {
967 vtaid[i] = vertexToAggID[i];
969 mwSize aggArrayDims[] = {(mwSize)numAggs, 1};
970 dataIn[3] = mxCreateNumericArray(2, aggArrayDims, mxINT32_CLASS, mxREAL);
973 for (
int i = 0; i < numNodes; i++) {
977 bool reassignRoots =
false;
978 if (totalRoots != numAggs) {
980 <<
"Warning: Number of root nodes and number of aggregates do not match." << endl;
981 cout <<
"Will reassign root nodes when writing aggregates to matlab." << endl
983 reassignRoots =
true;
985 int* rn = (
int*)mxGetData(dataIn[3]);
989 int lastFoundNode = 0;
990 for (
int i = 0; i < numAggs; i++) {
992 for (
int j = lastFoundNode; j < lastFoundNode + numNodes; j++) {
993 int index = j % numNodes;
994 if (vertexToAggID[index] == i) {
996 lastFoundNode = index;
999 TEUCHOS_TEST_FOR_EXCEPTION(rn[i] == -1, runtime_error,
"Invalid aggregates: Couldn't find any node in aggregate #" << i <<
".");
1003 for (
int j = 0; j < numNodes; j++) {
1004 if (data->IsRoot(j)) {
1006 throw runtime_error(
"Cannot store invalid aggregates in MATLAB - more root nodes than aggregates.");
1011 if (i + 1 < numAggs)
1012 throw runtime_error(
"Cannot store invalid aggregates in MATLAB - fewer root nodes than aggregates.");
1015 dataIn[4] = mxCreateNumericArray(1, aggArrayDims, mxINT32_CLASS, mxREAL);
1016 int* as = (
int*)mxGetData(dataIn[4]);
1017 auto aggSizes = data->ComputeAggregateSizes();
1018 for (
int i = 0; i < numAggs; i++) {
1019 as[i] = aggSizes[i];
1022 int result = mexCallMATLAB(1, matlabAggs, 5, dataIn,
"constructAggregates");
1024 throw runtime_error(
"Matlab encountered an error while constructing aggregates struct.");
1025 return matlabAggs[0];
1036 int numEntries = (int)data->GetGlobalNumEdges();
1037 int numRows = (int)data->GetDomainMap()->getGlobalNumElements();
1038 mxArray* mat = mxCreateSparseLogicalMatrix(numRows, numRows, numEntries);
1039 mxLogical* outData = (mxLogical*)mxGetData(mat);
1040 mwIndex* rowInds = mxGetIr(mat);
1041 mwIndex* colPtrs = mxGetJc(mat);
1044 int* entriesPerRow =
new int[numRows];
1045 int* entriesPerCol =
new int[numRows];
1046 for (
int i = 0; i < numRows; i++) {
1047 entriesPerRow[i] = 0;
1048 entriesPerCol[i] = 0;
1050 for (
int i = 0; i < numRows; i++) {
1051 ArrayView<typename MGraph::local_ordinal_type> neighbors = data->getNeighborVertices_av(i);
1052 memcpy(iter, neighbors.getRawPtr(),
sizeof(
mm_LocalOrd) * neighbors.size());
1053 entriesPerRow[i] = neighbors.size();
1054 for (
int j = 0; j < neighbors.size(); j++) {
1055 entriesPerCol[neighbors[j]]++;
1057 iter += neighbors.size();
1060 mxLogical** valuesByColumn =
new mxLogical*[numRows];
1061 int* numEnteredPerCol =
new int[numRows];
1063 for (
int i = 0; i < numRows; i++) {
1064 rowIndsByColumn[i] = &rowInds[accum];
1066 valuesByColumn[i] = &outData[accum];
1067 accum += entriesPerCol[i];
1068 if (accum > numEntries)
1069 throw runtime_error(
"potato");
1071 for (
int i = 0; i < numRows; i++) {
1072 numEnteredPerCol[i] = 0;
1076 for (
int row = 0; row < numRows; row++) {
1077 for (
int entryInRow = 0; entryInRow < entriesPerRow[row]; entryInRow++) {
1078 int col = dataCopy[accum];
1080 rowIndsByColumn[col][numEnteredPerCol[col]] = row;
1081 valuesByColumn[col][numEnteredPerCol[col]] = (mxLogical)1;
1082 numEnteredPerCol[col]++;
1086 for (
int col = 0; col < numRows; col++) {
1087 colPtrs[col] = accum;
1088 accum += entriesPerCol[col];
1090 colPtrs[numRows] = accum;
1091 delete[] numEnteredPerCol;
1092 delete[] rowIndsByColumn;
1093 delete[] valuesByColumn;
1095 delete[] entriesPerRow;
1096 delete[] entriesPerCol;
1098 auto boundaryFlags = data->GetBoundaryNodeMap();
1099 int numBoundaryNodes = 0;
1100 for (
int i = 0; i < (int)boundaryFlags.size(); i++) {
1101 if (boundaryFlags[i])
1104 cout <<
"Graph has " << numBoundaryNodes <<
" Dirichlet boundary nodes." << endl;
1105 mwSize dims[] = {(mwSize)numBoundaryNodes, 1};
1106 mxArray* boundaryList = mxCreateNumericArray(2, dims, mxINT32_CLASS, mxREAL);
1107 int* dest = (
int*)mxGetData(boundaryList);
1108 int* destIter = dest;
1109 for (
int i = 0; i < (int)boundaryFlags.size(); i++) {
1110 if (boundaryFlags[i]) {
1115 mxArray* constructArgs[] = {mat, boundaryList};
1117 mexCallMATLAB(1, out, 2, constructArgs,
"constructGraph");
1198 using namespace std;
1200 typedef RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Matrix_t;
1201 typedef RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > MultiVector_t;
1202 typedef RCP<Aggregates<LocalOrdinal, GlobalOrdinal, Node> > Aggregates_t;
1203 typedef RCP<AmalgamationInfo<LocalOrdinal, GlobalOrdinal, Node> > AmalgamationInfo_t;
1204 typedef RCP<MGraph> Graph_t;
1206 vector<RCP<MuemexArg> > args;
1207 for (
size_t i = 0; i < needsList.size(); i++) {
1208 if (needsList[i] ==
"A" || needsList[i] ==
"P" || needsList[i] ==
"R" || needsList[i] ==
"Ptent") {
1209 Matrix_t mydata = lvl.
Get<Matrix_t>(needsList[i], factory->
GetFactory(needsList[i]).get());
1211 }
else if (needsList[i] ==
"Nullspace" || needsList[i] ==
"Coordinates") {
1212 MultiVector_t mydata = lvl.
Get<MultiVector_t>(needsList[i], factory->
GetFactory(needsList[i]).get());
1214 }
else if (needsList[i] ==
"Aggregates") {
1215 Aggregates_t mydata = lvl.
Get<Aggregates_t>(needsList[i], factory->
GetFactory(needsList[i]).get());
1217 }
else if (needsList[i] ==
"UnAmalgamationInfo") {
1218 AmalgamationInfo_t mydata = lvl.
Get<AmalgamationInfo_t>(needsList[i], factory->
GetFactory(needsList[i]).get());
1220 }
else if (needsList[i] ==
"Level") {
1223 }
else if (needsList[i] ==
"Graph") {
1224 Graph_t mydata = lvl.
Get<Graph_t>(needsList[i], factory->
GetFactory(needsList[i]).get());
1227 vector<string> words;
1228 string badNameMsg =
"Custom Muemex variables in \"Needs\" list require a type and a name, e.g. \"double myVal\". \n Leading and trailing spaces are OK. \n Don't know how to handle \"" + needsList[i] +
"\".\n";
1230 char* buf = (
char*)malloc(needsList[i].size() + 1);
1231 strcpy(buf, needsList[i].c_str());
1232 for (
char* iter = buf; *iter !=
' '; iter++) {
1235 throw runtime_error(badNameMsg);
1237 *iter = (char)tolower(*iter);
1239 const char* wordDelim =
" ";
1240 char* mark = strtok(buf, wordDelim);
1241 while (mark != NULL) {
1242 string wordStr(mark);
1243 words.push_back(wordStr);
1244 mark = strtok(NULL, wordDelim);
1246 if (words.size() != 2) {
1248 throw runtime_error(badNameMsg);
1250 char* typeStr = (
char*)words[0].c_str();
1251 if (strstr(typeStr,
"ordinalvector")) {
1252 typedef RCP<Xpetra::Vector<mm_LocalOrd, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > LOVector_t;
1253 LOVector_t mydata = getLevelVariable<LOVector_t>(needsList[i], lvl);
1255 }
else if (strstr(typeStr,
"map")) {
1256 typedef RCP<Xpetra::Map<mm_LocalOrd, mm_GlobalOrd, mm_node_t> > Map_t;
1257 Map_t mydata = getLevelVariable<Map_t>(needsList[i], lvl);
1259 }
else if (strstr(typeStr,
"scalar")) {
1260 Scalar mydata = getLevelVariable<Scalar>(needsList[i], lvl);
1262 }
else if (strstr(typeStr,
"double")) {
1263 double mydata = getLevelVariable<double>(needsList[i], lvl);
1265 }
else if (strstr(typeStr,
"complex")) {
1266 complex_t mydata = getLevelVariable<complex_t>(needsList[i], lvl);
1268 }
else if (strstr(typeStr,
"matrix")) {
1269 Matrix_t mydata = getLevelVariable<Matrix_t>(needsList[i], lvl);
1271 }
else if (strstr(typeStr,
"multivector")) {
1272 MultiVector_t mydata = getLevelVariable<MultiVector_t>(needsList[i], lvl);
1274 }
else if (strstr(typeStr,
"int")) {
1275 int mydata = getLevelVariable<int>(needsList[i], lvl);
1277 }
else if (strstr(typeStr,
"string")) {
1278 string mydata = getLevelVariable<string>(needsList[i], lvl);
1282 throw std::runtime_error(words[0] +
" is not a known variable type.");
1292 using namespace std;
1294 typedef RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Matrix_t;
1295 typedef RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > MultiVector_t;
1296 typedef RCP<Aggregates<LocalOrdinal, GlobalOrdinal, Node> > Aggregates_t;
1297 typedef RCP<AmalgamationInfo<LocalOrdinal, GlobalOrdinal, Node> > AmalgamationInfo_t;
1298 typedef RCP<MGraph> Graph_t;
1300 for (
size_t i = 0; i < size_t(provides.size()); i++) {
1301 if (provides[i] ==
"A" || provides[i] ==
"P" || provides[i] ==
"R" || provides[i] ==
"Ptent") {
1302 RCP<MuemexData<Matrix_t> > mydata = Teuchos::rcp_static_cast<MuemexData<Matrix_t> >(mexOutput[i]);
1303 lvl.
Set(provides[i], mydata->getData(), factory);
1304 }
else if (provides[i] ==
"Nullspace" || provides[i] ==
"Coordinates") {
1305 RCP<MuemexData<MultiVector_t> > mydata = Teuchos::rcp_static_cast<MuemexData<MultiVector_t> >(mexOutput[i]);
1306 lvl.
Set(provides[i], mydata->getData(), factory);
1307 }
else if (provides[i] ==
"Aggregates") {
1308 RCP<MuemexData<Aggregates_t> > mydata = Teuchos::rcp_static_cast<MuemexData<Aggregates_t> >(mexOutput[i]);
1309 lvl.
Set(provides[i], mydata->getData(), factory);
1310 }
else if (provides[i] ==
"UnAmalgamationInfo") {
1311 RCP<MuemexData<AmalgamationInfo_t> > mydata = Teuchos::rcp_static_cast<MuemexData<AmalgamationInfo_t> >(mexOutput[i]);
1312 lvl.
Set(provides[i], mydata->getData(), factory);
1313 }
else if (provides[i] ==
"Graph") {
1314 RCP<MuemexData<Graph_t> > mydata = Teuchos::rcp_static_cast<MuemexData<Graph_t> >(mexOutput[i]);
1315 lvl.
Set(provides[i], mydata->getData(), factory);
1317 vector<string> words;
1318 string badNameMsg =
"Custom Muemex variables in \"Provides\" list require a type and a name, e.g. \"double myVal\". \n Leading and trailing spaces are OK. \n Don't know how to handle \"" + provides[i] +
"\".\n";
1320 char* buf = (
char*)malloc(provides[i].size() + 1);
1321 strcpy(buf, provides[i].c_str());
1322 for (
char* iter = buf; *iter !=
' '; iter++) {
1325 throw runtime_error(badNameMsg);
1327 *iter = (char)tolower(*iter);
1329 const char* wordDelim =
" ";
1330 char* mark = strtok(buf, wordDelim);
1331 while (mark != NULL) {
1332 string wordStr(mark);
1333 words.push_back(wordStr);
1334 mark = strtok(NULL, wordDelim);
1336 if (words.size() != 2) {
1338 throw runtime_error(badNameMsg);
1340 const char* typeStr = words[0].c_str();
1341 if (strstr(typeStr,
"ordinalvector")) {
1342 typedef RCP<Xpetra::Vector<mm_LocalOrd, mm_LocalOrd, mm_GlobalOrd, mm_node_t> > LOVector_t;
1343 RCP<MuemexData<LOVector_t> > mydata = Teuchos::rcp_static_cast<MuemexData<LOVector_t> >(mexOutput[i]);
1344 addLevelVariable<LOVector_t>(mydata->getData(), words[1], lvl, factory);
1345 }
else if (strstr(typeStr,
"map")) {
1346 typedef RCP<Xpetra::Map<mm_LocalOrd, mm_GlobalOrd, mm_node_t> > Map_t;
1347 RCP<MuemexData<Map_t> > mydata = Teuchos::rcp_static_cast<MuemexData<Map_t> >(mexOutput[i]);
1348 addLevelVariable<Map_t>(mydata->getData(), words[1], lvl, factory);
1349 }
else if (strstr(typeStr,
"scalar")) {
1350 RCP<MuemexData<Scalar> > mydata = Teuchos::rcp_static_cast<MuemexData<Scalar> >(mexOutput[i]);
1351 addLevelVariable<Scalar>(mydata->getData(), words[1], lvl, factory);
1352 }
else if (strstr(typeStr,
"double")) {
1353 RCP<MuemexData<double> > mydata = Teuchos::rcp_static_cast<MuemexData<double> >(mexOutput[i]);
1354 addLevelVariable<double>(mydata->getData(), words[1], lvl, factory);
1355 }
else if (strstr(typeStr,
"complex")) {
1356 RCP<MuemexData<complex_t> > mydata = Teuchos::rcp_static_cast<MuemexData<complex_t> >(mexOutput[i]);
1357 addLevelVariable<complex_t>(mydata->getData(), words[1], lvl, factory);
1358 }
else if (strstr(typeStr,
"matrix")) {
1359 RCP<MuemexData<Matrix_t> > mydata = Teuchos::rcp_static_cast<MuemexData<Matrix_t> >(mexOutput[i]);
1360 addLevelVariable<Matrix_t>(mydata->getData(), words[1], lvl, factory);
1361 }
else if (strstr(typeStr,
"multivector")) {
1362 RCP<MuemexData<MultiVector_t> > mydata = Teuchos::rcp_static_cast<MuemexData<MultiVector_t> >(mexOutput[i]);
1363 addLevelVariable<MultiVector_t>(mydata->getData(), words[1], lvl, factory);
1364 }
else if (strstr(typeStr,
"int")) {
1365 RCP<MuemexData<int> > mydata = Teuchos::rcp_static_cast<MuemexData<int> >(mexOutput[i]);
1366 addLevelVariable<int>(mydata->getData(), words[1], lvl, factory);
1367 }
else if (strstr(typeStr,
"bool")) {
1368 RCP<MuemexData<bool> > mydata = Teuchos::rcp_static_cast<MuemexData<bool> >(mexOutput[i]);
1369 addLevelVariable<bool>(mydata->getData(), words[1], lvl, factory);
1370 }
else if (strstr(typeStr,
"string")) {
1371 RCP<MuemexData<string> > mydata = Teuchos::rcp_static_cast<MuemexData<string> >(mexOutput[i]);
1372 addLevelVariable<string>(mydata->getData(), words[1], lvl, factory);
1375 throw std::runtime_error(words[0] +
" is not a known variable type.");
1386 throw std::runtime_error(
"Muemex does not support long long for global indices");
1391 throw std::runtime_error(
"Muemex does not support long long for global indices");