optimizations and generalization

we calculated the number of thread log with the current number of
threads instead of the maximum number of thread, that why our previous
code didn't work.

i noticed access to const variables (even on register) was faster so i
added it.

we got with 8 thread , 2^24 vector to 408 msec time and 3.9 speedup.