I am writing host code for the CUDA program, so I am stuck using the standard C functions. I am having trouble initializing the elements of an integer array using the memset function. I was impressed that you could use memset to initialize an integer array, for example, for all four of these:
int num_elements = 10; int* array_example = (int*)malloc(num_elements * sizeof(int)); memset(array_example, 4, sizeof(array_example));
But when I do this, it sets every byte, not every int , to 4. If I say:
memset(array_example, 4, 1);
I get 4 in the first whole, and if I say:
memset(array_example, 4, 2);
I get 1024 in the first integer and 0 in the second. I understand that the memset function sets the number of bytes specified in the third parameter to 4, but is there a way to use memset to set each integer to 4 instead of each byte? Otherwise, I am stuck using a for loop? My GPU has low processing power, so I donβt have access to some of the nicer CUDA add-ons, which allow me to use C ++ more.
source share