]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/parallel/omp_loop_static.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / parallel / omp_loop_static.h
index cc3443ba1a91ceba8c6708adcb84a5aa4ef15c0b..83b93c450a4e2fbca9d7f77de1e1f7eab0ee6422 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007-2020 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the terms
 
 namespace __gnu_parallel
 {
-
   /** @brief Embarrassingly parallel algorithm for random access
    * iterators, using an OpenMP for loop with static scheduling.
    *
-   *  @param __begin Begin iterator of element __sequence.
-   *  @param __end End iterator of element __sequence.
+   *  @param __begin Begin iterator of element sequence.
+   *  @param __end End iterator of element sequence.
    *  @param __o User-supplied functor (comparator, predicate, adding
    *  functor, ...).
-   *  @param __f Functor to "process" an element with __op (depends on
+   *  @param __f Functor to @a process an element with __op (depends on
    *  desired functionality, e. g. for std::for_each(), ...).
-   *  @param __r Functor to "add" a single __result to the already processed
+   *  @param __r Functor to @a add a single __result to the already processed
    *  __elements (depends on functionality).
    *  @param __base Base value for reduction.
    *  @param __output Pointer to position where final result is written to
@@ -58,37 +57,38 @@ namespace __gnu_parallel
    *  std::count_n()).
    *  @return User-supplied functor (that may contain a part of the result).
    */
-template<typename _RAIter,
-         typename _Op,
-         typename _Fu,
-         typename _Red,
-         typename _Result>
-  _Op
-  for_each_template_random_access_omp_loop_static(
-    _RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r,
-    _Result __base, _Result& __output,
-    typename std::iterator_traits<_RAIter>::difference_type __bound)
-  {
-    typedef typename
-      std::iterator_traits<_RAIter>::difference_type
-      _DifferenceType;
-
-    _DifferenceType __length = __end - __begin;
-    _ThreadIndex __num_threads =
-      std::min<_DifferenceType>(__get_max_threads(), __length);
-
-    _Result *__thread_results;
-
-#   pragma omp parallel num_threads(__num_threads)
+  template<typename _RAIter,
+          typename _Op,
+          typename _Fu,
+          typename _Red,
+          typename _Result>
+    _Op
+    __for_each_template_random_access_omp_loop_static(_RAIter __begin,
+                                                     _RAIter __end, _Op __o,
+                                                     _Fu& __f, _Red __r,
+                                                     _Result __base,
+                                                     _Result& __output,
+      typename std::iterator_traits<_RAIter>::difference_type __bound)
+    {
+      typedef typename std::iterator_traits<_RAIter>::difference_type
+       _DifferenceType;
+
+      _DifferenceType __length = __end - __begin;
+      _ThreadIndex __num_threads = std::min<_DifferenceType>
+       (__get_max_threads(), __length);
+
+      _Result *__thread_results;
+
+#     pragma omp parallel num_threads(__num_threads)
       {
 #       pragma omp single
-          {
-            __num_threads = omp_get_num_threads();
-            __thread_results = new _Result[__num_threads];
+       {
+         __num_threads = omp_get_num_threads();
+         __thread_results = new _Result[__num_threads];
 
-            for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
-              __thread_results[__i] = _Result();
-          }
+         for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
+           __thread_results[__i] = _Result();
+       }
 
         _ThreadIndex __iam = omp_get_thread_num();
 
@@ -98,17 +98,17 @@ template<typename _RAIter,
                                         __f(__o, __begin+__pos));
       } //parallel
 
-    for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
-      __output = __r(__output, __thread_results[__i]);
+      for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
+       __output = __r(__output, __thread_results[__i]);
 
-    delete [] __thread_results;
+      delete [] __thread_results;
 
-    // Points to last element processed (needed as return value for
-    // some algorithms like transform).
-    __f.finish_iterator = __begin + __length;
+      // Points to last element processed (needed as return value for
+      // some algorithms like transform).
+      __f.finish_iterator = __begin + __length;
 
-    return __o;
-  }
+      return __o;
+    }
 
 } // end namespace