Professional Documents
Culture Documents
Gather A (K (I) ) Lecturas Irregulares - Scatter A (K (I) ) W Escrituras Irregulares Cilk
Gather A (K (I) ) Lecturas Irregulares - Scatter A (K (I) ) W Escrituras Irregulares Cilk
Cilk
A[:]=5 || for(i=0;i<10;i++) A[i]=5;
A[0:5:2] = 5 || for(i=0;i<10,;i+=2) A[i]=5
A[:]=B[:] || for(i=0;i<10;i++) A[i]=B[i]
C[0:5:2][:] = 12|| for(i=0;i<10;i+=2) for(j=0;j<10;j++) C[i][j]=12
__sec_reduce {add,mul,max,min,max_index..}
Thrust
thrust::host_vector<int> H(4); //Declara un vector en host 4 elementos H(elementos,valor_inicial);
thrust::device_vector<int> D = H; //Inicializa en el device una copia del vector H
thrust::fill(D.begin(), D.begin() + 7, 9); // Primeros 7 elementos 9
thrust::fill(D.begin(), D.begin() + 7, 9); // Elementos 0,1,2,3
thrust::copy(H.begin(), H.end(), D.begin()); // Copia vectores
thrust::transform(X.begin(), X.end(), Y.begin(), thrust::negate<int>()); // Aplica funciones al vector
{ thrust::negate,thrust::modulus}
thrust::copy(Y.begin(), Y.end(), std::ostream_iterator<int>(std::cout, "\n")); // Muestra vector
!Functor!
struct saxpy_functor
{
const float a;
saxpy_functor(float _a) : a(_a) {}
__host__ __device__
float operator()(const float& x, const float& y) const {
return a * x + y;
}
};
void saxpy_fast(float A, thrust::device_vector<float>& X, thrust::device_vector<float>& Y)
{
// Y <- A * X + Y
thrust::transform(X.begin(), X.end(), Y.begin(), Y.begin(), saxpy_functor(A));
}