Automatic Differentiation
 
Loading...
Searching...
No Matches
map_rect_mpi.hpp
Go to the documentation of this file.
1#ifdef STAN_MPI
2
3#ifndef STAN_MATH_PRIM_FUNCTOR_MAP_RECT_MPI_HPP
4#define STAN_MATH_PRIM_FUNCTOR_MAP_RECT_MPI_HPP
5
12#include <vector>
13
14namespace stan {
15namespace math {
16namespace internal {
17
18template <int call_id, typename F, typename T_shared_param,
19 typename T_job_param>
20Eigen::Matrix<return_type_t<T_shared_param, T_job_param>, Eigen::Dynamic, 1>
21map_rect_mpi(const T_shared_param& shared_params,
22 const std::vector<Eigen::Matrix<T_job_param, Eigen::Dynamic, 1>>&
23 job_params,
24 const std::vector<std::vector<double>>& x_r,
25 const std::vector<std::vector<int>>& x_i,
26 std::ostream* msgs = nullptr) {
28 T_job_param>;
30
31 // whenever the cluster is already busy with some command we fall
32 // back to serial execution (possible if map_rect calls are nested
33 // or MPI facility used already in use)
34 try {
36 shared_params, job_params, x_r, x_i);
37
38 return job_chunk.reduce_combine();
39 } catch (const mpi_is_in_use& e) {
40 return map_rect_concurrent<call_id, F>(shared_params, job_params, x_r, x_i,
41 msgs);
42 }
43}
44} // namespace internal
45} // namespace math
46} // namespace stan
47
48#define STAN_REGISTER_MPI_MAP_RECT(CALLID, FUNCTOR, SHARED, JOB) \
49 namespace stan { \
50 namespace math { \
51 namespace internal { \
52 typedef FUNCTOR mpi_mr_##CALLID##_##SHARED##_##JOB##_; \
53 typedef map_rect_reduce<mpi_mr_##CALLID##_##SHARED##_##JOB##_, SHARED, JOB> \
54 mpi_mr_##CALLID##_##SHARED##_##JOB##_red_; \
55 typedef map_rect_combine<mpi_mr_##CALLID##_##SHARED##_##JOB##_, \
56 Eigen::Matrix<SHARED, Eigen::Dynamic, 1>, JOB> \
57 mpi_mr_##CALLID##_##SHARED##_##JOB##_comb_; \
58 typedef mpi_parallel_call<CALLID, mpi_mr_##CALLID##_##SHARED##_##JOB##_red_, \
59 mpi_mr_##CALLID##_##SHARED##_##JOB##_comb_> \
60 mpi_mr_##CALLID##_##SHARED##_##JOB##_pcall_; \
61 } \
62 } \
63 } \
64 STAN_REGISTER_MPI_DISTRIBUTED_APPLY( \
65 stan::math::internal::mpi_mr_##CALLID##_##SHARED##_##JOB##_pcall_)
66
67#define STAN_REGISTER_MPI_MAP_RECT_ALL(CALLID, FUNCTOR) \
68 STAN_REGISTER_MPI_MAP_RECT(CALLID, FUNCTOR, double, double)
69
70// redefine register macro to use MPI variant
71#undef STAN_REGISTER_MAP_RECT
72#define STAN_REGISTER_MAP_RECT(CALLID, FUNCTOR) \
73 STAN_REGISTER_MPI_MAP_RECT_ALL(CALLID, FUNCTOR)
74
75#endif
76
77#endif
Exception thrown whenever the MPI resource is busy.
result_t reduce_combine()
Once all data is distributed and cached the reduce_combine evaluates all assigned function evaluation...
The MPI parallel call class manages the distributed evaluation of a collection of tasks following the...
Eigen::Matrix< return_type_t< T_shared_param, T_job_param >, Eigen::Dynamic, 1 > map_rect_mpi(const T_shared_param &shared_params, const std::vector< Eigen::Matrix< T_job_param, Eigen::Dynamic, 1 > > &job_params, const std::vector< std::vector< double > > &x_r, const std::vector< std::vector< int > > &x_i, std::ostream *msgs=nullptr)
static constexpr double e()
Return the base of the natural logarithm.
Definition constants.hpp:20
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9