Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9fb1132

Browse files
committedAug 21, 2019
Simplify code by return Views instead of passing them by references
1 parent ebbf9f8 commit 9fb1132

File tree

2 files changed

+74
-74
lines changed

2 files changed

+74
-74
lines changed
 

‎packages/Discretization/src/DTK_PointSearch_decl.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ class PointSearch
8080
* @note This function should be <b>private</b> but lambda functions can
8181
* only be called from a public function in CUDA.
8282
*/
83-
void filterTopology(
83+
std::tuple<Kokkos::View<int *, DeviceType>,
84+
Kokkos::View<double **, DeviceType>,
85+
Kokkos::View<int *, DeviceType>, Kokkos::View<int *, DeviceType>>
86+
filterTopology(
8487
Kokkos::View<unsigned int *, DeviceType> topo, unsigned int topo_id,
88+
unsigned int size,
8589
Kokkos::View<unsigned int **, DeviceType> bounding_box_to_cell,
8690
Kokkos::View<int *, DeviceType> cell_indices,
8791
Kokkos::View<ArborX::Point *, DeviceType> points,
8892
Kokkos::View<int *, DeviceType> query_ids,
89-
Kokkos::View<int *, DeviceType> ranks,
90-
Kokkos::View<int *, DeviceType> filtered_cell_indices,
91-
Kokkos::View<double **, DeviceType> filtered_points,
92-
Kokkos::View<int *, DeviceType> filtered_query_ids,
93-
Kokkos::View<int *, DeviceType> filtered_ranks );
93+
Kokkos::View<int *, DeviceType> ranks );
9494

9595
/**
9696
* Keep data corresponding to points found inside the reference cell.
@@ -122,20 +122,19 @@ class PointSearch
122122
* Compute the position in the reference frame of candidates found by the
123123
* search.
124124
*/
125-
void performPointInCell(
125+
std::tuple<Kokkos::View<int *, DeviceType>, Kokkos::View<int *, DeviceType>,
126+
Kokkos::View<double **, DeviceType>,
127+
Kokkos::View<bool *, DeviceType>,
128+
Kokkos::View<int *, DeviceType>>
129+
performPointInCell(
126130
Kokkos::View<double ***, DeviceType> cells,
127131
Kokkos::View<unsigned int **, DeviceType> bounding_box_to_cell,
128132
Kokkos::View<int *, DeviceType> imported_cell_indices,
129133
Kokkos::View<ArborX::Point *, DeviceType> imported_points,
130134
Kokkos::View<int *, DeviceType> imported_query_ids,
131135
Kokkos::View<int *, DeviceType> imported_ranks,
132136
Kokkos::View<unsigned int *, DeviceType> topo, unsigned int topo_id,
133-
Kokkos::View<double **, DeviceType> filtered_points,
134-
Kokkos::View<int *, DeviceType> filtered_cell_indices,
135-
Kokkos::View<int *, DeviceType> filtered_query_ids,
136-
Kokkos::View<double **, DeviceType> reference_points,
137-
Kokkos::View<bool *, DeviceType> point_in_cell,
138-
Kokkos::View<int *, DeviceType> ranks );
137+
unsigned int size );
139138

