Using TBB on Xeon Phi compilation issue

 Intro

While partiipating in Intel Accelerate Your Code 2013 summer contest, I had some issues with compiling TBB code for mic (Xeon Phi) architecture.

I wasn't able to find this information on the internet, so after successfully solving this issue, I decided to share my experience here.

 System

CentOS 6.4 x64, icpc (ICC) 13.1.1 20130313

 The source code

#include <tbb/task_scheduler_init.h>

 

int main(){

            tbb::task_scheduler_init init;

            return 0;

}

 

For the purpose of an example, I will use a source code as simple as possible.

The command I would normally use to compile this would be

icpc -O3 test.cpp -ltbb -o test

This works perfectly fine for the desktop.

 The issue

To build a Xeon Phi compatible binary I need to use –mmic, but when trying

icpc -O3 test.cpp -ltbb -mmic -o test

Compilation fails with an error

x86_64-k1om-linux-ld: cannot find -ltbb

Knowing that the –tbb instead of -ltbb also works for desktop

icpc -O3 test.cpp -tbb -o test

I tried to use it with –mmic

icpc -O3 test.cpp -tbb -mmic -o test

This produced a different error

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `sem_init'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_mutex_trylock'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_mutexattr_settype'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_key_create'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_attr_setstacksize'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_attr_getstack'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `sem_destroy'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_getspecific'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_mutexattr_destroy'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_create'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_mutexattr_init'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_key_delete'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `sem_post'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_detach'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_setspecific'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_getattr_np'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `sem_wait'

/opt/intel/composer_xe_2013.3.163/tbb/lib/mic/libtbb.so.2: undefined reference to `pthread_join'

 

Though still having an error, this error is much more informative: looks like all missing references are from pthread library, so let’s try adding –lpthread to the compiler options

icpc -O3 test.cpp -tbb -lpthread -mmic -o test

And it worked!

I hope this will be helpful to some people.

This is my first blog post here, and all your comments are very welcome.

 

有关编译器优化的更完整信息,请参阅优化通知