How to set a dynmic size of shared memory?

I use the shared memory like this:
shared int sm[WIDTH][HEIGHT];

the size of the shared memroy should be constant, it can not be set as a variable?
Is there any solution that the size of shared memory can flexible changed with conditions outside?

Look in the SDK samples. Search for:

extern shared

for example in the nbody project.

You will have to set the shared memory size when you call your kernel, like this:

integrateBodies<false><<< grid, threads, sharedMemSize >>>

			((float4*)newPos, (float4*)newVel,

			(float4*)oldPos, (float4*)oldVel,

			deltaTime, damping, numBodies);

Thank you