-
Notifications
You must be signed in to change notification settings - Fork 0
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
Introduced HPC into relevant parts #3
Conversation
WalkthroughThis pull request introduces OpenMP support to the Changes
Sequence DiagramsequenceDiagram
participant Search as BreadthFirstSearch
participant OpenMP as OpenMP Runtime
participant Frontier as Search Frontier
Search->>OpenMP: Parallel for loop triggered
OpenMP->>Frontier: Distribute node expansion tasks
Frontier-->>OpenMP: Concurrent child node generation
OpenMP-->>Search: Aggregated search results
Possibly related PRs
Poem
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/tests.cpp (1)
4-4
: Usestd::chrono
instead of OpenMP for timing measurementsIncluding
<omp.h>
and usingomp_get_wtime()
solely for timing adds unnecessary dependency on OpenMP in your tests. The C++ standard library offers<chrono>
for high-resolution timing without external dependencies.Suggested changes:
-#include <omp.h> +#include <chrono>And update the timing code in your tests:
-double start = omp_get_wtime(); +auto start = std::chrono::high_resolution_clock::now(); ... -double end = omp_get_wtime(); +auto end = std::chrono::high_resolution_clock::now(); ... -std::cout << "Time: " << end - start << std::endl; +std::chrono::duration<double> elapsed = end - start; +std::cout << "Time: " << elapsed.count() << " seconds" << std::endl;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CMakeLists.txt
(1 hunks)src/search.cpp
(2 hunks)tests/tests.cpp
(5 hunks)
🧰 Additional context used
🪛 GitHub Actions: C++ CI
tests/tests.cpp
[error] 36-39: Mismatched end line for _ZN22Definitions_State_Test8TestBodyEv function. LCOV coverage data generation failed.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (5)
src/search.cpp (1)
10-10
: Ensure OpenMP is supported in your build environmentThe inclusion of
#include <omp.h>
requires that your compiler and build environment support OpenMP. Make sure that the appropriate compiler flags (e.g.,-fopenmp
for GCC/Clang) are set in your build configuration.tests/tests.cpp (3)
22-22
: Verify the impact of increasing the goal value on test performanceChanging the goal value from
10
to10010
ingoal_test
significantly increases the search depth required to find a solution. This can lead to longer execution times and higher resource consumption during testing, especially for uninformed search algorithms like Breadth-First Search.Please confirm that this change is intentional and that the tests still complete within an acceptable time frame.
32-32
: Ensure heuristic remains admissible with updated goal valueUpdating the heuristic function to return
10010 - test_state->value
aligns it with the new goal value. However, it's important to verify that the heuristic remains admissible (never overestimates the true cost) and consistent to guarantee the optimality and efficiency of algorithms like A* Search.Please ensure that the heuristic accurately reflects the minimal cost to reach the goal from any given state.
44-49
: Investigate pipeline failure related to code coverageThe pipeline reports a failure in LCOV coverage data generation with a mismatched end line error. This issue might be related to the inclusion of OpenMP directives or the use of
omp_get_wtime()
in the tests.Consider the following steps to troubleshoot:
- Remove the dependency on OpenMP in tests by using
std::chrono
for timing, as suggested earlier.- Ensure that your code coverage tools are configured to handle any parallel code correctly.
- Verify that all source files are being compiled with the same settings used during coverage analysis.
Also applies to: 56-61, 70-70
CMakeLists.txt (1)
17-22
: OpenMP integration in CMake is correctly implementedThe addition of OpenMP support in your CMake configuration is properly done. The
find_package(OpenMP)
command searches for OpenMP, and conditional linking withtarget_link_libraries
ensures compatibility when OpenMP is available.
@@ -60,6 +61,7 @@ std::shared_ptr<Node> BreadthFirstSearch::search() { | |||
if (problem->goal_test(state)) { | |||
return node; | |||
} | |||
#pragma omp parallel for shared(frontier) schedule(dynamic) if (frontier.size() > 1000) |
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.
Potential data race on frontier
due to concurrent modifications
The use of #pragma omp parallel for
introduces parallelism when iterating over problem->actions(node->state)
. However, the frontier
queue is being modified concurrently by multiple threads with frontier.push(child);
. Since std::queue
is not thread-safe, this can lead to data races and undefined behavior.
To address this issue, consider collecting child nodes in a thread-local container and then merging them into frontier
after the parallel region. Here's a suggested fix:
while (!frontier.empty()) {
auto node = frontier.front();
frontier.pop();
State *state = node->state.get();
if (problem->goal_test(state)) {
return node;
}
+ std::vector<std::shared_ptr<Node>> local_children;
#pragma omp parallel for schedule(dynamic) if (frontier.size() > 1000)
for (size_t i = 0; i < problem->actions(node->state).size(); ++i) {
const auto &action = problem->actions(node->state)[i];
auto child = std::make_shared<Node>(
node,
action->effect,
action,
node->path_cost + action->cost,
problem->heuristic(action->effect.get())
);
- frontier.push(child);
+ #pragma omp critical
+ {
+ local_children.push_back(child);
+ }
}
+ for (const auto& child : local_children) {
+ frontier.push(child);
+ }
}
Alternatively, you might use locks or a thread-safe queue to manage concurrent access to frontier
, but be mindful of the potential performance implications.
Committable suggestion skipped: line range outside the PR's diff.
This pull request introduces OpenMP parallelism to the project, modifies the goal test and heuristic values in the test suite, and adds timing measurements to the search tests. The most important changes include adding OpenMP support, updating the goal test and heuristic values, and measuring execution time in tests.
Parallelism and Performance Improvements:
CMakeLists.txt
: Added OpenMP support by finding the OpenMP package and linking it to thesymphony
target if found.src/search.cpp
: Included the OpenMP header and added a parallel for loop with dynamic scheduling for the breadth-first search algorithm. [1] [2]Test Suite Modifications:
tests/tests.cpp
: Updated the goal test and heuristic values in theTestProblem
class to use 10010 instead of 10. [1] [2]tests/tests.cpp
: Added timing measurements usingomp_get_wtime()
to the A* search and breadth-first search tests to measure and print the execution time.These changes aim to enhance the performance of the search algorithms through parallelism and provide more accurate test results with updated values and performance metrics.
Summary by CodeRabbit
New Features
Performance Improvements
Test Updates