スラストを使用して配列 c の合計を見つけていますが、「エラー: 式にはクラス型が必要です」というコンパイラ エラーが発生し続けます。
float tot = thrust::reduce(c.begin(), c.end());
これは機能していないコード行です。c は float 配列であり、他の 2 つの配列の要素の合計です。
乾杯
スラストを使用して配列 c の合計を見つけていますが、「エラー: 式にはクラス型が必要です」というコンパイラ エラーが発生し続けます。
float tot = thrust::reduce(c.begin(), c.end());
これは機能していないコード行です。c は float 配列であり、他の 2 つの配列の要素の合計です。
乾杯
にポインタを渡すことができますthrust::reduce
。ホストメモリに配列へのポインタがある場合、次のようなことができます:
float tot = thrust::reduce(c, c + N); // N is the length of c in words
thrust::device_ptr
ポインタがデバイス メモリ内の配列を指している場合は、最初にキャストする必要があります。
thrust::device_ptr<float> cptr = thrust::device_pointer_cast(c);
float tot = thrust::reduce(cptr, cptr + N); // N is the length of c in words
c はorthrust
などの型でなければなりません。thrust::host_vector
thrust::device_vector
Thrust の github ページには、thrust::reduce の例があります。オブジェクトのインスタンスではないため、単純な古い配列で .begin() を呼び出すことはできません。つまり、意味がありません。例として、以下のコードで配列 "b" に対して .begin() を呼び出すようなものです。
int main(void)
{
thrust::host_vector<float> a(10);
float b[10];
thrust::fill(a.begin(), a.end(), 1.0);
thrust::fill(b, b+10, 2.0);
cout << "a: " << thrust::reduce(a.begin(), a.end()) << endl;
cout << "b: " << thrust::reduce(b, b+10) << endl;
return 0;
}