177 symmetrize(
const Teuchos::RCP<Teuchos::ParameterList>& params) {
181 using range_type = Kokkos::RangePolicy<execution_space, size_t>;
184 using row_ptrs_array =
typename local_graph_device_type::row_map_type::non_const_type;
185 using col_inds_array =
typename local_graph_device_type::entries_type::non_const_type;
187 using global_col_inds_array =
typename Kokkos::View<GlobalOrdinal*, device_type>;
189 auto graph = origGraph_;
190 auto domain_map = graph->getDomainMap();
191 auto range_map = graph->getRangeMap();
192 auto row_map = graph->getRowMap();
193 auto col_map = graph->getColMap();
194 RCP<const map_type> col_map_sym;
195 RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > importer;
197 TEUCHOS_ASSERT(domain_map->isSameAs(*range_map));
198 TEUCHOS_ASSERT(domain_map->isSameAs(*row_map));
203 auto col_map_T = graphT->getColMap();
204 TEUCHOS_ASSERT(!col_map_T.is_null());
205 TEUCHOS_ASSERT(domain_map->isSameAs(*graphT->getDomainMap()));
207 bool graphSorted = graph->isSorted();
208 bool graphTSorted = graphT->isSorted();
209 bool sorted = graphSorted && graphTSorted;
210 bool matchingColMaps = col_map->isSameAs(*col_map_T);
212 auto lclGraph = graph->getLocalGraphDevice();
213 auto lclGraphT = graphT->getLocalGraphDevice();
215 using KKH_LO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, LocalOrdinal,
impl_scalar_type,
216 typename Node::execution_space,
typename Node::memory_space,
typename Node::memory_space>;
217 using KKH_GO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, GlobalOrdinal,
impl_scalar_type,
218 typename Node::execution_space,
typename Node::memory_space,
typename Node::memory_space>;
220 auto rowptrs = lclGraph.row_map;
221 auto rowptrsT = lclGraphT.row_map;
222 auto colinds = lclGraph.entries;
223 auto colindsT = lclGraphT.entries;
225 auto nrows = rowptrs.extent(0) - 1;
226 auto rowptrsSym = row_ptrs_array(Kokkos::ViewAllocateWithoutInitializing(
"row ptrs sym"), nrows + 1);
228 col_inds_array colindsSym;
230 if (!matchingColMaps) {
232 auto lclColmap = col_map->getLocalMap();
233 global_col_inds_array colindsConverted(Kokkos::ViewAllocateWithoutInitializing(
"colinds (converted)"), colinds.extent(0));
234 ConvertLocalToGlobalFunctor<GlobalOrdinal, col_inds_array, global_col_inds_array, local_map_type> convert(colinds, colindsConverted, lclColmap);
235 Kokkos::parallel_for(
"colInds (converted)", range_type(0, colinds.extent(0)), convert);
238 auto lclColmapT = col_map_T->getLocalMap();
239 global_col_inds_array colindsTConverted(Kokkos::ViewAllocateWithoutInitializing(
"colindsT (converted)"), colindsT.extent(0));
240 ConvertLocalToGlobalFunctor<GlobalOrdinal, col_inds_array, global_col_inds_array, local_map_type> convertT(colindsT, colindsTConverted, lclColmapT);
241 Kokkos::parallel_for(
"colIndsT (converted)", range_type(0, colindsT.extent(0)), convertT);
245 handle.create_spadd_handle(
false);
246 auto addHandle = handle.get_spadd_handle();
248 global_col_inds_array globalColindsSym;
250 KokkosSparse::spadd_symbolic(&handle,
251 nrows, graph->getGlobalNumCols(),
252 rowptrs, colindsConverted, rowptrsT, colindsTConverted, rowptrsSym);
253 globalColindsSym = global_col_inds_array(Kokkos::ViewAllocateWithoutInitializing(
"global colinds sym"), addHandle->get_c_nnz());
255 UnsortedNumericIndicesOnlyFunctor<
256 size_t, GlobalOrdinal,
257 typename row_ptrs_array::const_type,
typename row_ptrs_array::const_type, row_ptrs_array,
258 typename global_col_inds_array::const_type,
typename global_col_inds_array::const_type, global_col_inds_array>
259 unsortedNumeric(rowptrs, rowptrsT, rowptrsSym,
260 colindsConverted, colindsTConverted, globalColindsSym,
261 addHandle->get_a_pos(), addHandle->get_b_pos());
262 Kokkos::parallel_for(
"KokkosSparse::SpAdd:Numeric::InputNotSorted",
263 range_type(0, nrows), unsortedNumeric);
269 auto lclColmapSym = col_map_sym->getLocalMap();
270 colindsSym = col_inds_array(
"colindsSym", globalColindsSym.extent(0));
271 ConvertGlobalToLocalFunctor<LocalOrdinal, GlobalOrdinal, col_inds_array, global_col_inds_array, typename map_type::local_map_type> convertSym(colindsSym, globalColindsSym, lclColmapSym);
272 Kokkos::parallel_for(range_type(0, globalColindsSym.extent(0)), convertSym);
277 handle.create_spadd_handle(sorted);
278 auto addHandle = handle.get_spadd_handle();
280 KokkosSparse::spadd_symbolic(&handle,
281 nrows, graph->getGlobalNumCols(),
282 rowptrs, colinds, rowptrsT, colindsT, rowptrsSym);
283 colindsSym = col_inds_array(Kokkos::ViewAllocateWithoutInitializing(
"C colinds"), addHandle->get_c_nnz());
286 SortedNumericIndicesOnlyFunctor<
287 size_t, LocalOrdinal,
288 typename row_ptrs_array::const_type,
typename row_ptrs_array::const_type, row_ptrs_array,
289 typename col_inds_array::const_type,
typename col_inds_array::const_type, col_inds_array>
290 sortedNumeric(rowptrs, rowptrsT, rowptrsSym,
291 colinds, colindsT, colindsSym);
292 Kokkos::parallel_for(
"KokkosSparse::SpAdd:Numeric::InputSorted",
293 range_type(0, nrows), sortedNumeric);
296 UnsortedNumericIndicesOnlyFunctor<
297 size_t, LocalOrdinal,
298 typename row_ptrs_array::const_type,
typename row_ptrs_array::const_type, row_ptrs_array,
299 typename col_inds_array::const_type,
typename col_inds_array::const_type, col_inds_array>
300 unsortedNumeric(rowptrs, rowptrsT, rowptrsSym,
301 colinds, colindsT, colindsSym,
302 addHandle->get_a_pos(), addHandle->get_b_pos());
303 Kokkos::parallel_for(
"KokkosSparse::SpAdd:Numeric::InputNotSorted",
304 range_type(0, nrows), unsortedNumeric);
308 col_map_sym = col_map;
309 importer = graph->getImporter();
318 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
320 graphParams = rcp(
new Teuchos::ParameterList);
321 graphParams->set(
"sorted",
false);
324 return rcp(
new crs_graph_type(lclGraphSym,
376 using Teuchos::rcp_dynamic_cast;
377 using LO = LocalOrdinal;
378 using GO = GlobalOrdinal;
384 const bool sort = [&]() {
385 constexpr bool sortDefault =
true;
386 const char sortParamName[] =
"sort";
387 return params.get() ==
nullptr ? sortDefault : params->get(sortParamName, sortDefault);
394 using c_rowmap_t =
typename local_graph_device_type::row_map_type;
395 using c_entries_t =
typename local_graph_device_type::entries_type;
396 using rowmap_t =
typename local_graph_device_type::row_map_type::non_const_type;
397 using entries_t =
typename local_graph_device_type::entries_type::non_const_type;
398 LocalOrdinal numCols = origGraph_->
getColMap()->getLocalNumElements();
399 rowmap_t lclGraphT_rowmap(
"Transpose rowmap", numCols + 1);
400 entries_t lclGraphT_entries(
401 Kokkos::ViewAllocateWithoutInitializing(
"Transpose entries"), lclGraph.entries.extent(0));
402 KokkosSparse::Impl::transpose_graph<
403 c_rowmap_t, c_entries_t,
405 rowmap_t,
typename local_graph_device_type::execution_space>(
406 lclGraph.numRows(), numCols,
407 lclGraph.row_map, lclGraph.entries,
408 lclGraphT_rowmap, lclGraphT_entries);
418 const auto origExport = origGraph_->getExporter();
419 RCP<const import_type> myImport = origExport.is_null() ? Teuchos::null : rcp(
new import_type(*origExport));
420 const auto origImport = origGraph_->getImporter();
421 RCP<const export_type> myExport = origImport.is_null() ? Teuchos::null : rcp(
new export_type(*origImport));
423 RCP<Teuchos::ParameterList> graphParams = Teuchos::null;
425 graphParams = rcp(
new Teuchos::ParameterList);
426 graphParams->set(
"sorted",
false);
429 return rcp(
new crs_graph_type(lclGraphT,
431 origGraph_->getRowMap(),
432 origGraph_->getRangeMap(),
433 origGraph_->getDomainMap(),
434 myImport, myExport, graphParams));