LCOV - code coverage report
Current view: top level - include/parallel - threads_allocators.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4417 (f0ff5e) with base 9bbd75 Lines: 4 4 100.0 %
Date: 2026-11-16 16:30:47 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : #ifndef LIBMESH_THREADS_ALLOCATORS_H
      20             : #define LIBMESH_THREADS_ALLOCATORS_H
      21             : 
      22             : // Local includes
      23             : #include "libmesh/libmesh_config.h"
      24             : #include "libmesh/threads.h"
      25             : 
      26             : // Threading building blocks includes
      27             : #ifdef LIBMESH_HAVE_TBB_API
      28             : #  include "libmesh/ignore_warnings.h"
      29             : #  include "tbb/scalable_allocator.h"
      30             : #  include "libmesh/restore_warnings.h"
      31             : #endif
      32             : 
      33             : // C++ includes
      34             : #include <memory> // for std::allocator
      35             : #include <cstddef> // std::ptrdiff_t
      36             : 
      37             : namespace libMesh
      38             : {
      39             : 
      40             : 
      41             : /**
      42             :  * The Threads namespace is for wrapper functions
      43             :  * for common general multithreading algorithms and tasks.
      44             :  */
      45             : namespace Threads
      46             : {
      47             : #ifdef LIBMESH_HAVE_TBB_API
      48             : 
      49             : //-------------------------------------------------------------------
      50             : /**
      51             :  * Scalable allocator to be used in multithreaded code chunks which
      52             :  * allocate a lot of dynamic memory.  This allocator can be faster
      53             :  * than the std::allocator when there are multiple threads.
      54             :  */
      55             : template <typename T>
      56             : class scalable_allocator : public tbb::scalable_allocator<T>
      57             : {
      58             : public:
      59             :   typedef T * pointer;
      60             :   typedef const T * const_pointer;
      61             :   //     typedef T & reference;              // Intel 7.1 tries to instantiate an allocator<void>,
      62             :   //     typedef const T & const_reference;  // so we can't typedef a reference to void.
      63             :   typedef T value_type;
      64             :   typedef size_t size_type;
      65             :   typedef std::ptrdiff_t difference_type;
      66             : 
      67             :   template<typename U>
      68             :   struct rebind
      69             :   {
      70             :     typedef scalable_allocator<U> other;
      71             :   };
      72             : 
      73             :   scalable_allocator () :
      74             :     tbb::scalable_allocator<T>() {}
      75             : 
      76             :   scalable_allocator (const scalable_allocator & a) :
      77             :     tbb::scalable_allocator<T>(a) {}
      78             : 
      79             :   scalable_allocator & operator= (const scalable_allocator &) = default;
      80             : 
      81             :   template<typename U>
      82             :   scalable_allocator(const scalable_allocator<U> & a) :
      83             :     tbb::scalable_allocator<T>(a) {}
      84             : };
      85             : 
      86             : 
      87             : 
      88             : #else //LIBMESH_HAVE_TBB_API
      89             : 
      90             : 
      91             : 
      92             : //-------------------------------------------------------------------
      93             : /**
      94             :  * Just use std::allocator when the Threading Building Blocks is absent.
      95             :  */
      96             : template <typename T>
      97             : class scalable_allocator : public std::allocator<T>
      98             : {
      99             : public:
     100             :   typedef T * pointer;
     101             :   typedef const T * const_pointer;
     102             :   //     typedef T & reference;              // Intel 7.1 tries to instantiate an allocator<void>,
     103             :   //     typedef const T & const_reference;  // so we can't typedef a reference to void.
     104             :   typedef T value_type;
     105             :   typedef size_t size_type;
     106             :   typedef std::ptrdiff_t difference_type;
     107             : 
     108             :   template<typename U>
     109             :   struct rebind
     110             :   {
     111             :     typedef scalable_allocator<U> other;
     112             :   };
     113             : 
     114     1534036 :   scalable_allocator () :
     115     1534036 :     std::allocator<T>() {}
     116             : 
     117      135649 :   scalable_allocator (const scalable_allocator & a) :
     118      135649 :     std::allocator<T>(a) {}
     119             : 
     120             :   scalable_allocator & operator= (const scalable_allocator &) = default;
     121             : 
     122             :   template<typename U>
     123             :   scalable_allocator(const scalable_allocator<U> & a) :
     124             :     std::allocator<T>(a) {}
     125             : };
     126             : 
     127             : 
     128             : #endif // #ifdef LIBMESH_HAVE_TBB_API
     129             : 
     130             : } // namespace Threads
     131             : 
     132             : } // namespace libMesh
     133             : 
     134             : #endif // LIBMESH_THREADS_ALLOCATORS_H

Generated by: LCOV version 1.14