【发布时间】:2015-06-25 07:28:20
【问题描述】:
我用 OpenCL C 编写了一个代码来列出所有可用的平台。
int main()
{
cl_context context;
cl_platform_id* platforms;
cl_device_id* devices;
cl_uint platformcount;
cl_int ret;
clGetPlatformIDs(2,NULL,&platformcount);
clGetPlatformIDs(platformcount,platforms,NULL);
/*if(ret==CL_SUCCESS)
{
printf("\nNumber of platforms found=%d\n",platformcount);
}*/
return 0;
}
这会导致核心被转储(Segmentation fault (core dumped))。
$ gcc -lOpenCL a.c -o a && ./a
Segmentation fault (core dumped)
但是,如果我注释掉 ret 声明,代码编译得很好。
int main()
{
cl_context context;
cl_platform_id* platforms;
cl_device_id* devices;
cl_uint platformcount;
//cl_int ret;
clGetPlatformIDs(2,NULL,&platformcount);
clGetPlatformIDs(platformcount,platforms,NULL);
/*if(ret==CL_SUCCESS)
{
printf("\nNumber of platforms found=%d\n",platformcount);
}*/
return 0;
}
为什么会这样?
【问题讨论】:
-
要突出显示代码,请将您的代码环绕在一对 ` 之间
-
哦。我用 ' 而不是 `。
标签: c linux parallel-processing opencl gpgpu