182 symmetrize(
const Teuchos::RCP<Teuchos::ParameterList>& params) {
186 using range_type = Kokkos::RangePolicy<execution_space, size_t>;
189 using row_ptrs_array =
typename local_graph_device_type::row_map_type::non_const_type;
190 using col_inds_array =
typename local_graph_device_type::entries_type::non_const_type;
192 using global_col_inds_array =
typename Kokkos::View<GlobalOrdinal*, device_type>;
194 auto graph = origGraph_;
195 auto domain_map = graph->getDomainMap();
196 auto range_map = graph->getRangeMap();
197 auto row_map = graph->getRowMap();
198 auto col_map = graph->getColMap();
199 RCP<const map_type> col_map_sym;
200 RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > importer;
202 TEUCHOS_ASSERT(domain_map->isSameAs(*range_map));
203 TEUCHOS_ASSERT(domain_map->isSameAs(*row_map));
208 auto col_map_T = graphT->getColMap();
209 TEUCHOS_ASSERT(!col_map_T.is_null());
210 TEUCHOS_ASSERT(domain_map->isSameAs(*graphT->getDomainMap()));
212 bool graphSorted = graph->isSorted();
213 bool graphTSorted = graphT->isSorted();
214 bool sorted = graphSorted && graphTSorted;
215 bool matchingColMaps = col_map->isSameAs(*col_map_T);
217 auto lclGraph = graph->getLocalGraphDevice();
218 auto lclGraphT = graphT->getLocalGraphDevice();
220 using KKH_LO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, LocalOrdinal,
impl_scalar_type,
221 typename Node::execution_space,
typename Node::memory_space,
typename Node::memory_space>;
222 using KKH_GO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, GlobalOrdinal,
impl_scalar_type,
223 typename Node::execution_space,
typename Node::memory_space,
typename Node::memory_space>;
225 auto rowptrs = lclGraph.row_map;
226 auto rowptrsT = lclGraphT.row_map;
227 auto colinds = lclGraph.entries;
228 auto colindsT = lclGraphT.entries;
230 auto nrows = rowptrs.extent(0) - 1;
231 auto rowptrsSym = row_ptrs_array(Kokkos::ViewAllocateWithoutInitializing(
"row ptrs sym"), nrows + 1);
233 col_inds_array colindsSym;
235 if (!matchingColMaps) {
237 auto lclColmap = col_map->getLocalMap();
238 global_col_inds_array colindsConverted(Kokkos::ViewAllocateWithoutInitializing(
"colinds (converted)"), colinds.extent(0));
239 ConvertLocalToGlobalFunctor<GlobalOrdinal, col_inds_array, global_col_inds_array, local_map_type> convert(colinds, colindsConverted, lclColmap);
240 Kokkos::parallel_for(
"colInds (converted)", range_type(0, colinds.extent(0)), convert);
243 auto lclColmapT = col_map_T->getLocalMap();
244 global_col_inds_array colindsTConverted(Kokkos::ViewAllocateWithoutInitializing(
"colindsT (converted)"), colindsT.extent(0));
245 ConvertLocalToGlobalFunctor<GlobalOrdinal, col_inds_array, global_col_inds_array, local_map_type> convertT(colindsT, colindsTConverted, lclColmapT);
246 Kokkos::parallel_for(
"colIndsT (converted)", range_type(0, colindsT.extent(0)), convertT);
250 handle.create_spadd_handle(
false);
251 auto addHandle = handle.get_spadd_handle();
253 global_col_inds_array globalColindsSym;
255 KokkosSparse::spadd_symbolic(&handle,
256 nrows, graph->getGlobalNumCols(),
257 rowptrs, colindsConverted, rowptrsT, colindsTConverted, rowptrsSym);
258 globalColindsSym = global_col_inds_array(Kokkos::ViewAllocateWithoutInitializing(
"global colinds sym"), addHandle->get_c_nnz());
260 UnsortedNumericIndicesOnlyFunctor<
261 size_t, GlobalOrdinal,
262 typename row_ptrs_array::const_type,
typename row_ptrs_array::const_type, row_ptrs_array,
263 typename global_col_inds_array::const_type,
typename global_col_inds_array::const_type, global_col_inds_array>
264 unsortedNumeric(rowptrs, rowptrsT, rowptrsSym,
265 colindsConverted, colindsTConverted, globalColindsSym,
266 addHandle->get_a_pos(), addHandle->get_b_pos());
267 Kokkos::parallel_for(
"KokkosSparse::SpAdd:Numeric::InputNotSorted",
268 range_type(0, nrows), unsortedNumeric);
274 auto lclColmapSym = col_map_sym->getLocalMap();
275 colindsSym = col_inds_array(
"colindsSym", globalColindsSym.extent(0));
276 ConvertGlobalToLocalFunctor<LocalOrdinal, GlobalOrdinal, col_inds_array, global_col_inds_array, typename map_type::local_map_type> convertSym(colindsSym, globalColindsSym, lclColmapSym);
277 Kokkos::parallel_for(range_type(0, globalColindsSym.extent(0)), convertSym);
282 handle.create_spadd_handle(sorted);
283 auto addHandle = handle.get_spadd_handle();
285 KokkosSparse::spadd_symbolic(&handle,
286 nrows, graph->getGlobalNumCols(),
287 rowptrs, colinds, rowptrsT, colindsT, rowptrsSym);
288 colindsSym = col_inds_array(Kokkos::ViewAllocateWithoutInitializing(
"C colinds"), addHandle->get_c_nnz());
291 SortedNumericIndicesOnlyFunctor<
292 size_t, LocalOrdinal,
293 typename row_ptrs_array::const_type,
typename row_ptrs_array::const_type, row_ptrs_array,
294 typename col_inds_array::const_type,
typename col_inds_array::const_type, col_inds_array>
295 sortedNumeric(rowptrs, rowptrsT, rowptrsSym,
296 colinds, colindsT, colindsSym);
297 Kokkos::parallel_for(
"KokkosSparse::SpAdd:Numeric::InputSorted",
298 range_type(0, nrows), sortedNumeric);
301 UnsortedNumericIndicesOnlyFunctor<
302 size_t, LocalOrdinal,
303 typename row_ptrs_array::const_type,
typename row_ptrs_array::const_type, row_ptrs_array,
304 typename col_inds_array::const_type,
typename col_inds_array::const_type, col_inds_array>
305 unsortedNumeric(rowptrs, rowptrsT, rowptrsSym,
306 colinds, colindsT, colindsSym,
307 addHandle->get_a_pos(), addHandle->get_b_pos());
308 Kokkos::parallel_for(
"KokkosSparse::SpAdd:Numeric::InputNotSorted",
309 range_type(0, nrows), unsortedNumeric);
313 col_map_sym = col_map;
314 importer = graph->getImporter();
319 KokkosSparse::sort_crs_graph<execution_space, row_ptrs_array, col_inds_array>(rowptrsSym, colindsSym);
323 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
325 graphParams = rcp(
new Teuchos::ParameterList);
326 graphParams->set(
"sorted",
false);
329 return rcp(
new crs_graph_type(lclGraphSym,
388 using Teuchos::rcp_dynamic_cast;
389 using LO = LocalOrdinal;
390 using GO = GlobalOrdinal;
394#ifdef HAVE_TPETRA_MMM_TIMINGS
395 std::string prefix = std::string(
"Tpetra ") + label_ +
": ";
396 using Teuchos::TimeMonitor;
397 TimeMonitor MM(*TimeMonitor::getNewTimer(prefix +
"Transpose Local"));
400 const bool sort = [&]() {
401 constexpr bool sortDefault =
true;
402 const char sortParamName[] =
"sort";
403 return params.get() ==
nullptr ? sortDefault : params->get(sortParamName, sortDefault);
410 using c_rowmap_t =
typename local_graph_device_type::row_map_type;
411 using c_entries_t =
typename local_graph_device_type::entries_type;
412 using rowmap_t =
typename local_graph_device_type::row_map_type::non_const_type;
413 using entries_t =
typename local_graph_device_type::entries_type::non_const_type;
414 LocalOrdinal numCols = origGraph_->
getColMap()->getLocalNumElements();
415 rowmap_t lclGraphT_rowmap(
"Transpose rowmap", numCols + 1);
416 entries_t lclGraphT_entries(
417 Kokkos::ViewAllocateWithoutInitializing(
"Transpose entries"), lclGraph.entries.extent(0));
418 KokkosSparse::Impl::transpose_graph<
419 c_rowmap_t, c_entries_t,
421 rowmap_t,
typename local_graph_device_type::execution_space>(
422 lclGraph.numRows(), numCols,
423 lclGraph.row_map, lclGraph.entries,
424 lclGraphT_rowmap, lclGraphT_entries);
427 KokkosSparse::sort_crs_graph<
428 typename local_graph_device_type::execution_space,
429 rowmap_t, entries_t>(
438 const auto origExport = origGraph_->getExporter();
439 RCP<const import_type> myImport = origExport.is_null() ? Teuchos::null : rcp(
new import_type(*origExport));
440 const auto origImport = origGraph_->getImporter();
441 RCP<const export_type> myExport = origImport.is_null() ? Teuchos::null : rcp(
new export_type(*origImport));
443 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
445 graphParams = rcp(
new Teuchos::ParameterList);
446 graphParams->set(
"sorted",
false);
449 return rcp(
new crs_graph_type(lclGraphT,
450 origGraph_->getColMap(),
451 origGraph_->getRowMap(),
452 origGraph_->getRangeMap(),
453 origGraph_->getDomainMap(),
454 myImport, myExport, graphParams));