Skip to content

Commit 5e8dc03

Browse files
committed
Merge branch 'develop' of github.com:LLNL/Umpire into kab163/test-exp-RAP
2 parents 1d0ae8a + fc4dd26 commit 5e8dc03

File tree

10 files changed

+38
-8
lines changed

10 files changed

+38
-8
lines changed

examples/cookbook/recipe_shared_memory.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "umpire/Umpire.hpp"
1717
#include "umpire/config.hpp"
1818
#include "umpire/resource/HostSharedMemoryResource.hpp"
19+
#include "umpire/strategy/NamedAllocationStrategy.hpp"
1920
#include "umpire/util/MemoryResourceTraits.hpp"
2021

2122
//
@@ -58,6 +59,9 @@ int main(int ac, char** av)
5859
//
5960
auto node_allocator{rm.makeResource("SHARED::node_allocator", traits)};
6061

62+
auto named_node_allocator{
63+
rm.makeAllocator<umpire::strategy::NamedAllocationStrategy>("My Node Allocator", node_allocator)};
64+
6165
//
6266
// Resource of this allocator is SHARED
6367
//
@@ -82,6 +86,7 @@ int main(int ac, char** av)
8286
// Allocate shared memory
8387
//
8488
void* ptr{node_allocator.allocate("allocation_name_2", sizeof(uint64_t))};
89+
void* ptr2{named_node_allocator.allocate("allocation two", 1024)};
8590
uint64_t* data{static_cast<uint64_t*>(ptr)};
8691

8792
if (shared_rank == foreman_rank)
@@ -98,6 +103,7 @@ int main(int ac, char** av)
98103
UMPIRE_ASSERT(*data == 0xDEADBEEF);
99104

100105
node_allocator.deallocate(ptr);
106+
named_node_allocator.deallocate(ptr2);
101107

102108
if (use_mpi) {
103109
MPI_Finalize();

src/umpire/ResourceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ResourceManager::ResourceManager()
6464
{
6565
UMPIRE_LOG(Debug, "() entering");
6666

67-
const char* env_enable_log{getenv("UMPIRE_LOG_LEVEL")};
67+
const char* env_enable_log{std::getenv("UMPIRE_LOG_LEVEL")};
6868
const bool enable_log{env_enable_log != nullptr};
6969

7070
util::initialize_io(enable_log);

src/umpire/event/event.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define UMPIRE_event_HPP
99

1010
#include <cstdint>
11+
#include <cstdlib>
1112
#include <map>
1213
#include <sstream>
1314
#include <string>
@@ -57,9 +58,9 @@ namespace umpire {
5758
namespace event {
5859

5960
namespace {
60-
static const char* replay_env{getenv("UMPIRE_REPLAY")};
61+
static const char* replay_env{std::getenv("UMPIRE_REPLAY")};
6162
static const bool enable_replay{(replay_env != NULL)};
62-
static const char* event_env{getenv("UMPIRE_EVENTS")};
63+
static const char* event_env{std::getenv("UMPIRE_EVENTS")};
6364
static const bool enable_event{(event_env != NULL)};
6465
static const bool event_build_enabled{enable_replay || enable_event};
6566
} // namespace

src/umpire/strategy/NamedAllocationStrategy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ void* NamedAllocationStrategy::allocate(std::size_t bytes)
2222
return m_allocator->allocate_internal(bytes);
2323
}
2424

25+
void* NamedAllocationStrategy::allocate_named(const std::string& name, std::size_t bytes)
26+
{
27+
return m_allocator->allocate_named_internal(name, bytes);
28+
}
29+
2530
void NamedAllocationStrategy::deallocate(void* ptr, std::size_t size)
2631
{
2732
return m_allocator->deallocate_internal(ptr, size);

src/umpire/strategy/NamedAllocationStrategy.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class NamedAllocationStrategy : public AllocationStrategy {
1818
NamedAllocationStrategy(const std::string& name, int id, Allocator allocator);
1919

2020
void* allocate(std::size_t bytes) override;
21+
void* allocate_named(const std::string& name, std::size_t bytes) override;
2122
void deallocate(void* ptr, std::size_t size) override;
2223

2324
Platform getPlatform() noexcept override;

src/umpire/util/Logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Logger::Logger() noexcept
3333
m_is_enabled{false, false, false, false}
3434
{
3535
message::Level level{defaultLevel};
36-
const char* enval = getenv(env_name);
36+
const char* enval = std::getenv(env_name);
3737

3838
if (enval) {
3939
for (int i = 0; i < message::Num_Levels; ++i) {

src/umpire/util/Macros.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
plog = axom::slic::Logger::getActiveLogger(); \
3737
axom::slic::message::Level level; \
3838
level = axom::slic::message::Level::Error; \
39-
char* enval = getenv(env_name.c_str()); \
39+
char* enval = std::getenv(env_name.c_str()); \
4040
if (enval != NULL) { \
4141
for (int i = 0; i < axom::slic::message::Level::Num_Levels; ++i) { \
4242
if (strcasecmp(enval, axom::slic::message::MessageLevelName[i].c_str()) == 0) { \

src/umpire/util/backtrace.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool backtrace_enabled()
4141
static bool initialized{false};
4242

4343
if (!initialized) {
44-
const char* enval{getenv("UMPIRE_BACKTRACE")};
44+
const char* enval{std::getenv("UMPIRE_BACKTRACE")};
4545
if (enval) {
4646
std::string env_str{enval};
4747
std::transform(env_str.begin(), env_str.end(), env_str.begin(), ::toupper);

src/umpire/util/io.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
#include "umpire/util/io.hpp"
99

10-
#include <stdlib.h> // for getenv()
11-
10+
#include <cstdlib>
1211
#include <fstream>
1312
#include <iostream>
1413
#include <ostream>

tests/integration/strategy_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,4 +763,22 @@ TEST(NamingShimTests, TestAllocateDeallocate)
763763
shim.deallocate(ptr);
764764
}
765765
}
766+
767+
TEST(NamedAllocatorTest, ForwardName)
768+
{
769+
auto& rm = umpire::ResourceManager::getInstance();
770+
771+
auto traits{umpire::get_default_resource_traits("SHARED")};
772+
traits.size = 1 * 1024 * 1024;
773+
traits.scope = umpire::MemoryResourceTraits::shared_scope::node;
774+
775+
auto node_allocator{rm.makeResource("SHARED::allocator_for_named_test", traits)};
776+
777+
auto allocator{rm.makeAllocator<umpire::strategy::NamedAllocationStrategy>("shared named alloc", node_allocator)};
778+
{
779+
void* ptr = allocator.allocate("test", 1024);
780+
EXPECT_NE(ptr, nullptr);
781+
allocator.deallocate(ptr);
782+
}
783+
}
766784
#endif

0 commit comments

Comments
 (0)