boostorg / boostorg/coroutine2

Using multicores with OpenMP and Coroutine2

Open
#49 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
140
Forks
44
PR merge metrics
No merged PRs in 30d

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
#include
#include
#include
#define N 10000000

using namespace boost::coroutines2;
using CoroutinePush = coroutine::push_type;
using CoroutinePull = coroutine::pull_type;
using Funptr = boost::function;

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 l;
for(int i=0;ix << 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.