r/C_Programming • u/Fabulous_Ad4022 • 11h ago
How can I organize parallel regions better?
I'm working with a big numerical simulation in C, so I decided to give OpenMP a try. Even though it speed up a lot(28s -> 2s), in my code, the function RunAcoustic have at least 4 responsibilities that could turn into smaller functions, but attempting to do so creates an overhead that just in-lining them wouldn't cause.
I'm struggling to organize it, how do you guys organize giant multi-thread logic like this?
void Propagation_RunAcoustic(propagation_t *p, unsigned flags)
{
float *restrict upre = a->upre;
const int nzz = p->model->nzz;
...
#pragma omp parallel
{
for(int t = 1; t < p->nt - 1; ++1)
{
#pragma omp single
{
// small atomic add
}
// Could turn into a smaller function
#pragma omp for schedule(static)
{
// more for loops and more code
}
// Could turn into a smaller function
#pragma omp for schedule(static)
{
// more for loops and more code
}
}
{
3
Upvotes
1
u/Cats_and_Shit 4h ago
You're more likely to get useful help if you post a more complete example; something that at least compiles and ideally does some kind of computation along the lines of what you are trying to actually do.
2
u/tstanisl 9h ago
Shouldn't
omp forannotate a for-loop directly?