-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: numa_partitioner for parallel_for. #1461
Open
JhaShweta1
wants to merge
15
commits into
master
Choose a base branch
from
dev/shwetajh/numa
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
aa684b6
split
JhaShweta1 59253c9
added first touch
JhaShweta1 3d1174a
refractored
JhaShweta1 2209ab3
refractored
JhaShweta1 238c892
1D first touch
JhaShweta1 6edea84
added scan
JhaShweta1 0a01596
added scan
JhaShweta1 6c68575
added scan
JhaShweta1 0407953
Parallel_reduce - first touch
JhaShweta1 1e1d7a1
First touch - potential issue
JhaShweta1 200675b
reverted back first touch from the ranges
JhaShweta1 52fd000
reverted back first touch from the ranges
JhaShweta1 5ebaf7e
removed reduce & scan, added tests for for
JhaShweta1 2172632
removed tests
JhaShweta1 a8de090
arena-single invoke, execute in partitioner, more tests
JhaShweta1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -462,3 +462,136 @@ TEST_CASE("parallel_for constraints") { | |
#if _MSC_VER | ||
#pragma warning (pop) | ||
#endif | ||
|
||
// Define a simple functor to use with parallel_for | ||
struct SimpleFunctor { | ||
void operator()(const tbb::blocked_range<size_t>& r) const { | ||
for (size_t i = r.begin(); i != r.end(); ++i) { | ||
// For simplicity, we'll just ensure each element is visited | ||
} | ||
} | ||
}; | ||
|
||
void TestNumaPartitionerSimple() { | ||
const size_t N = 1000; | ||
std::vector<int> vec(N, 1); | ||
|
||
tbb::blocked_range<size_t> range(0, N); | ||
SimpleFunctor functor; | ||
tbb::affinity_partitioner ap; | ||
tbb::numa_partitioner<tbb::affinity_partitioner> n_partitioner(ap); | ||
|
||
// Test parallel_for with numa_partitioner | ||
parallel_for(range, functor, n_partitioner); | ||
|
||
// Verify results (for now, just check if the function runs without errors) | ||
CHECK(true); | ||
} | ||
|
||
void TestNumaPartitionerWithBody() { | ||
const size_t N = 1000; | ||
std::vector<int> vec(N, 0); | ||
|
||
tbb::blocked_range<size_t> range(0, N); | ||
|
||
auto body = [&](const tbb::blocked_range<size_t>& r) { | ||
for (size_t i = r.begin(); i != r.end(); ++i) { | ||
vec[i] = 1; // Set each element to 1 | ||
} | ||
}; | ||
|
||
tbb::affinity_partitioner ap; | ||
tbb::numa_partitioner<tbb::affinity_partitioner> n_partitioner(ap); | ||
|
||
// Test parallel_for with numa_partitioner and a lambda body | ||
parallel_for(range, body, n_partitioner); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need a test with more than one parallel_for invocation. I think that would uncover some of the design issues. |
||
|
||
// Verify results | ||
for (size_t i = 0; i < N; ++i) { | ||
CHECK(vec[i] == 1); | ||
} | ||
} | ||
|
||
void TestNumaPartitionerEmptyRange() { | ||
const size_t N = 0; | ||
std::vector<int> vec(N, 1); | ||
|
||
tbb::blocked_range<size_t> range(0, N); | ||
SimpleFunctor functor; | ||
tbb::affinity_partitioner ap; | ||
tbb::numa_partitioner<tbb::affinity_partitioner> n_partitioner(ap); | ||
|
||
// Test parallel_for with an empty range | ||
parallel_for(range, functor, n_partitioner); | ||
|
||
// Verify that the function runs without errors and vec remains unchanged | ||
CHECK(true); | ||
} | ||
|
||
//! Testing parallel_for with numa_partitioner | ||
//! \brief \ref requirement | ||
TEST_CASE("NUMA partitioner tests") { | ||
TestNumaPartitionerSimple(); | ||
TestNumaPartitionerWithBody(); | ||
TestNumaPartitionerEmptyRange(); | ||
} | ||
|
||
void TestNumaPartitionerNonDivisibleRange() { | ||
const size_t N = 1003; // A number that's less likely to be divisible by standard partition sizes | ||
std::vector<int> vec(N, 0); | ||
|
||
tbb::blocked_range<size_t> range(0, N); | ||
|
||
auto body = [&](const tbb::blocked_range<size_t>& r) { | ||
for (size_t i = r.begin(); i != r.end(); ++i) { | ||
vec[i] = 1; | ||
} | ||
}; | ||
|
||
tbb::affinity_partitioner ap; | ||
tbb::numa_partitioner<tbb::affinity_partitioner> n_partitioner(ap); | ||
|
||
// Test parallel_for with a non-divisible range | ||
parallel_for(range, body, n_partitioner); | ||
|
||
// Verify results | ||
for (size_t i = 0; i < N; ++i) { | ||
CHECK(vec[i] == 1); | ||
} | ||
} | ||
|
||
void TestNumaPartitionerExceptionHandling() { | ||
const size_t N = 1000; | ||
std::vector<int> vec(N, 0); | ||
|
||
tbb::blocked_range<size_t> range(0, N); | ||
|
||
auto body = [&](const tbb::blocked_range<size_t>& r) { | ||
for (size_t i = r.begin(); i != r.end(); ++i) { | ||
if (i == N / 2) throw std::runtime_error("Test exception"); | ||
vec[i] = 1; | ||
} | ||
}; | ||
|
||
tbb::affinity_partitioner ap; | ||
tbb::numa_partitioner<tbb::affinity_partitioner> n_partitioner(ap); | ||
|
||
// Test parallel_for with exception handling | ||
bool exceptionCaught = false; | ||
try { | ||
parallel_for(range, body, n_partitioner); | ||
} catch (const std::runtime_error& e) { | ||
exceptionCaught = true; | ||
} | ||
|
||
// Verify that the exception was caught | ||
CHECK(exceptionCaught == true); | ||
} | ||
|
||
// Add this to test suite | ||
TEST_CASE("NUMA partitioner tests- exceptions") { | ||
TestNumaPartitionerNonDivisibleRange(); | ||
TestNumaPartitionerExceptionHandling(); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the same instance is used across multiple parallel_fors, won't the arenas vector keep growing? I think initialize would be repeatedly invoked.