140139
/**
141140
* Build the target-to-source distributor.

‎packages/Discretization/src/DTK_PointSearch_def.hpp

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,10 @@ PointSearch<DeviceType>::PointSearch(
215215
// Perform the distributed search. At the end of the distributed search the
216216
// points are moved from the "source processors" to the "target processors".
217217
std::array<Kokkos::View<int *, DeviceType>, DTK_N_TOPO> per_topo_ranks;
218-
Kokkos::View<ArborX::Point *, DeviceType> imported_points(
219-
"imported_points", 0 );
220-
Kokkos::View<int *, DeviceType> imported_query_ids( "imported_query_ids",
221-
0 );
222-
Kokkos::View<int *, DeviceType> imported_cell_indices( "imported_indices",
223-
0 );
224-
Kokkos::View<int *, DeviceType> imported_ranks( "imported_ranks", 0 );
218+
Kokkos::View<ArborX::Point *, DeviceType> imported_points;
219+
Kokkos::View<int *, DeviceType> imported_query_ids;
220+
Kokkos::View<int *, DeviceType> imported_cell_indices;
221+
Kokkos::View<int *, DeviceType> imported_ranks;
225222
std::tie( imported_points, imported_cell_indices, imported_query_ids,
226223
imported_ranks ) =
227224
performDistributedSearch(
@@ -251,41 +248,19 @@ PointSearch<DeviceType>::PointSearch(
251248
filtered_per_topo_point_in_cell;
252249
std::array<Kokkos::View<int *, DeviceType>, DTK_N_TOPO>
253250
filtered_per_topo_ranks;
254-
for ( unsigned int i = 0; i < DTK_N_TOPO; ++i )
255-
{
256-
filtered_per_topo_cell_indices[i] = Kokkos::View<int *, DeviceType>(
257-
"filtered_per_topo_cell_indices_" + std::to_string( i ),
258-
topo_size_host( i ) );
259-
filtered_per_topo_query_ids[i] = Kokkos::View<int *, DeviceType>(
260-
"filtered_per_topo_query_ids_" + std::to_string( i ),
261-
topo_size_host( i ) );
262-
filtered_per_topo_reference_points[i] =
263-
Kokkos::View<double **, DeviceType>(
264-
"filtered_per_topo_reference_points_" + std::to_string( i ),
265-
topo_size_host( i ), _dim );
266-
filtered_per_topo_point_in_cell[i] = Kokkos::View<bool *, DeviceType>(
267-
"filtered_per_topo_point_in_cell_" + std::to_string( i ),
268-
topo_size_host( i ) );
269-
filtered_per_topo_ranks[i] = Kokkos::View<int *, DeviceType>(
270-
"filtered_per_topo_ranks_" + std::to_string( i ),
271-
topo_size_host( i ) );
272-
}
273-
274251
// Check if the points are in the cells
275252
for ( unsigned int topo_id = 0; topo_id < DTK_N_TOPO; ++topo_id )
276253
if ( block_cells[topo_id].extent( 0 ) != 0 )
277254
{
278-
Kokkos::View<double **, DeviceType> filtered_points(
279-
"filtered_points", topo_size_host( topo_id ), _dim );
280-
performPointInCell( block_cells[topo_id], bounding_box_to_cell,
281-
imported_cell_indices, imported_points,
282-
imported_query_ids, imported_ranks, topo,
283-
topo_id, filtered_points,
284-
filtered_per_topo_cell_indices[topo_id],
285-
filtered_per_topo_query_ids[topo_id],
286-
filtered_per_topo_reference_points[topo_id],
287-
filtered_per_topo_point_in_cell[topo_id],
288-
filtered_per_topo_ranks[topo_id] );
255+
std::tie( filtered_per_topo_cell_indices[topo_id],
256+
filtered_per_topo_query_ids[topo_id],
257+
filtered_per_topo_reference_points[topo_id],
258+
filtered_per_topo_point_in_cell[topo_id],
259+
filtered_per_topo_ranks[topo_id] ) =
260+
performPointInCell( block_cells[topo_id], bounding_box_to_cell,
261+
imported_cell_indices, imported_points,
262+
imported_query_ids, imported_ranks, topo,
263+
topo_id, topo_size_host( topo_id ) );
289264
}
290265

291266
// Filter the points. Only keep the points that are in cell
@@ -457,17 +432,16 @@ PointSearch<DeviceType>::performDistributedSearch(
457432
}
458433

459434
template <typename DeviceType>
460-
void PointSearch<DeviceType>::filterTopology(
435+
std::tuple<Kokkos::View<int *, DeviceType>, Kokkos::View<double **, DeviceType>,
436+
Kokkos::View<int *, DeviceType>, Kokkos::View<int *, DeviceType>>
437+
PointSearch<DeviceType>::filterTopology(
461438
Kokkos::View<unsigned int *, DeviceType> topo, unsigned int topo_id,
439+
unsigned int size,
462440
Kokkos::View<unsigned int **, DeviceType> bounding_box_to_cell,
463441
Kokkos::View<int *, DeviceType> cell_indices,
464442
Kokkos::View<ArborX::Point *, DeviceType> points,
465443
Kokkos::View<int *, DeviceType> query_ids,
466-
Kokkos::View<int *, DeviceType> ranks,
467-
Kokkos::View<int *, DeviceType> filtered_cell_indices,
468-
Kokkos::View<double **, DeviceType> filtered_points,
469-
Kokkos::View<int *, DeviceType> filtered_query_ids,
470-
Kokkos::View<int *, DeviceType> filtered_ranks )
444+
Kokkos::View<int *, DeviceType> ranks )
471445
{
472446
DTK_REQUIRE( topo.extent( 0 ) == ranks.extent( 0 ) );
473447
DTK_REQUIRE( query_ids.extent( 0 ) == ranks.extent( 0 ) );
@@ -481,22 +455,34 @@ void PointSearch<DeviceType>::filterTopology(
481455
// Create Kokkos::View with the points and the cell indices associated
482456
// with cells of topo_id topology. Also transform 3D points back to 2D
483457
// points.
458+
Kokkos::View<double **, DeviceType> filtered_per_topo_points(
459+
"filtered_per_topo_points", size, _dim );
460+
Kokkos::View<int *, DeviceType> filtered_per_topo_cell_indices(
461+
"filtered_per_topo_cell_indices_" + std::to_string( topo_id ), size );
462+
Kokkos::View<int *, DeviceType> filtered_per_topo_query_ids(
463+
"filtered_per_topo_query_ids_" + std::to_string( topo_id ), size );
464+
Kokkos::View<int *, DeviceType> filtered_per_topo_ranks(
465+
"filtered_per_topo_ranks_" + std::to_string( topo_id ), size );
484466
unsigned int dim = _dim;
485467
Kokkos::parallel_for(
486468
"filter_data", Kokkos::RangePolicy<ExecutionSpace>( 0, n_imports ),
487469
KOKKOS_LAMBDA( int const i ) {
488470
if ( topo( i ) == topo_id )
489471
{
490472
unsigned int const k = offset( i );
491-
filtered_cell_indices( k ) =
473+
filtered_per_topo_cell_indices( k ) =
492474
bounding_box_to_cell( cell_indices( i ), topo_id );
493475
for ( unsigned int j = 0; j < dim; ++j )
494-
filtered_points( k, j ) = points( i )[j];
495-
filtered_query_ids( k ) = query_ids( i );
496-
filtered_ranks( k ) = ranks( i );
476+
filtered_per_topo_points( k, j ) = points( i )[j];
477+
filtered_per_topo_query_ids( k ) = query_ids( i );
478+
filtered_per_topo_ranks( k ) = ranks( i );
497479
}
498480
} );
499481
Kokkos::fence();
482+
483+
return std::make_tuple(
484+
filtered_per_topo_cell_indices, filtered_per_topo_points,
485+
filtered_per_topo_query_ids, filtered_per_topo_ranks );
500486
}
501487

502488
template <typename DeviceType>
@@ -580,31 +566,46 @@ void PointSearch<DeviceType>::filterInCell(
580566
}
581567

582568
template <typename DeviceType>
583-
void PointSearch<DeviceType>::performPointInCell(
569+
std::tuple<Kokkos::View<int *, DeviceType>, Kokkos::View<int *, DeviceType>,
570+
Kokkos::View<double **, DeviceType>,
571+
Kokkos::View<bool *, DeviceType>, Kokkos::View<int *, DeviceType>>
572+
PointSearch<DeviceType>::performPointInCell(
584573
Kokkos::View<double ***, DeviceType> cells,
585574
Kokkos::View<unsigned int **, DeviceType> bounding_box_to_cell,
586575
Kokkos::View<int *, DeviceType> imported_cell_indices,
587576
Kokkos::View<ArborX::Point *, DeviceType> imported_points,
588577
Kokkos::View<int *, DeviceType> imported_query_ids,
589578
Kokkos::View<int *, DeviceType> imported_ranks,
590579
Kokkos::View<unsigned int *, DeviceType> topo, unsigned int topo_id,
591-
Kokkos::View<double **, DeviceType> filtered_points,
592-
Kokkos::View<int *, DeviceType> filtered_cell_indices,
593-
Kokkos::View<int *, DeviceType> filtered_query_ids,
594-
Kokkos::View<double **, DeviceType> reference_points,
595-
Kokkos::View<bool *, DeviceType> point_in_cell,
596-
Kokkos::View<int *, DeviceType> filtered_ranks )
580+
unsigned int size )
597581
{
598-
filterTopology( topo, topo_id, bounding_box_to_cell, imported_cell_indices,
599-
imported_points, imported_query_ids, imported_ranks,
600-
filtered_cell_indices, filtered_points, filtered_query_ids,
601-
filtered_ranks );
582+
Kokkos::View<double **, DeviceType> filtered_per_topo_points;
583+
Kokkos::View<int *, DeviceType> filtered_per_topo_cell_indices;
584+
Kokkos::View<int *, DeviceType> filtered_per_topo_query_ids;
585+
Kokkos::View<int *, DeviceType> filtered_per_topo_ranks;
586+
587+
std::tie( filtered_per_topo_cell_indices, filtered_per_topo_points,
588+
filtered_per_topo_query_ids, filtered_per_topo_ranks ) =
589+
filterTopology( topo, topo_id, size, bounding_box_to_cell,
590+
imported_cell_indices, imported_points,
591+
imported_query_ids, imported_ranks );
602592

603593
// Perform the PointInCell search
604594
Topologies topologies;
595+
Kokkos::View<double **, DeviceType> filtered_per_topo_reference_points(
596+
"filtered_per_topo_reference_points_" + std::to_string( topo_id ), size,
597+
_dim );
598+
Kokkos::View<bool *, DeviceType> filtered_per_topo_point_in_cell(
599+
"filtered_per_topo_point_in_cell_" + std::to_string( topo_id ), size );
605600
PointInCell<DeviceType>::search(
606-
filtered_points, cells, filtered_cell_indices, topologies[topo_id].topo,
607-
reference_points, point_in_cell );
601+
filtered_per_topo_points, cells, filtered_per_topo_cell_indices,
602+
topologies[topo_id].topo, filtered_per_topo_reference_points,
603+
filtered_per_topo_point_in_cell );
604+
605+
return std::make_tuple(
606+
filtered_per_topo_cell_indices, filtered_per_topo_query_ids,
607+
filtered_per_topo_reference_points, filtered_per_topo_point_in_cell,
608+
filtered_per_topo_ranks );
608609
}
609610

610611
template <typename DeviceType>

0 commit comments

Comments
 (0)
This repository has been archived.