Disable Introspection

If you know that you won’t be using any of Umpire’s introspection capabalities for allocations that come from a particular umpire::Allocator, you can turn off the introspection and avoid the overhead of tracking the associated metadata.

Warning

Disabling introspection means that allocations from this Allocator cannot be used for operations, or size and location queries.

In this recipe, we look at disabling introspection for a pool. To turn off introspection, you pass a boolean as the second template parameter to the umpire::ResourceManager::makeAllocator() method:

      rm.makeAllocator<umpire::strategy::DynamicPool, false>(
          "NO_INTROSPECTION_POOL", allocator);

Remember that disabling introspection will stop tracking the size of allocations made from the pool, so the umpire::Allocator::getCurrentSize() method will return 0:

            << " bytes are used" << std::endl;

The complete example is included below:

//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016-20, Lawrence Livermore National Security, LLC and Umpire
// project contributors. See the COPYRIGHT file for details.
//
// SPDX-License-Identifier: (MIT)
//////////////////////////////////////////////////////////////////////////////
#include <iostream>

#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "umpire/strategy/DynamicPool.hpp"
#include "umpire/util/Macros.hpp"

int main(int, char**)
{
  auto& rm = umpire::ResourceManager::getInstance();

  auto allocator = rm.getAllocator("HOST");

  /*
   * Create a pool with introspection disabled (can improve performance)
   */
  auto pooled_allocator =
      rm.makeAllocator<umpire::strategy::DynamicPool, false>(
          "NO_INTROSPECTION_POOL", allocator);

  void* data = pooled_allocator.allocate(1024);

  std::cout << "Pool has allocated " << pooled_allocator.getActualSize()
            << " bytes of memory. " << pooled_allocator.getCurrentSize()
            << " bytes are used" << std::endl;

  pooled_allocator.deallocate(data);

  return 0;
}