Consider the following code:
__global__ void kernel(int *something) {
extern __shared__ int shared_array[];
// Some operations on shared_array here.
}
Is it possible to initialize the whole shared_array
to some value - e.g. 0 - without explicitly addressing each cell in some thread?
No. Shared memory is uninitialised. You have to somehow initialise it yourself, one way or another...
From CUDA C Programming Guide 3.2, Section B.2.4.2, paragraph 2:
__shared__
variables cannot have an initialization as part of their declaration.
This also discards nontrivial default constructors for shared variables.