## Thread Building Block test drive

*April 28, 2009 at 12:01 am* *
1 comment *

After reading the TBB book, I spent half day on playing the lib. My test is simple. Having 2 1000-element arrays, do some math on one array, store the result in the other, swap the arrays and do it again. Run this a few million times. I tried this program on my 2-core machine, the result is just as we expected:

Loop | Signal Thread | TBB on 2 cores |

1,000,000 | 36.235s | 18.418s |

3,000,000 | 106.257 | 54.638s |

In this case, the small change of code worth it well. If this library was available when I was working on my last ray-tracing engine, my life would have been much easier. I wish someday, a similar library would be available on GPU.

I found another interesting thing during my test drive:

unsigned a, b = b0;

unsigned n = <a number you like>;

for(int i = 0; i < LOOP; ++i) {

a = b * b + n;

b = a * a + n;

}

No matter what b0 is, a and b will fall into a pair of fixed numbers (s1, s2), which only depend on value of n; If n is a odd number, then a != b. Otherwise, a = b = one of s1 and s2. I can’t prove it in math but I’ve verified b0=[0, 1024) and n=(0, 1024].

Entry filed under: parallel programming. Tags: TBB.

1.MaryTenderLOS | November 26, 2011 at 11:09 pmIt has a rumble feature, and joystick to keep your child engaged. Toys that move with just a little help from baby. These toys are not designed to be used on the sands only.