2016-06-08 34 views
0

我爲與-time/2步填充向量t時間/ 2和步長DT以下功能:推力:操作員「*」不支持

#define THRUST_PREC thrust::complex<double> 
__host__ void generate_time(thrust::device_vector<THRUST_PREC> *t, const double dt, const double time) 
{ 
    THRUST_PREC start = -time/2.0; 
    THRUST_PREC step = dt; 
    thrust::sequence((*t).begin(), (*t).end(), start, step); 
} 

編譯時,我得到error : no operator "*" matches these operands 。爲什麼?有沒有辦法像我一樣填充矢量,還是應該用舊的方式填充它(又名循環)?

編輯:完整的錯誤:Error 1 error : no operator "*" matches these operands C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include\thrust\system\detail\generic\sequence.inl 48 1 FFT_test

+4

請提供[mcve],並提供來自編譯器的*整套錯誤和註釋*,而不僅僅是exerpt。如果你理解錯誤信息,你不需要在這裏問,如果你不明白爲什麼你認爲總結是足夠的?我的意思是,我無法相信它沒有給你發生錯誤的線路。 – Yakk

+0

@Yakk:我添加了完整的錯誤,這是我得到的所有MSVC ... –

+0

我不知道,我直接從MSVC複製錯誤。刪除/註釋此功能時,錯誤消失。添加/取消註釋時,出現上面列出的錯誤。 –

回答

4

它看起來像的thrust::complex的錯誤。沒有定義const thrust:complex<double>signed long之間的乘法運算。

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sequence.inl(48): 
error: no operator "*" matches these operands 
      operand types are: const thrust::complex<double> * signed long 
      detected during: 
      .... 

但奇怪的是,你可以使用thrust::transform來代替。以下代碼有效。

#define THRUST_PREC thrust::complex<double> 
__host__ void generate_time(thrust::device_vector<THRUST_PREC> *t, const double dt, const double time) 
{ 
    THRUST_PREC start = -time/2.0; 
    THRUST_PREC step = dt; 
    thrust::transform(thrust::make_counting_iterator(0), 
        thrust::make_counting_iterator(0) + t->size(), 
        t->begin(), 
        start + step * _1); 
} 

在任一方式中,內部實現使用索引(類型signed longthrust::sequence的)與式來計算所期望的序列

start + step * index; 

事情防止thrust::sequence從工作是operator *(...)是沒有很好的重載。

thrust::complex<double> a(1,1); 
double double_b = 4; 
float float_b = 4; 
int int_b = 4; 
long long_b = 4; 

a *= double_b; // ok 
a *= float_b; // ok 
a *= int_b; // ok 
a *= long_b; // ok 

std::cout << a * double_b << std::endl; // ok 
std::cout << a * float_b << std::endl; // error 
std::cout << a * int_b << std::endl; // error 
std::cout << a * long_b << std::endl; // error 
+0

我沒有得到這個輸出作爲錯誤信息,只有我發佈的第一部分。無論如何,爲什麼還要簽名? –

+0

你也可以自己定義它。 :) – Yakk

+0

@arc_lupus我們使用不同的編譯器。 – kangshiyin