Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 603546 - tc-has-openmp() function in toolchain-funcs.eclass fails to check for openmp support via libomp
Summary: tc-has-openmp() function in toolchain-funcs.eclass fails to check for openmp ...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-23 07:10 UTC by Amit Prakash Ambasta
Modified: 2021-06-06 03:26 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
libomp-llvm-openmp.patch (libomp-llvm-openmp.patch,267 bytes, patch)
2016-12-23 07:20 UTC, Amit Prakash Ambasta
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Amit Prakash Ambasta 2016-12-23 07:10:52 UTC
tc-has-openmp is implemented as 

tc-has-openmp() {
	local base="${T}/test-tc-openmp"
	cat <<-EOF > "${base}.c"
	#include <omp.h>
	int main() {
		int nthreads, tid, ret = 0;
		#pragma omp parallel private(nthreads, tid)
		{
		tid = omp_get_thread_num();
		nthreads = omp_get_num_threads(); ret += tid + nthreads;
		}
		return ret;
	}
	EOF
	$(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null
	local ret=$?
	rm -f "${base}"*
	return ${ret}
}

However, for llvm/clang openmp support is provided via libomp and the -fopenmp flag should be changed to -fopenmp=libomp.

The following implementation is recommended instead.

tc-has-openmp() {
	local base="${T}/test-tc-openmp"
	cat <<-EOF > "${base}.c"
	#include <omp.h>
	int main() {
		int nthreads, tid, ret = 0;
		#pragma omp parallel private(nthreads, tid)
		{
		tid = omp_get_thread_num();
		nthreads = omp_get_num_threads(); ret += tid + nthreads;
		}
		return ret;
	}
	EOF

	if tc-is-gcc; then
		$(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null
	elif tc-is-clang; then
		$(tc-getCC "$@") -fopenmp=libomp "${base}.c" -o "${base}" >&/dev/null
	fi

	local ret=$?
	rm -f "${base}"*
	return ${ret}
}
Comment 1 Amit Prakash Ambasta 2016-12-23 07:20:53 UTC
Created attachment 457176 [details, diff]
libomp-llvm-openmp.patch
Comment 2 Amit Prakash Ambasta 2016-12-23 08:41:33 UTC
Sorry.. just verified that -fopenmp is sufficient