Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:51

0001 /*
0002  [auto_generated]
0003  boost/numeric/odeint/external/openmp/openmp_range_algebra.hpp
0004 
0005  [begin_description]
0006  Range algebra for OpenMP.
0007  [end_description]
0008 
0009  Copyright 2013 Karsten Ahnert
0010  Copyright 2013 Mario Mulansky
0011  Copyright 2013 Pascal Germroth
0012 
0013  Distributed under the Boost Software License, Version 1.0.
0014  (See accompanying file LICENSE_1_0.txt or
0015  copy at http://www.boost.org/LICENSE_1_0.txt)
0016  */
0017 
0018 
0019 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_RANGE_ALGEBRA_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_RANGE_ALGEBRA_HPP_INCLUDED
0021 
0022 #include <boost/assert.hpp>
0023 #include <boost/range.hpp>
0024 #include <boost/numeric/odeint/algebra/norm_result_type.hpp>
0025 #include <boost/numeric/odeint/util/n_ary_helper.hpp>
0026 
0027 namespace boost {
0028 namespace numeric {
0029 namespace odeint {
0030 
0031 /** \brief OpenMP-parallelized range algebra.
0032  *
0033  * State must be a model of Random Access Range.
0034  */
0035 struct openmp_range_algebra
0036 {
0037 
0038 #if __cplusplus >= 201103L // C++11 supports _Pragma
0039 
0040 #define BOOST_ODEINT_GEN_LOCAL(z, n, unused) \
0041     BOOST_ASSERT_MSG( len == boost::size(s ## n), "All state ranges must have the same size." ); \
0042     typename boost::range_iterator<S ## n>::type beg ## n = boost::begin(s ## n);
0043 #define BOOST_ODEINT_GEN_BODY(n) \
0044     const size_t len = boost::size(s0); \
0045     BOOST_PP_REPEAT(n, BOOST_ODEINT_GEN_LOCAL, ~) \
0046     _Pragma("omp parallel for schedule(runtime)") \
0047     for( size_t i = 0 ; i < len ; i++ ) \
0048         op( BOOST_PP_ENUM_BINARY_PARAMS(n, beg, [i] BOOST_PP_INTERCEPT) );
0049 BOOST_ODEINT_GEN_FOR_EACH(BOOST_ODEINT_GEN_BODY)
0050 #undef BOOST_ODEINT_GEN_BODY
0051 #undef BOOST_ODEINT_GEN_LOCAL
0052 
0053 #else
0054 
0055     template< class S0 , class Op > static void for_each1 ( S0 &s0 , Op op ) {
0056         const size_t len = boost::size(s0);
0057         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0058         #pragma omp parallel for schedule(runtime)
0059         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] );
0060     }
0061     template< class S0 , class S1 , class Op > static void for_each2 ( S0 &s0 , S1 &s1 , Op op ) {
0062         const size_t len = boost::size(s0);
0063         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0064         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0065         #pragma omp parallel for schedule(runtime)
0066         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] );
0067     }
0068     template< class S0 , class S1 , class S2 , class Op > static void for_each3 ( S0 &s0 , S1 &s1 , S2 &s2 , Op op ) {
0069         const size_t len = boost::size(s0);
0070         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0071         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0072         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0073         #pragma omp parallel for schedule(runtime)
0074         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] );
0075     }
0076     template< class S0 , class S1 , class S2 , class S3 , class Op > static void for_each4 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , Op op ) {
0077         const size_t len = boost::size(s0);
0078         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0079         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0080         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0081         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0082         #pragma omp parallel for schedule(runtime)
0083         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] );
0084     }
0085     template< class S0 , class S1 , class S2 , class S3 , class S4 , class Op > static void for_each5 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , Op op ) {
0086         const size_t len = boost::size(s0);
0087         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0088         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0089         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0090         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0091         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0092         #pragma omp parallel for schedule(runtime)
0093         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] );
0094     }
0095     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class Op > static void for_each6 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , Op op ) {
0096         const size_t len = boost::size(s0);
0097         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0098         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0099         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0100         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0101         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0102         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0103         #pragma omp parallel for schedule(runtime)
0104         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] );
0105     }
0106     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class Op > static void for_each7 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , Op op ) {
0107         const size_t len = boost::size(s0);
0108         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0109         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0110         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0111         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0112         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0113         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0114         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0115         #pragma omp parallel for schedule(runtime)
0116         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] );
0117     }
0118     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class Op > static void for_each8 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , Op op ) {
0119         const size_t len = boost::size(s0);
0120         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0121         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0122         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0123         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0124         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0125         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0126         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0127         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0128         #pragma omp parallel for schedule(runtime)
0129         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] );
0130     }
0131     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class Op > static void for_each9 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , Op op ) {
0132         const size_t len = boost::size(s0);
0133         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0134         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0135         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0136         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0137         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0138         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0139         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0140         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0141         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0142         #pragma omp parallel for schedule(runtime)
0143         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] );
0144     }
0145     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class Op > static void for_each10 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , Op op ) {
0146         const size_t len = boost::size(s0);
0147         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0148         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0149         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0150         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0151         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0152         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0153         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0154         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0155         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0156         typename boost::range_iterator<S9>::type beg9 = boost::begin(s9);
0157         #pragma omp parallel for schedule(runtime)
0158         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] , beg9 [i] );
0159     }
0160     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class Op > static void for_each11 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , Op op ) {
0161         const size_t len = boost::size(s0);
0162         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0163         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0164         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0165         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0166         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0167         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0168         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0169         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0170         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0171         typename boost::range_iterator<S9>::type beg9 = boost::begin(s9);
0172         typename boost::range_iterator<S10>::type beg10 = boost::begin(s10);
0173         #pragma omp parallel for schedule(runtime)
0174         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] , beg9 [i] , beg10 [i] );
0175     }
0176     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class Op > static void for_each12 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , Op op ) {
0177         const size_t len = boost::size(s0);
0178         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0179         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0180         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0181         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0182         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0183         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0184         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0185         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0186         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0187         typename boost::range_iterator<S9>::type beg9 = boost::begin(s9);
0188         typename boost::range_iterator<S10>::type beg10 = boost::begin(s10);
0189         typename boost::range_iterator<S11>::type beg11 = boost::begin(s11);
0190         #pragma omp parallel for schedule(runtime)
0191         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] , beg9 [i] , beg10 [i] , beg11 [i] );
0192     }
0193     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class Op > static void for_each13 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , Op op ) {
0194         const size_t len = boost::size(s0);
0195         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0196         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0197         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0198         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0199         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0200         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0201         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0202         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0203         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0204         typename boost::range_iterator<S9>::type beg9 = boost::begin(s9);
0205         typename boost::range_iterator<S10>::type beg10 = boost::begin(s10);
0206         typename boost::range_iterator<S11>::type beg11 = boost::begin(s11);
0207         typename boost::range_iterator<S12>::type beg12 = boost::begin(s12);
0208         #pragma omp parallel for schedule(runtime)
0209         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] , beg9 [i] , beg10 [i] , beg11 [i] , beg12 [i] );
0210     }
0211     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class Op > static void for_each14 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , Op op ) {
0212         const size_t len = boost::size(s0);
0213         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0214         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0215         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0216         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0217         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0218         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0219         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0220         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0221         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0222         typename boost::range_iterator<S9>::type beg9 = boost::begin(s9);
0223         typename boost::range_iterator<S10>::type beg10 = boost::begin(s10);
0224         typename boost::range_iterator<S11>::type beg11 = boost::begin(s11);
0225         typename boost::range_iterator<S12>::type beg12 = boost::begin(s12);
0226         typename boost::range_iterator<S13>::type beg13 = boost::begin(s13);
0227         #pragma omp parallel for schedule(runtime)
0228         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] , beg9 [i] , beg10 [i] , beg11 [i] , beg12 [i] , beg13 [i] );
0229     }
0230     template< class S0 , class S1 , class S2 , class S3 , class S4 , class S5 , class S6 , class S7 , class S8 , class S9 , class S10 , class S11 , class S12 , class S13 , class S14 , class Op > static void for_each15 ( S0 &s0 , S1 &s1 , S2 &s2 , S3 &s3 , S4 &s4 , S5 &s5 , S6 &s6 , S7 &s7 , S8 &s8 , S9 &s9 , S10 &s10 , S11 &s11 , S12 &s12 , S13 &s13 , S14 &s14 , Op op ) {
0231         const size_t len = boost::size(s0);
0232         typename boost::range_iterator<S0>::type beg0 = boost::begin(s0);
0233         typename boost::range_iterator<S1>::type beg1 = boost::begin(s1);
0234         typename boost::range_iterator<S2>::type beg2 = boost::begin(s2);
0235         typename boost::range_iterator<S3>::type beg3 = boost::begin(s3);
0236         typename boost::range_iterator<S4>::type beg4 = boost::begin(s4);
0237         typename boost::range_iterator<S5>::type beg5 = boost::begin(s5);
0238         typename boost::range_iterator<S6>::type beg6 = boost::begin(s6);
0239         typename boost::range_iterator<S7>::type beg7 = boost::begin(s7);
0240         typename boost::range_iterator<S8>::type beg8 = boost::begin(s8);
0241         typename boost::range_iterator<S9>::type beg9 = boost::begin(s9);
0242         typename boost::range_iterator<S10>::type beg10 = boost::begin(s10);
0243         typename boost::range_iterator<S11>::type beg11 = boost::begin(s11);
0244         typename boost::range_iterator<S12>::type beg12 = boost::begin(s12);
0245         typename boost::range_iterator<S13>::type beg13 = boost::begin(s13);
0246         typename boost::range_iterator<S14>::type beg14 = boost::begin(s14);
0247         #pragma omp parallel for schedule(runtime)
0248         for( size_t i = 0 ; i < len ; i++ ) op( beg0 [i] , beg1 [i] , beg2 [i] , beg3 [i] , beg4 [i] , beg5 [i] , beg6 [i] , beg7 [i] , beg8 [i] , beg9 [i] , beg10 [i] , beg11 [i] , beg12 [i] , beg13 [i] , beg14 [i] );
0249     }
0250 
0251 #endif
0252 
0253 
0254     template< class S >
0255     static typename norm_result_type< S >::type norm_inf( const S &s )
0256     {
0257         using std::max;
0258         using std::abs;
0259         typedef typename norm_result_type< S >::type result_type;
0260         result_type init = static_cast< result_type >( 0 );
0261         const size_t len = boost::size(s);
0262         typename boost::range_iterator<const S>::type beg = boost::begin(s);
0263 #       pragma omp parallel for reduction(max: init) schedule(dynamic)
0264         for( size_t i = 0 ; i < len ; ++i )
0265             init = max( init , abs( beg[i] ) );
0266         return init;
0267     }
0268 
0269 };
0270 
0271 
0272 }
0273 }
0274 }
0275 
0276 #endif