c - OpenMP C 程序说明
问题描述
如果要从并行范围之外访问私有化变量的线程局部值,可以将它们写回全局声明的辅助数组。这是 OpenMP 书籍中描述的方式
(2017 - Bertil Schmidt、Jorge Gonzalez-Dominguez、Christian Hundt、Moritz Schlarb - 并行编程_ 概念与实践-Morgan Kaufmann)
作者想出了这个程序——
int main () {
// maximum number of threads and auxiliary memory
int num = omp_get_max_threads();
int * aux = new int[num];
int i = 1; // we pass this via copy by value
#pragma omp parallel firstprivate(i) num_threads(num) {
// get the thread identifier j
int j = omp_get_thread_num();
i += j;
aux[j] = i;
}
for(k=0; k<num; k++)
printf("%d \n", aux[k]);
}
在 Mac 上试过 -->
这里有什么问题?
解决方案
new
不是 的运算符C
。new
是为了C++
,C
你可以用其他功能分配内存,比如malloc
。
正如您在错误中看到的那样,它说new undeclared
因为该运算符未在中定义C
。(就像使用未知名称一样)
所以它希望你在这里添加一些东西,new int[num];
因为它是这样的
unknown_name/*add something like ;*/ int[num];
而不是new
,你可以使用这样的东西:
int *aux=malloc(sizeof(int)*num);
推荐阅读
- html - 如何将导航栏与标签标签对齐
- apache-spark - Qubole 上的日志记录和调试
- python - 共享对象中的python多进程和线程安全
- python - 如何删除极坐标图中的最后一个刻度
- asp.net-mvc - 如何在 mvc 中部分加载的 div 中处理会话过期
- ruby-on-rails - no implicit conversion of Symbol into Integer rails 5.2.2.1
- php - PHP - 由于上传路径,文件上传失败并使用相关路径保存
- vb.net - 当我在我的 DataGridView 中删除一个项目时如何调整价格(不连接任何数据库)Vb.net
- active-directory - LDAP 绑定允许不正确(非空白)密码
- android - 文字转语音 - 说出价格金额 Android