Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle-grid periodic communication #263

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ if(Cabana_ENABLE_MPI)
)
endif()

if(Cabana_ENABLE_CAJITA)
list(APPEND HEADERS_PUBLIC
Cabana_ParticleGridCommunication.hpp
)
endif()

set(HEADERS_IMPL
impl/Cabana_CartesianGrid.hpp
impl/Cabana_Index.hpp
Expand All @@ -54,6 +60,10 @@ if(Cabana_ENABLE_MPI)
target_link_libraries(cabanacore MPI::MPI_CXX)
endif()

if(Cabana_ENABLE_CAJITA)
target_link_libraries(cabanacore Cajita)
endif()

target_include_directories(cabanacore
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down
40 changes: 26 additions & 14 deletions core/src/Cabana_CommunicationPlan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Cabana
{
namespace Impl
{

//---------------------------------------------------------------------------//
// Count sends and create steering algorithm tags.
struct CountSendsAndCreateSteeringDuplicated
Expand Down Expand Up @@ -246,6 +247,29 @@ auto countSendsAndCreateSteering( const ExportRankView element_export_ranks,
return std::make_pair( neighbor_counts, neighbor_ids );
}

//---------------------------------------------------------------------------//
// Return unique neighbor ranks, with the current rank first.
std::vector<int> getUniqueTopology( std::vector<int> topology )
{
auto remove_end = std::remove( topology.begin(), topology.end(), -1 );
std::sort( topology.begin(), remove_end );
auto unique_end = std::unique( topology.begin(), remove_end );
topology.resize( std::distance( topology.begin(), unique_end ) );

// Put this rank first.
int my_rank = -1;
MPI_Comm_rank( MPI_COMM_WORLD, &my_rank );
for ( auto& n : topology )
{
if ( n == my_rank )
{
std::swap( n, topology[0] );
break;
}
}
return topology;
}

//---------------------------------------------------------------------------//

} // end namespace Impl
Expand Down Expand Up @@ -464,11 +488,8 @@ class CommunicationPlan
// Store the number of export elements.
_num_export_element = element_export_ranks.size();

// Store the unique neighbors.
_neighbors = neighbor_ranks;
std::sort( _neighbors.begin(), _neighbors.end() );
auto unique_end = std::unique( _neighbors.begin(), _neighbors.end() );
_neighbors.resize( std::distance( _neighbors.begin(), unique_end ) );
// Store the unique neighbors (this rank first).
_neighbors = Impl::getUniqueTopology( neighbor_ranks );
int num_n = _neighbors.size();

// Get the size of this communicator.
Expand All @@ -483,15 +504,6 @@ class CommunicationPlan
// communication space so any mpi tag will do.
const int mpi_tag = 1221;

// If we are sending to ourself put that one first in the neighbor
// list.
for ( auto& n : _neighbors )
if ( n == my_rank )
{
std::swap( n, _neighbors[0] );
break;
}

// Initialize import/export sizes.
_num_export.assign( num_n, 0 );
_num_import.assign( num_n, 0 );
Expand Down
4 changes: 4 additions & 0 deletions core/src/Cabana_Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <Cabana_Halo.hpp>
#endif

#ifdef Cabana_ENABLE_CAJITA
#include <Cabana_ParticleGridCommunication.hpp>
#endif

#ifdef Cabana_ENABLE_ARBORX
#include <Cabana_Experimental_NeighborList.hpp>
#endif
Expand Down
Loading