# Newbie question about shared memory

**URL:** <https://forums.developer.nvidia.com/t/newbie-question-about-shared-memory/12794>\
**Category:** CUDA Programming and Performance\
**Created:** [October 16, 2009, 7:44am UTC](https://forums.developer.nvidia.com/t/newbie-question-about-shared-memory/12794 "2009-10-16T07:44:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![v3n0w](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@v3n0w](https://forums.developer.nvidia.com/u/v3n0w)\
**Post date:** [October 16, 2009, 7:44am UTC](https://forums.developer.nvidia.com/t/newbie-question-about-shared-memory/12794/1 "2009-10-16T07:44:03Z")

</div>

Hello guys!

I’m trying to calculate the sum of a simple vector.

I think the most difficult concept to understand about OpenCL is the shared memory.

So, All threads on the same block share the “\_\_local” memory, right?

To test this, I create a kernel the sums a vector using only one group.

And did the following kernel:

```auto
__kernel void VectorAdd(__global const float* vector, __global float* result,__ local float *partResult)

{

	

	int id = get_global_id(0);

	

	if(id == 0)

		*partResult = 0;

	

	 barrier(CLK_LOCAL_MEM_FENCE);

	*partResult += vector[id];

	barrier(CLK_LOCAL_MEM_FENCE);

	if(id == get_global_size(0)-1)

		*result = *partResult;

	

}

```

I initialized the \_\_local with 0, synchronize… Do the sum, synchronize and copy to the global memory.

What’s is wrong on this code?

Remembering that there’s only one group.

Thanks!
