2013-04-03 118 views
1
thrust::host_vector<int> A; 
thrust::host_vector<int> B; 

int rand_from_0_to_100_gen(void) 
{ 
    return rand() % 100; 
} 


__host__ void generateVector(int count) { 


    thrust::host_vector<int> A(count); 
    thrust::generate(A.begin(),A.end(),rand_from_0_to_100_gen); 

    thrust::host_vector<int> B(count); 
    thrust::generate(B.begin(),B.end(),rand_from_0_to_100_gen); 
} 

__host__ void displayVector(int count){ 

    void generateVector(count); 

    cout << A[1]; 


} 

在上面的代码中,为什么我不能显示矢量值?它给错误在为什么编译器给出错误?

void generateVector(count); 

那说incomplete is not allowed为什么?这里有什么问题?可能的解决方案是什么?

回答

1

您在功能displayVector中错误地调用功能generateVector。它应该是这样的:

generateVector(count); 

此外,要创建载体AB功能generateVector这将是局部的功能和thrust::generate将在这些地方工作的载体里面。全局向量AB不会被修改。你应该删除本地载体来实现你想要的。请改为拨打host_vector::resize以获取全局向量AB以分配内存。

最后的代码应该是这样的:

thrust::host_vector<int> A; 
thrust::host_vector<int> B; 

int rand_from_0_to_100_gen(void) 
{ 
    return rand() % 100; 
} 

__host__ void generateVector(int count) 
{ 
    A.resize(count); 
    thrust::generate(A.begin(),A.end(),rand_from_0_to_100_gen); 

    B.resize(count); 
    thrust::generate(B.begin(),B.end(),rand_from_0_to_100_gen); 
} 

__host__ void displayVector(int count) 
{ 
    generateVector(count); 
    cout << A[1]<<endl; 
} 
+0

感谢在generateVector和displayVector功能你的帮助有* HDATA什么可能是定义为int一个参数? – user2236653

+0

你的代码中的'hData'在哪里? – sgarizvi

+0

这里没有hData。家伙定义这个函数通过把int * hData我不知道为什么 – user2236653

相关问题