-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall | ||
// Project Developers. See the top-level COPYRIGHT file for details. | ||
// | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
|
||
/// \file concurrent.cpp | ||
/// \brief This example demonstrates Metall's concurrency support. | ||
/// Metall can be used in a multi-threaded environment. | ||
/// Please see the API documentation of the manager class to find out which | ||
/// functions are thread-safe. | ||
|
||
#include <iostream> | ||
#include <thread> | ||
|
||
#include <metall/metall.hpp> | ||
|
||
void metall_alloc(metall::manager& manager, const int tid) { | ||
for (int i = 0; i < 10; ++i) { | ||
if (tid % 2 == 0) { | ||
manager.deallocate(manager.allocate(10)); | ||
} else { | ||
manager.destroy_ptr(manager.construct<int>(metall::anonymous_instance)()); | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
{ | ||
metall::manager manager(metall::create_only, "/tmp/datastore"); | ||
|
||
{ | ||
std::thread t1(metall_alloc, std::ref(manager), 1); | ||
std::thread t2(metall_alloc, std::ref(manager), 2); | ||
std::thread t3(metall_alloc, std::ref(manager), 3); | ||
std::thread t4(metall_alloc, std::ref(manager), 4); | ||
|
||
t1.join(); | ||
t2.join(); | ||
t3.join(); | ||
t4.join(); | ||
} | ||
assert(manager.check_sanity()); | ||
assert(manager.all_memory_deallocated()); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
# This script builds and runs example programs with various sanitizers. | ||
# Usage example: | ||
# cd metall # Metall root directory | ||
# sh scripts/sanitizer/run_sanitizers.sh | ||
|
||
# Change the following variables to your own settings | ||
CC=clang | ||
CXX=clang++ | ||
BOOST_ROOT="${HOME}/local/boost" | ||
METALL_ROOT=".." | ||
|
||
LOG_FILE=out-sanitizer.log | ||
|
||
exec_cmd () { | ||
echo "" >> ${LOG_FILE} | ||
echo "------------------------------------------------------------" >> ${LOG_FILE} | ||
echo "Command: " "$@" | tee -a ${LOG_FILE} | ||
"$@" >> ${LOG_FILE} 2>&1 | ||
echo "------------------------------------------------------------" >> ${LOG_FILE} | ||
echo "" >> ${LOG_FILE} | ||
} | ||
|
||
build () { | ||
local target=$1 | ||
exec_cmd ${CXX} -I ${BOOST_ROOT} -I ${METALL_ROOT}/include -std=c++17 ${SANITIZER_BUILD_ARGS} ${target} -DMETALL_DEFAULT_CAPACITY=$((1024*1024*500)) | ||
} | ||
|
||
run_sanitizer () { | ||
SANITIZER_BUILD_ARGS=$1 | ||
|
||
# build "${METALL_ROOT}/example/simple.cpp" | ||
# ./a.out 2>&1 | tee -a ${LOG_FILE} | ||
# rm -f a.out | ||
|
||
build "${METALL_ROOT}/example/concurrent.cpp" | ||
echo "Running concurrent program" | ||
./a.out 2>&1 | tee -a ${LOG_FILE} | ||
rm -f a.out | ||
} | ||
|
||
main() { | ||
mkdir build | ||
cd build | ||
rm -rf ${LOG_FILE} | ||
|
||
echo "" | ||
echo "=====================================================================" | ||
echo "Build with address sanitizer and leak sanitizer" | ||
run_sanitizer "-fsanitize=address -fno-omit-frame-pointer -O1 -g" | ||
|
||
echo "" | ||
echo "=====================================================================" | ||
echo "Build with thread sanitizer" | ||
run_sanitizer "-fsanitize=thread -fPIE -pie -O1 -g" | ||
|
||
echo "" | ||
echo "=====================================================================" | ||
echo "Build with memory sanitizer" | ||
run_sanitizer "-fsanitize=memory -fsanitize-memory-track-origins -fPIE -pie -fno-omit-frame-pointer -g -O2" | ||
|
||
echo "" | ||
echo "=====================================================================" | ||
echo "Build with undefined behavior sanitizer" | ||
run_sanitizer "-fsanitize=undefined -O1 -g" | ||
} | ||
|
||
main "$@" |