Skip to content

Commit

Permalink
Fixup atomic_{inc,dec}[rement]
Browse files Browse the repository at this point in the history
Signed-off-by: Damien L-G <[email protected]>
  • Loading branch information
dalg24 committed Oct 18, 2024
1 parent 1beef8c commit f78e1f5
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void AggregationPhase1Algorithm<LocalOrdinal, GlobalOrdinal, Node>::
break;
} else {
// Decrement back the value of aggSizesView(agg)
Kokkos::atomic_decrement(&aggSizesView(agg));
Kokkos::atomic_dec(&aggSizesView(agg));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void AggregationPhase3Algorithm<LocalOrdinal, GlobalOrdinal, Node>::
procWinner(nodeIdx, 0) = myRank;
vertex2AggId(nodeIdx, 0) = aggId;
// aggregates.SetIsRoot(nodeIdx);
Kokkos::atomic_decrement(&numNonAggregated());
Kokkos::atomic_dec(&numNonAggregated());
for (int neigh = 0; neigh < neighbors.length; ++neigh) {
neighIdx = neighbors(neigh);
if ((neighIdx != nodeIdx) &&
Expand All @@ -264,7 +264,7 @@ void AggregationPhase3Algorithm<LocalOrdinal, GlobalOrdinal, Node>::
aggStat(neighIdx) = AGGREGATED;
procWinner(neighIdx, 0) = myRank;
vertex2AggId(neighIdx, 0) = aggId;
Kokkos::atomic_decrement(&numNonAggregated());
Kokkos::atomic_dec(&numNonAggregated());
}
}
return;
Expand All @@ -279,7 +279,7 @@ void AggregationPhase3Algorithm<LocalOrdinal, GlobalOrdinal, Node>::
aggStat(nodeIdx) = AGGREGATED;
procWinner(nodeIdx, 0) = myRank;
vertex2AggId(nodeIdx, 0) = vertex2AggId(neighIdx, 0);
Kokkos::atomic_decrement(&numNonAggregated());
Kokkos::atomic_dec(&numNonAggregated());
return;
}
}
Expand All @@ -293,7 +293,7 @@ void AggregationPhase3Algorithm<LocalOrdinal, GlobalOrdinal, Node>::
aggStat(nodeIdx) = AGGREGATED;
procWinner(nodeIdx, 0) = myRank;
vertex2AggId(nodeIdx, 0) = vertex2AggId(otherNodeIdx, 0);
Kokkos::atomic_decrement(&numNonAggregated());
Kokkos::atomic_dec(&numNonAggregated());
return;
}
}
Expand All @@ -306,7 +306,7 @@ void AggregationPhase3Algorithm<LocalOrdinal, GlobalOrdinal, Node>::
aggStat(nodeIdx) = AGGREGATED;
procWinner(nodeIdx, 0) = myRank;
vertex2AggId(nodeIdx, 0) = aggId;
Kokkos::atomic_decrement(&numNonAggregated());
Kokkos::atomic_dec(&numNonAggregated());
}
});
// LBV on 09/27/19: here we could copy numNonAggregated to host
Expand Down
10 changes: 5 additions & 5 deletions packages/nox/test/tpetra/1DFEM_Functors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ struct RowCountsFunctor
void operator() (const LO localRow, std::size_t& curNumLocalEntries) const
{
// Add a diagonal matrix entry
Kokkos::atomic_increment(&counts_(localRow));
Kokkos::atomic_inc(&counts_(localRow));
++curNumLocalEntries;
// Contribute a matrix entry to the previous row
if (localRow > 0) {
Kokkos::atomic_increment(&counts_(localRow-1));
Kokkos::atomic_inc(&counts_(localRow-1));
++curNumLocalEntries;
}
// Contribute a matrix entry to the next row
if (localRow < numMyNodes_-1) {
Kokkos::atomic_increment(&counts_(localRow+1));
Kokkos::atomic_inc(&counts_(localRow+1));
++curNumLocalEntries;
}
// MPI process to the left sends us an entry
if ((myRank_ > 0) && (localRow == 0)) {
Kokkos::atomic_increment(&counts_(localRow));
Kokkos::atomic_inc(&counts_(localRow));
++curNumLocalEntries;
}
// MPI process to the right sends us an entry
if ((myRank_ < numProcs_-1) && (localRow == numMyNodes_-1)) {
Kokkos::atomic_increment(&counts_(localRow));
Kokkos::atomic_inc(&counts_(localRow));
++curNumLocalEntries;
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/sacado/test/performance/fenl_assembly/fenl_functors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ class NodeNodeGraph {
if ( result.success() ) {

// If row node is owned then increment count
if ( row_node < row_count.extent(0) ) { atomic_increment( & row_count( row_node ) ); }
if ( row_node < row_count.extent(0) ) { Kokkos::atomic_inc( & row_count( row_node ) ); }

// If column node is owned and not equal to row node then increment count
if ( col_node < row_count.extent(0) && col_node != row_node ) { atomic_increment( & row_count( col_node ) ); }
if ( col_node < row_count.extent(0) && col_node != row_node ) { Kokkos::atomic_inc( & row_count( col_node ) ); }
}
else if ( result.failed() ) {
++count ;
Expand All @@ -276,12 +276,12 @@ class NodeNodeGraph {
const unsigned col_node = key.second ;

if ( row_node < row_count.extent(0) ) {
const unsigned offset = graph.row_map( row_node ) + atomic_fetch_add( & row_count( row_node ) , atomic_incr_type(1) );
const unsigned offset = graph.row_map( row_node ) + Kokkos::atomic_fetch_add( & row_count( row_node ) , atomic_incr_type(1) );
graph.entries( offset ) = col_node ;
}

if ( col_node < row_count.extent(0) && col_node != row_node ) {
const unsigned offset = graph.row_map( col_node ) + atomic_fetch_add( & row_count( col_node ) , atomic_incr_type(1) );
const unsigned offset = graph.row_map( col_node ) + Kokkos::atomic_fetch_add( & row_count( col_node ) , atomic_incr_type(1) );
graph.entries( offset ) = row_node ;
}
}
Expand Down Expand Up @@ -650,12 +650,12 @@ class ElementComputation
for( unsigned i = 0 ; i < FunctionCount ; i++ ) {
const unsigned row = node_index[i] ;
if ( row < this->residual.extent(0) ) {
atomic_add( & this->residual( row ) , res[i] );
Kokkos::atomic_add( & this->residual( row ) , res[i] );

for( unsigned j = 0 ; j < FunctionCount ; j++ ) {
const unsigned entry = this->elem_graph( ielem , i , j );
if ( entry != ~0u ) {
atomic_add( & this->jacobian.coeff( entry ) , mat[i][j] );
Kokkos::atomic_add( & this->jacobian.coeff( entry ) , mat[i][j] );
}
}
}
Expand Down Expand Up @@ -835,12 +835,12 @@ class ElementComputation
for( unsigned i = 0 ; i < FunctionCount ; i++ ) {
const unsigned row = node_index[i] ;
if ( row < this->residual.extent(0) ) {
atomic_add( & this->residual( row ) , res[i].val() );
Kokkos::atomic_add( & this->residual( row ) , res[i].val() );

for( unsigned j = 0 ; j < FunctionCount ; j++ ) {
const unsigned entry = this->elem_graph( ielem , i , j );
if ( entry != ~0u ) {
atomic_add( & this->jacobian.coeff( entry ) ,
Kokkos::atomic_add( & this->jacobian.coeff( entry ) ,
res[i].fastAccessDx(j) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ class NodeNodeGraph {
if ( result.success() ) {

// If row node is owned then increment count
if ( row_node < row_count.extent(0) ) { atomic_increment( & row_count( row_node ) ); }
if ( row_node < row_count.extent(0) ) { atomic_inc( & row_count( row_node ) ); }

// If column node is owned and not equal to row node then increment count
if ( col_node < row_count.extent(0) && col_node != row_node ) { atomic_increment( & row_count( col_node ) ); }
if ( col_node < row_count.extent(0) && col_node != row_node ) { atomic_inc( & row_count( col_node ) ); }
}
else if ( result.failed() ) {
++count ;
Expand Down
3 changes: 1 addition & 2 deletions packages/shylu/shylu_node/basker/src/shylubasker_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ namespace BaskerNS
BASKER_INLINE
void atomic_barrier_fanout(volatile Int &value, const Int l_size)
{
Kokkos::atomic_increment(&(value));
while(value < l_size)
while(Kokkos::atomic_inc_fetch(&value) < l_size)
{
BASKER_NO_OP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ std::vector<double> get_centroid_average_from_device(stk::mesh::BulkData &bulk,
for(size_t dim = 0; dim < 3; dim++) {
Kokkos::atomic_add(&deviceAverageView(dim), ngpField(elem, dim));
}
Kokkos::atomic_increment(&deviceAverageView(3));
Kokkos::atomic_inc(&deviceAverageView(3));
});

Kokkos::deep_copy(hostAverageView, deviceAverageView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CountBuckets {
typedef typename hash_type::result_type hash_value_type;

const hash_value_type hashVal = hash_type::hashFunc (keys_[i], size_);
Kokkos::atomic_increment (&counts_[hashVal]);
Kokkos::atomic_inc (&counts_[hashVal]);
}

using value_type = Kokkos::pair<int, key_type>;
Expand All @@ -128,7 +128,7 @@ class CountBuckets {
dst.second = keyVal;
}
else {
Kokkos::atomic_increment (&counts_[hashVal]);
Kokkos::atomic_inc (&counts_[hashVal]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/trilinoscouplings/examples/fenl/fenl_functors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ class NodeNodeGraph {

if ( result.success() ) {
// First time this pair was inserted
if ( row_node < row_count.extent(0) ) { atomic_increment( & row_count( row_node ) ); }
if ( col_node < row_count.extent(0) && col_node != row_node ) { atomic_increment( & row_count( col_node ) ); }
if ( row_node < row_count.extent(0) ) { Kokkos::atomic_inc( & row_count( row_node ) ); }
if ( col_node < row_count.extent(0) && col_node != row_node ) { Kokkos::atomic_inc( & row_count( col_node ) ); }
}
else if ( result.failed() ) {
// Ran out of memory for insertion.
Expand All @@ -244,12 +244,12 @@ class NodeNodeGraph {
using atomic_incr_type = typename std::remove_reference< decltype( row_count(0) ) >::type;

if ( row_node < row_count.extent(0) ) {
const unsigned offset = graph.row_map( row_node ) + atomic_fetch_add( & row_count( row_node ) , atomic_incr_type(1) );
const unsigned offset = graph.row_map( row_node ) + Kokkos::atomic_fetch_add( & row_count( row_node ) , atomic_incr_type(1) );
graph.entries( offset ) = col_node ;
}

if ( col_node < row_count.extent(0) && col_node != row_node ) {
const unsigned offset = graph.row_map( col_node ) + atomic_fetch_add( & row_count( col_node ) , atomic_incr_type(1) );
const unsigned offset = graph.row_map( col_node ) + Kokkos::atomic_fetch_add( & row_count( col_node ) , atomic_incr_type(1) );
graph.entries( offset ) = row_node ;
}
}
Expand Down

0 comments on commit f78e1f5

Please sign in to comment.