Skip to content
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

yarpgen support pragma omp simd #202

Open
huangcj123456 opened this issue Oct 22, 2024 · 3 comments
Open

yarpgen support pragma omp simd #202

huangcj123456 opened this issue Oct 22, 2024 · 3 comments

Comments

@huangcj123456
Copy link

I used the Yargen tool and found a bug in the tool.

wrong code:
void test(int *acc, int *inc) {
#pragma omp simd
for (int i = 0; i < 16; i++)
*acc += *inc;
}

OK code:
void test(int *acc, int *inc) {
#pragma omp simd reduction(+:acc[0])
for (int i = 0; i < 16; i++)
*acc += *inc;
}
The absence of the "reduction" keyword leads to undefined behavior in this test case.

Who knows how to solve this problem?

@dbabokin
Copy link
Contributor

Could you please elaborate why is this UB? I'm not an expert in OpenMP, so pointers to standard would help.

@huangcj123456
Copy link
Author

SIMD Reduction:

#pragma omp for simd reduction(+:local_sum) is applied to the loop. This tells the compiler to vectorize the loop and also to perform a reduction operation on local_sum across different iterations assigned to different threads.
The reduction is done with the addition operator +, which combines local_sum from all threads into the final result.

@huangcj123456 huangcj123456 changed the title yaprgen support pragma omp simd yarpgen support pragma omp simd Oct 22, 2024
@dbabokin
Copy link
Contributor

But why is it UB without reduction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants