Pretty simple thing in CPU.
But If its doing with OpenGL shader you may find a difficulty of losing parallelism of GPU.
Few days later we had a requirement of finding sum of pixels in texture of dimension 100 * 100.
If we are calculating sum in Fragment shader, a single pixel will be rendered and iterate through each pixels in the texture, and sum will be returned from the shader.
Now here is another option to get the sum without iterating through each elements in texture.
We can use blending feature of OpenGL frame buffer.
Enable Additive blending for Frame Buffer. use glBlendEquation(GL_FUNC_ADD)
http://www.opengl.org/sdk/docs/man/xhtml/glBlendEquation.xml
Create a RenderTarget of size 1*1. Then clear it, and render all pixel to it.
Now U will get sum of the texture in your render target.