c - 如何在 OpenMP 中的线程之间分发数据?

标签 c parallel-processing openmp

假设我有一个特定大小为 n 的数组,并且还有 n 个线程。现在我想在程序开始时将数组的一个元素提供给每个线程。我该如何在 OpenMP 中执行此操作?

最佳答案

在并行 block 中使用 omp_get_thread_num() 来获取线程 ID,然后使用该 ID 索引长度为 n 的共享数组。确保将用于保存线程 ID 的任何变量设置为私有(private)/本地。

关于c - 如何在 OpenMP 中的线程之间分发数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52726713/

相关文章:

c++ - 将 OpenMP 与 clang 一起使用

c - 如何在 openMP 中使用保护数组中的一个元素?

C 扩展整数数组

parallel-processing - GNU 并行 : How do determine job "slot" you're using?

c - C 与 scanf 中的变量赋值

scala - parallelsim下scala并发类和非并发类的区别

python - Python 中的多处理 : execute two functions at the exact same time

c++ - 我使用哪个 openMP pragma 来阻塞 for 循环?

python - 用 C 扩展 python,返回 numpy 数组给出垃圾

c++ - C/C++ J2ME 解释器