mpi_nested_algebra.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp
  4. [begin_description]
  5. Nested parallelized algebra for MPI.
  6. [end_description]
  7. Copyright 2013 Karsten Ahnert
  8. Copyright 2013 Mario Mulansky
  9. Copyright 2013 Pascal Germroth
  10. Distributed under the Boost Software License, Version 1.0.
  11. (See accompanying file LICENSE_1_0.txt or
  12. copy at http://www.boost.org/LICENSE_1_0.txt)
  13. */
  14. #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_NESTED_ALGEBRA_HPP_INCLUDED
  15. #define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_NESTED_ALGEBRA_HPP_INCLUDED
  16. #include <boost/numeric/odeint/algebra/norm_result_type.hpp>
  17. #include <boost/numeric/odeint/util/n_ary_helper.hpp>
  18. namespace boost {
  19. namespace numeric {
  20. namespace odeint {
  21. /** \brief MPI-parallelized algebra, wrapping another algebra.
  22. */
  23. template< class InnerAlgebra >
  24. struct mpi_nested_algebra
  25. {
  26. // execute the InnerAlgebra on each node's local data.
  27. #define BOOST_ODEINT_GEN_BODY(n) \
  28. InnerAlgebra::for_each##n( \
  29. BOOST_PP_ENUM_BINARY_PARAMS(n, s, () BOOST_PP_INTERCEPT) , \
  30. op \
  31. );
  32. BOOST_ODEINT_GEN_FOR_EACH(BOOST_ODEINT_GEN_BODY)
  33. #undef BOOST_ODEINT_GEN_BODY
  34. template< class NestedState >
  35. static typename norm_result_type< typename NestedState::value_type >::type norm_inf( const NestedState &s )
  36. {
  37. typedef typename norm_result_type< typename NestedState::value_type >::type result_type;
  38. // local maximum
  39. result_type value = InnerAlgebra::norm_inf( s() );
  40. // global maximum
  41. return boost::mpi::all_reduce(s.world, value, boost::mpi::maximum<result_type>());
  42. }
  43. };
  44. }
  45. }
  46. }
  47. #endif