1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) 4 // Copyright 2008-2016 National ICT Australia (NICTA) 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // ------------------------------------------------------------------------ 17 18 19 //! \addtogroup mp_misc 20 //! @{ 21 22 23 24 25 template<typename eT, const bool use_smaller_thresh = false> 26 struct mp_gate 27 { 28 arma_inline 29 static 30 bool evalmp_gate31 eval(const uword n_elem) 32 { 33 #if defined(ARMA_USE_OPENMP) 34 { 35 const bool length_ok = (is_cx<eT>::yes || use_smaller_thresh) ? (n_elem >= (arma_config::mp_threshold/uword(2))) : (n_elem >= arma_config::mp_threshold); 36 37 if(length_ok) 38 { 39 if(omp_in_parallel()) { return false; } 40 } 41 42 return length_ok; 43 } 44 #else 45 { 46 arma_ignore(n_elem); 47 48 return false; 49 } 50 #endif 51 } 52 }; 53 54 55 56 struct mp_thread_limit 57 { 58 arma_inline 59 static 60 int getmp_thread_limit61 get() 62 { 63 #if defined(ARMA_USE_OPENMP) 64 int n_threads = (std::min)(int(arma_config::mp_threads), int((std::max)(int(1), int(omp_get_max_threads())))); 65 #else 66 int n_threads = int(1); 67 #endif 68 69 return n_threads; 70 } 71 72 arma_inline 73 static 74 bool in_parallelmp_thread_limit75 in_parallel() 76 { 77 #if defined(ARMA_USE_OPENMP) 78 { 79 return bool(omp_in_parallel()); 80 } 81 #else 82 { 83 return false; 84 } 85 #endif 86 } 87 }; 88 89 90 91 //! @} 92