标签:
1. 二维数组使用
1 #include <iostream> 2 #include<cstdlib> 3 using namespace std; 4 5 static const int ROW = 10; 6 static const int COL = 5; 7 8 int main() { 9 int** array = (int**)malloc(ROW*sizeof(int*)); 10 int* data = (int*)malloc(ROW*COL*sizeof(int)); 11 12 // initialize the data 13 for (int i=0; i<ROW*COL; i++) { 14 data[i] = i; 15 } 16 17 // initialize the array 18 for (int i=0; i<ROW; i++) { 19 array[i] = data + i*COL; 20 } 21 22 // output the array 23 for (int i=0; i<ROW; i++) 24 for (int j=0; j<COL; j++) { 25 cout << array[i][j] << endl; 26 } 27 28 free(array); 29 free(data); 30 31 return 0; 32 }
参考文献:
[1] 有哪些优秀的CUDA开源代码?:https://www.zhihu.com/question/29036289/answer/42971562
[2] CUDA一维矩阵的加法:http://tech.it168.com/a2009/1112/807/000000807771.shtml
[3] CUDA二维矩阵加法:http://www.cnblogs.com/jugg1024/p/4349243.html
[4] NVIDIA CUDA Runtime API:http://docs.nvidia.com/cuda/cuda-runtime-api/index.html#axzz4G8M3LWlq
标签:
原文地址:http://www.cnblogs.com/shengshengwang/p/5730287.html