fml  0.1-0
Fused Matrix Library
mpi_utils.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_PAR_INTERNALS_MPI_UTILS_H
6 #define FML_PAR_INTERNALS_MPI_UTILS_H
7 #pragma once
8 
9 
10 #include "../comm.hh"
11 
12 
13 namespace fml
14 {
15  namespace mpi
16  {
17  static const int REDUCE_TO_ALL = -1;
18 
19 
20 
21  static inline void check_MPI_ret(int ret)
22  {
23  if (ret != MPI_SUCCESS)
24  {
25  int slen;
26  char s[MPI_MAX_ERROR_STRING];
27 
28  MPI_Error_string(ret, s, &slen);
29  throw std::runtime_error(s);
30  }
31  }
32 
33 
34 
35  static inline void contig_type(const int count, const float *x,
36  MPI_Datatype *newtype)
37  {
38  (void)x;
39  int ret;
40 
41  ret = MPI_Type_contiguous(count, MPI_FLOAT, newtype);
42  check_MPI_ret(ret);
43  ret = MPI_Type_commit(newtype);
44  check_MPI_ret(ret);
45  }
46 
47  static inline void contig_type(const int count, const double *x,
48  MPI_Datatype *newtype)
49  {
50  (void)x;
51  int ret;
52 
53  ret = MPI_Type_contiguous(count, MPI_DOUBLE, newtype);
54  check_MPI_ret(ret);
55  ret = MPI_Type_commit(newtype);
56  check_MPI_ret(ret);
57  }
58  }
59 }
60 
61 
62 #endif
fml
Core namespace.
Definition: dimops.hh:10