5#include <thrust/host_vector.h>
6#include <thrust/device_vector.h>
62 error = MPI_Init_thread(argc, argv, MPI_THREAD_FUNNELED, &provided);
63 assert( error == MPI_SUCCESS &&
"Threaded MPI lib required!\n");
67#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA
69 MPI_Comm_rank( MPI_COMM_WORLD, &rank);
71 cudaGetDeviceCount(&num_devices);
74 std::cerr <<
"# No CUDA capable devices found on rank "<<rank<<std::endl;
75 MPI_Abort(MPI_COMM_WORLD, -1);
82 int device = rank % num_devices;
83 cudaSetDevice( device);
96std::vector<T>
mpi_read_as(
unsigned num, MPI_Comm comm, std::istream& is = std::cin)
99 MPI_Comm_rank( comm, &rank);
100 std::vector<T> nums(num);
103 for(
unsigned u=0; u<num; u++)
107 MPI_Bcast( &nums[0], num, getMPIDataType<T>(), 0, comm);
128inline void mpi_read_grid(
unsigned& n, std::vector<unsigned>& N, MPI_Comm comm,
129 std::istream& is = std::cin,
bool verbose =
true, std::ostream& os = std::cout)
132 MPI_Comm_rank( comm, &rank);
133 const std::string Ns[6] = {
"Nx",
"Ny",
"Nz",
"Nu",
"Nv",
"Nw"};
134 unsigned ndims = N.size();
136 if(rank == 0 and verbose)
138 os <<
"# Type n, "<<Ns[0];
139 for(
unsigned u=1; u<ndims; u++)
140 os <<
" and "<< Ns[u];
145 for(
unsigned u=0; u<ndims; u++)
147 if(rank == 0 and verbose)
149 os <<
"# On the grid "<<
n;
150 for(
unsigned u=0; u<ndims; u++)
161inline void mpi_read_grid(
unsigned& n, std::vector<unsigned*> N, MPI_Comm comm,
162 std::istream& is = std::cin,
bool verbose =
true, std::ostream& os = std::cout)
164 std::vector<unsigned> Ns( N.size());
166 for(
unsigned u=0; u<Ns.size(); u++)
203 std::vector<int> periods,
bool reorder =
false)
206 MPI_Comm_size( comm_old, &size);
207 assert( dims.size() == periods.size());
208 int ndims = dims.size();
209 int re = (int)reorder;
210 int err = MPI_Dims_create( size, ndims, &dims[0]);
211 if( err != MPI_SUCCESS)
213 "Cannot create Cartesian dimensions from given dimensions and size "<<size);
215 for(
int u=0; u<(int)ndims; u++)
220 "ERROR: Process partition needs to match total number of processes! "
221 <<size<<
" vs "<<reduce);
225 if( err != MPI_SUCCESS)
227 "Cannot create Cartesian comm from given communicator");
263 std::vector<dg::bc> bcs,
264 std::istream& is = std::cin,
265 MPI_Comm comm_old = MPI_COMM_WORLD,
266 bool reorder =
false,
268 std::ostream& os = std::cout)
271 MPI_Comm_rank( comm_old, &rank);
272 MPI_Comm_size( comm_old, &size);
273 if(rank==0 && verbose)os <<
"# MPI v"<<MPI_VERSION<<
"."<<MPI_SUBVERSION<<std::endl;
274 unsigned ndims = bcs.size();
276 std::vector<int> periods( ndims);
277 for(
unsigned u=0; u<ndims; u++)
288 const std::string nps[6] = {
"npx",
"npy",
"npz",
"npu",
"npv",
"npw"};
289 os <<
"# Type "<<nps[0];
290 for(
unsigned u=1; u<ndims; u++)
291 os <<
" and "<< nps[u];
302 num_threads = omp_get_max_threads( );
304 os <<
"# Computing with "<<np[0];
305 for(
unsigned u=1; u<ndims; u++)
307 os <<
" processes x " << num_threads<<
" threads = "
308 << size*num_threads<<
" total"<<std::endl;
311#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA
313 cudaGetDevice( &device);
314 if( rank==0 and verbose)
316 std::cout <<
"# MPI is "
317 <<(nccl_mpi ?
"using NCCL" : (cuda_aware_mpi ?
"cuda-aware" :
"NOT cuda-aware"))
320 if(verbose)std::cout <<
"# Rank "<<rank<<
" computes with device "<<device<<
" !"<<std::endl;
336std::cin,
bool verbose =
true)
350is = std::cin,
bool verbose =
true)
365std::istream& is = std::cin,
bool verbose =
true )
383std::istream& is = std::cin,
bool verbose =
true )
402unsigned& Ny, MPI_Comm& comm, std::istream& is = std::cin,
bool verbose =
true
423unsigned& Nx,
unsigned& Ny,
unsigned& Nz, MPI_Comm& comm, std::istream& is =
424std::cin,
bool verbose =
true )
class intended for the use in throw statements
Definition exceptions.h:83
small class holding a stringstream
Definition exceptions.h:29
#define _ping_
Definition exceptions.h:12
bc
Switch between boundary conditions.
Definition enums.h:15
@ PER
periodic boundaries
Definition enums.h:16
void mpi_init3d(dg::bc bcx, dg::bc bcy, dg::bc bcz, MPI_Comm &comm, std::istream &is=std::cin, bool verbose=true)
DEPRECATED: Short for.
Definition mpi_init.h:364
void mpi_init1d(dg::bc bcx, MPI_Comm &comm, std::istream &is=std::cin, bool verbose=true)
DEPRECATED: Short for.
Definition mpi_init.h:335
void mpi_init2d(dg::bc bcx, dg::bc bcy, MPI_Comm &comm, std::istream &is=std::cin, bool verbose=true)
DEPRECATED: Short for.
Definition mpi_init.h:349
void mpi_read_grid(unsigned &n, std::vector< unsigned > &N, MPI_Comm comm, std::istream &is=std::cin, bool verbose=true, std::ostream &os=std::cout)
Read in grid sizes from is.
Definition mpi_init.h:128
void mpi_init(int *argc, char **argv[])
Convencience shortcut: Calls MPI_Init or MPI_Init_thread and inits CUDA devices.
Definition mpi_init.h:55
MPI_Comm mpi_cart_create(MPI_Comm comm_old, std::vector< int > dims, std::vector< int > periods, bool reorder=false)
Convenience call to MPI_Cart_create preceded by MPI_Dims_create.
Definition mpi_init.h:202
std::vector< T > mpi_read_as(unsigned num, MPI_Comm comm, std::istream &is=std::cin)
Read num values from is and broadcast to all processes as type T.
Definition mpi_init.h:96
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...