- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FYI for Linux Users. Linking binaries with Intel Compiler and -lgomp produces different behavior than linking with GCC and -lgomp (I believe this is expected behavior, however).
omptest.cpp
[cpp]#include#include int main(int argc, char* argv[]) { static const signed int THREADS_TO_USE = 8 ; static const signed int MAX_THREAD_NO = THREADS_TO_USE - 1 ; // 0-based index for thread number signed int maxThreadNo = -1 ; // Will log the highest thread we see here. #pragma omp parallel for schedule(static, 1) num_threads(THREADS_TO_USE) shared(maxThreadNo) for ( signed int i = 0 ; i < THREADS_TO_USE * THREADS_TO_USE ; ++i ) // Ensure enough work to get some threads going { signed int myThread = omp_get_thread_num() ; #pragma omp critical { if ( myThread > maxThreadNo ) maxThreadNo = myThread ; } } if ( maxThreadNo == MAX_THREAD_NO ) printf("SUCCESS\n") ; else printf("FAILED: maxThreadNo == %d\n", maxThreadNo) ; } [/cpp]
omptest.sh script to build/run 4 variants.
[bash]#! /bin/bash test_compile () { ldflag="${1}" exe="./omptest.exe" if [ "${CC}" = "g++" ] ; then openmp="-fopenmp" ; else openmp="-openmp" ; fi ${CC} -O3 -Wall -Werror ${openmp} ${ldflag} -o ${exe} omptest.cpp && ${exe} rm -f ${exe} } build_omptest_nogomp () { echo "Testing ${CC} without gomp:" test_compile "" } build_omptest_withgomp () { echo "Testing ${CC} with gomp:" test_compile -lgomp } CC="g++" build_omptest_nogomp CC="icpc" build_omptest_nogomp CC="g++" build_omptest_withgomp CC="icpc" build_omptest_withgomp [/bash]Produces:
osmith@lucid32:~$ uname -a && bash omptest.shLinux lucid32 2.6.32-19-generic #28-Ubuntu SMP Wed Mar 31 17:46:20 UTC 2010 i686 GNU/LinuxTesting g++ without gomp:SUCCESSTesting icpc without gomp:SUCCESSTesting g++ with gomp:SUCCESSTesting icpc with gomp:FAILED: maxThreadNo == 0
I.e. if you have left-over -lgomp flags from building your project with GCC/G++, you will only get one thread in OpenMP pragmas.
Please note that this code is not intended to be a good example of how to code with openmp :)
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
-liomp5 should replace lgomp. That library handles both gomp and Intel OpenMP function calls consistently (on linux).

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page