LCOV - code coverage report
Current view: top level - include/parallel - threads_allocators.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 4 4 100.0 %
Date: 2025-08-19 19:27:09 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 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             :   template<typename U>
      80             :   scalable_allocator(const scalable_allocator<U> & a) :
      81             :     tbb::scalable_allocator<T>(a) {}
      82             : };
      83             : 
      84             : 
      85             : 
      86             : #else //LIBMESH_HAVE_TBB_API
      87             : 
      88             : 
      89             : 
      90             : //-------------------------------------------------------------------
      91             : /**
      92             :  * Just use std::allocator when the Threading Building Blocks is absent.
      93             :  */
      94             : template <typename T>
      95             : class scalable_allocator : public std::allocator<T>
      96             : {
      97             : public:
      98             :   typedef T * pointer;
      99             :   typedef const T * const_pointer;
     100             :   //     typedef T & reference;              // Intel 7.1 tries to instantiate an allocator<void>,
     101             :   //     typedef const T & const_reference;  // so we can't typedef a reference to void.
     102             :   typedef T value_type;
     103             :   typedef size_t size_type;
     104             :   typedef std::ptrdiff_t difference_type;
     105             : 
     106             :   template<typename U>
     107             :   struct rebind
     108             :   {
     109             :     typedef scalable_allocator<U> other;
     110             :   };
     111             : 
     112     1726846 :   scalable_allocator () :
     113     1726846 :     std::allocator<T>() {}
     114             : 
     115      118288 :   scalable_allocator (const scalable_allocator & a) :
     116      118288 :     std::allocator<T>(a) {}
     117             : 
     118             :   template<typename U>
     119             :   scalable_allocator(const scalable_allocator<U> & a) :
     120             :     std::allocator<T>(a) {}
     121             : };
     122             : 
     123             : 
     124             : #endif // #ifdef LIBMESH_HAVE_TBB_API
     125             : 
     126             : } // namespace Threads
     127             : 
     128             : } // namespace libMesh
     129             : 
     130             : #endif // LIBMESH_THREADS_ALLOCATORS_H

Generated by: LCOV version 1.14