2017-06-27 35 views
1

想象一下帶有序列j的gfor ...ArrayFire seq to int C++

如果我需要使用實例j的值作爲索引,那麼我可以這樣做?

類似:

vector<double> a(n); 
gfor(seq j, n){ 
    //Do some calculation and save this on someValue 
    a[j] = someValue; 
} 

有人能幫助我(再次)? 謝謝。

回答

1

我找到了一個解決方案...

如果有人有一個更好的選擇,隨意張貼...

首先,創建您的GFOR實例的相同尺寸的序列。 然後,轉換數組中的seq。 現在,採取陣列該行的值(它等於指數)

seq sequencia(0, 200); 
af::array sqc = sequencia; 

//Inside the gfor loop 
countLoop = (int) sqc(j).scalar<float>(); 
+0

不工作,以及...一直循環趕上第一號... –

0

你的方法工作,但休息gfors並行的指標轉換爲標力才能將其從GPU的寫回到主機,砰地停在GPU上。

你想要做更多這樣的:

af::array a(200); 
gfor(seq j, 200){ 
    //Do some calculation and save this on someValue 
    a[j] = af::array(someValue); // for someValue a primitive type, say float 
} 
// ... Now we're safe outside the parallel loop, let's grab the array results 
float results[200]; 
a.host(results) // Copy array from GPU to host, populating a c-type array 
+0

@Lucas爲你做這個解決方案的工作? –