Open

Description
Say I want to add two vectors as in example two. In the example, memory space is allocated and host data is created inside the code:
float* h_a = (float*) calloc(LENGTH, sizeof(float)); // a vector
float* h_b = (float*) calloc(LENGTH, sizeof(float)); // a vector
int i = 0;
int count = LENGTH;
for(i = 0; i < count; i++){
h_a[i] = rand() / (float)RAND_MAX;
h_b[i] = rand() / (float)RAND_MAX;
}
I'm trying to pass vectors a
and b
from R
. They are passed as arguments to the main
function as: vadd(double *a, double *b, int *n)
(in R
I have to change main
for some other name like vadd
). I allocate memory and I dereference the arguments as:
int i = 0;
int count = LENGTH;
for(i = 0; i < count; i++){
h_a[i] = a[i];
h_b[i] = b[i];
}
This dereferencing procedure is taking too much time. Is there a way so that these pointers passed as arguments to the function are set as host data directly without the loop? Something like:
h_a = *a; h_b = *b;
Metadata
Metadata
Assignees
Labels
No labels