Using multicores with OpenMP and Coroutine2
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 20/100
- Issue type
- Documentation
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- documentation, performance
Research direction
Start with the simplified program in main and its OpenMP parallel loop, then review the Boost.Coroutine2 and OpenMP interaction described in the issue. A useful result would document whether this combination is supported, explain the observed single-core behavior, and provide an example or clear guidance using the shown compilation setup.
Written by the indexing model from the issue text.
Description
Hello,
I am currently modeling multiple producers using Boost.Coroutine2 and storing them in a container (std::vector). My goal is to leverage OpenMP to accelerate the calls of these coroutines on multiple cores.
However, I am encountering an issue where only one core is running the program. I have been searching for documentation on the combination of OpenMP and Coroutine2 but have not found examples or advice.
Below is a simplified version of my code:
#include <iostream>
#include <boost/coroutine2/all.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#define N 10000000
using namespace boost::coroutines2;
using CoroutinePush = coroutine<void>::push_type;
using CoroutinePull = coroutine<void>::pull_type;
using Funptr = boost::function<void(CoroutinePush&)>;
class Env{
public:
long x=0;
};
void producer(CoroutinePush& yield, Env* env) {
yield(); // init
for (int i = 0; i < N; ++i) {
env->x++; // some work here
yield(); // Yield the produced value
}
}
int main() {
Env* env=new Env();
Funptr producerFunction = boost::bind(&producer, _1, env);
std::vector<CoroutinePull*> l;
for(int i=0;i<N;i++){
l.push_back(new CoroutinePull(producerFunction));
}
#pragma omp parallel for
for(int i=0;i<N;i++){
// #pragma omp critical // if it's uncommented x becomes predictable but 1 thread at a time
{
(*l[i])();
}
}
std::cout << "x:" << env->x << std::endl;
for(int i = 0; i < N; i++) {
delete l[i];
}
delete env;
return 0;
}
My compilation line: g++ -std=c++20 -fopenmp ./g.cpp -lboost_context -lboost_coroutine
I would greatly appreciate any guidance, examples, or advice on how to use Boost.Coroutine2 and OpenMP for multicore execution.
Thank you
- Dominant language
- C++
- Stars
- 140
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/coroutine2
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
boostorg/coroutine2#54 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
boostorg/coroutine2#53 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
boostorg/coroutine2#37 ·
All issues in boostorg/coroutine2
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·