Threading Building Blocks, AMD Athlon 64 X2, and Gentoo Linux

There have been so many questions, since the announcement of the Threading Building Blocks open source project, about whether TBB works on non-Intel (for example, AMD) processors. The answer is quite simple: yes. As the TBB Product Overview states, Threading Building Blocks:

Provides a single solution for Windows*, Linux*, and Mac OS* on 32-bit and 64-bit platforms using Intel®, Microsoft, and GNU compilers.

So, the question of whether TBB is a viable solution for applications that need to run on AMD processors (and what Linux or Windows app doesn't need to run efficiently on AMD as well as Intel processors?) is one that can and should be set aside immediately.

Threading Building Blocks is a C++ template library, constructed using standard C++ library techniques. TBB is designed to be portable to any operating system that supports standardized C++ compilation. I myself am interested in looking into applying TBB on OpenSolaris. Much of my multithreaded development experience is on Sun Solaris machines, so it will be interesting to try out TBB on a Solaris platform.

But that's in the future. Today, I'm quite thrilled about having a fully built and tested installation of Threading Building Blocks running on my AMD dual-core Athlon 64 system, on which I'm running Gentoo 2007, optimized for 64-bit Athlon processors.

Building TBB on Gentoo

Gentoo has its own peculiarities. I like it because the portage package manager lets me easily install exactly what I want to install, and nothing more. The result is that I have a very "clean" system to work with. While installing the operating system, I had to be sure to include the options for multithreading; as usual, the Gentoo documentation is very thorough, making it easy to find the switches you need and activate them.

I went to the Downloads page, navigated to the "Commercial Aligned Release" (I wanted to start out with the stablest version available), and clicked the "tbb20_010oss" link. From there, I downloaded the tbb20_010oss_src.tar.gz and tbb20_010oss_lin.tar.gz files, and unpacked them into a directory on my hard drive.

Then, following the advice that was posted in response to my TBB Forums query about the Linux install package, I copied everything beneath my tbb20_010oss_lin directory into my tbb20_010oss_src directory. Doing this copied the em64t, ia32, and itanium directories from the *lin directory into the *src directory. I copied everything, but expected that I only really needed the em64t directory.

Next, I entered my tbb20_010oss_src directory and entered: make. And the build was off and running!

"Warning: not running on genuine Intel hardware"

The system chugged away for quite a long time, building and running test programs, the examples programs, etc. At one point, the scrolling paused, showing me this scary message:

Warning: not running on genuine Intel hardware

That was true, yes... And now that I've thought about it a bit more, that really is a rather curious message. Let's see where it comes from.

Ah! I see it! It's in file src/test/test_assembly.cpp:

static void TestIsGenuineIntel() {
if( !IsGenuineIntel() )
printf("Warning: not running on genuine Intel hardware\n");

The IsGenuineIntel() function can be found in src/tbb/task.cpp. It's a static inline function that accesses data defining the CPU ID. It all looks rather innocuous. No, Intel hasn't secretly disabled portions of the TBB library if you happen to be running on a processor that's not "genuine Intel hardware." If you don't believe me, look at the code.

And that, indeed, is one of the primary benefits of making software open source. There cannot be anything to hide, because the source code is all there, available for scrutiny by anyone who'd like to take a look.

Yeah, my AMD Athlon 64 X2 really is a 2-core system!

As the automated test programs that are part of the TBB installation were running, I was able to see the processing times for various runs scroll by. The timings showed that when the programs were run with more than a single thread, the execution time was approximately half of the execution time for the single thread execution -- proving that, indeed, I have a working AMD Athlon 64 X2 dual-core processor, and I can successfully utilize both cores by applying TBB while running on my favorite Linux distribution, Gentoo. Yeah!

Kevin Farnham
O'Reilly Media

For more complete information about compiler optimizations, see our Optimization Notice.

1 comment

anonymous's picture

Thank you for the information... Great read!

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.