XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
send_recv_toroidal.hpp
Go to the documentation of this file.
1 #ifndef SEND_RECV_TOROIDAL_HPP
2 #define SEND_RECV_TOROIDAL_HPP
3 
5 #ifdef USE_MPI
6 // General template declaration, with an undefined implementation to cause a compile-time error if not specialized correctly
7 template<typename T>
8 struct MPIDataType;
9 
10 // Template specialization for double
11 template<>
12 struct MPIDataType<double> {
13  static MPI_Datatype value() { return MPI_DOUBLE; }
14 };
15 
16 // Template specialization for int
17 template<>
18 struct MPIDataType<int> {
19  static MPI_Datatype value() { return MPI_INT; }
20 };
21 
22 template<typename T>
23 void send_to_neighbor_plane(const MyMPI& mpi, const T& source_view, const T& dest_view, bool send_right){
24  int n_ranks = mpi.n_intpl_ranks;
25  int this_rank = mpi.my_intpl_rank;
26  int source_dist = send_right ? -1 : 1; // If sending to the right, the source is the intpl rank one less
27  int source_rank = positive_modulo(this_rank-source_dist, n_ranks);
28  int dest_rank = positive_modulo(this_rank+source_dist, n_ranks);
29  int isendtag = this_rank;
30  int irecvtag = source_rank;
31  MPI_Datatype datatype = MPIDataType<typename T::value_type>::value();
32  MPI_Sendrecv(source_view.data(), source_view.size(), datatype,dest_rank, isendtag,
33  dest_view.data(), dest_view.size(), datatype,source_rank,irecvtag,
34  mpi.intpl_comm,MPI_STATUS_IGNORE);
35 }
36 
37 template<typename T>
38 void send_right(const MyMPI& mpi, const T& source_view, const T& dest_view){
39  send_to_neighbor_plane(mpi, source_view, dest_view, true);
40 }
41 
42 template<typename T>
43 void send_left(const MyMPI& mpi, const T& source_view, const T& dest_view){
44  send_to_neighbor_plane(mpi, source_view, dest_view, false);
45 }
46 
47 #endif
48 
49 #endif
int my_intpl_rank
Definition: my_mpi.hpp:49
KOKKOS_INLINE_FUNCTION unsigned positive_modulo(int value, unsigned m)
Definition: globals.hpp:211
Definition: my_mpi.hpp:19
MPI_Comm intpl_comm
Definition: my_mpi.hpp:48
int n_intpl_ranks
Definition: my_mpi.hpp:50