看了两天OpenCL的入门书,对OpenCL编程的流程有了大概的了解。下面是一个实现向量加的例子,从网上拿过来的,刚开始有些问题,修改以后可以跑通。代码如下: #include <stdio.h> #include <stdlib.h> #include <CL/cl.h> #define LEN(arr) (sizeof(arr) / sizeof(arr[0])) //kernel source code const char* src[] = { "__kernel void vec_add(__global const float *a, __global const float *b, __global float *c)/n", "{/n", " int gid = get_global_id(0);/n", " c[gid] = a[gid] + b[gid];/n", "}/n" }; int main() { cl_uint numPlatforms; cl_platform_id platform = NULL; cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms); if(status != CL_SUCCESS) { printf("error: getting platforms/n"); exit(1); } cl_platform_id *platforms = (cl_platform_id *)malloc(numPlatforms*sizeof(cl_platform_id)); status = clGetPlatformIDs(numPlatforms, platforms, N