45 RCP<Matrix> A = Get<RCP<Matrix> >(currentLevel,
"A");
67 LO nStridedOffset = 0;
68 LO stridedblocksize = fullblocksize;
69 LO storageblocksize = A->GetStorageBlockSize();
74 if (A->IsView(
"stridedMaps") && Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap(
"stridedMaps")) != Teuchos::null) {
75 Xpetra::viewLabel_t oldView = A->SwitchToView(
"stridedMaps");
76 RCP<const StridedMap> stridedRowMap = Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap());
77 TEUCHOS_TEST_FOR_EXCEPTION(stridedRowMap == Teuchos::null,
Exceptions::BadCast,
"MueLu::CoalesceFactory::Build: cast to strided row map failed.");
78 fullblocksize = stridedRowMap->getFixedBlockSize();
79 offset = DOFGidOffset(stridedRowMap);
80 blockid = stridedRowMap->getStridedBlockId();
83 std::vector<size_t> stridingInfo = stridedRowMap->getStridingData();
84 for (
size_t j = 0; j < Teuchos::as<size_t>(blockid); j++)
85 nStridedOffset += stridingInfo[j];
86 stridedblocksize = Teuchos::as<LocalOrdinal>(stridingInfo[blockid]);
89 stridedblocksize = fullblocksize;
93 TEUCHOS_TEST_FOR_EXCEPTION(fullblocksize % storageblocksize != 0,
Exceptions::RuntimeError,
"AmalgamationFactory: fullblocksize needs to be a multiple of A->GetStorageBlockSize()");
94 fullblocksize /= storageblocksize;
95 stridedblocksize /= storageblocksize;
97 oldView = A->SwitchToView(oldView);
98 GetOStream(
Runtime1) <<
"AmalagamationFactory::Build():"
99 <<
" found fullblocksize=" << fullblocksize <<
" and stridedblocksize=" << stridedblocksize <<
" from strided maps. offset=" << offset << std::endl;
102 GetOStream(
Warnings0) <<
"AmalagamationFactory::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
109 RCP<const Map> uniqueMap, nonUniqueMap;
110 RCP<AmalgamationInfo> amalgamationData;
111 RCP<Array<LO> > rowTranslation = Teuchos::null;
112 RCP<Array<LO> > colTranslation = Teuchos::null;
114 if (fullblocksize > 1) {
120 RCP<Array<LO> > theRowTranslation = rcp(
new Array<LO>);
121 RCP<Array<LO> > theColTranslation = rcp(
new Array<LO>);
122 AmalgamateMap(*(A->getRowMap()), *A, uniqueMap, *theRowTranslation);
123 AmalgamateMap(*(A->getColMap()), *A, nonUniqueMap, *theColTranslation);
149 Set(currentLevel,
"UnAmalgamationInfo", amalgamationData);
154 typedef typename ArrayView<const GO>::size_type size_type;
155 typedef std::unordered_map<GO, size_type> container;
157 GO indexBase = sourceMap.getIndexBase();
158 ArrayView<const GO> elementAList = sourceMap.getLocalElementList();
159 size_type numElements = elementAList.size();
163 LO blkSize = A.GetFixedBlockSize() / A.GetStorageBlockSize();
164 if (A.IsView(
"stridedMaps") ==
true) {
165 Teuchos::RCP<const Map> myMap = A.getRowMap(
"stridedMaps");
166 Teuchos::RCP<const StridedMap> strMap = Teuchos::rcp_dynamic_cast<const StridedMap>(myMap);
168 offset = DOFGidOffset(strMap);
169 blkSize = Teuchos::as<const LO>(strMap->getFixedBlockSize());
172 Array<GO> elementList(numElements);
173 translation.resize(numElements);
175 size_type numRows = 0;
176 for (size_type
id = 0;
id < numElements;
id++) {
177 GO dofID = elementAList[id];
180 typename container::iterator it = filter.find(nodeID);
181 if (it == filter.end()) {
182 filter[nodeID] = numRows;
184 translation[id] = numRows;
185 elementList[numRows] = nodeID;
190 translation[id] = it->second;
193 elementList.resize(numRows);
195 amalgamatedMap = MapFactory::Build(sourceMap.lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), elementList, indexBase, sourceMap.getComm());
203 using range_policy = Kokkos::RangePolicy<typename Node::execution_space>;
204 using array_type =
typename Map::global_indices_array_device_type;
206 array_type elementAList = sourceMap->getMyGlobalIndicesDevice();
207 GO indexBase = sourceMap->getIndexBase();
208 LO blkSize = sourceMap->getFixedBlockSize();
209 auto numElements = elementAList.size() / blkSize;
210 typename array_type::non_const_type elementList_nc(
"elementList", numElements);
213 Kokkos::parallel_for(
214 "Amalgamate Element List", range_policy(0, numElements), KOKKOS_LAMBDA(LO i) {
215 elementList_nc[i] = (elementAList[i * blkSize] - indexBase) / blkSize + indexBase;
217 array_type elementList = elementList_nc;
219 amalgamatedMap = MapFactory::Build(sourceMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
220 elementList, indexBase, sourceMap->getComm());
232 GlobalOrdinal offset = stridedRowMap->getMinAllGlobalIndex();
234 size_t nStridedOffset = 0;
235 for (
int j = 0; j < stridedRowMap->getStridedBlockId(); j++) {
236 nStridedOffset += stridedRowMap->getStridingData()[j];
238 const GO goStridedOffset = Teuchos::as<const GO>(nStridedOffset);
240 offset -= goStridedOffset + stridedRowMap->getIndexBase();
static const GlobalOrdinal DOFGid2NodeId(GlobalOrdinal gid, LocalOrdinal blockSize, const GlobalOrdinal offset, const GlobalOrdinal indexBase)
Translate global (row/column) id to global amalgamation block id.