Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 320215 - Request for tc-has-openmp() function in toolchain-funcs.eclass
Summary: Request for tc-has-openmp() function in toolchain-funcs.eclass
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 348964
  Show dependency tree
 
Reported: 2010-05-17 15:41 UTC by Samuli Suominen (RETIRED)
Modified: 2010-12-19 22:43 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuli Suominen (RETIRED) gentoo-dev 2010-05-17 15:41:26 UTC
We need a generic function to check if the currently used gcc has openmp capabilities (is built with USE="openmp") or not.

The current breakage:

Take a look at imagemagick's ebuild for example, we maintain a semi-ugly hack there. Then take a look at media-libs/opencv where the ebuild simply assumes this is true. The imagemagick hack pretty much breaks with prefix guys if gcc-apple is used... and the hack is about to get extended even futher. The opencv one simply breaks if you build your gcc without openmp.


At first I was thinking of grepping something from `gcc -v` but it seems no-avail. 

Does anyone have any suggestions?
Comment 1 Samuli Suominen (RETIRED) gentoo-dev 2010-05-17 16:11:52 UTC
gcc-has-openmp() {
	return $([[ $($(tc-getCC) -v 2>&1 </dev/null | grep enable-libgomp) ]])
}

d'oh? :)
Comment 2 Samuli Suominen (RETIRED) gentoo-dev 2010-05-17 16:30:54 UTC
(In reply to comment #1)
> gcc-has-openmp() {
>         return $([[ $($(tc-getCC) -v 2>&1 </dev/null | grep enable-libgomp) ]])
> }
> 
> d'oh? :)
> 

Arfrever suggested following:

gcc-has-openmp() { [[ $(gcc -v 2>&1 </dev/null) == *enable-libgomp* ]]; }
Comment 3 SpanKY gentoo-dev 2010-05-20 04:05:16 UTC
i'd go with tc-has-openmp() since this can be used with fortran code, and in case we want to extend it in the future to some other aspects of the toolchain

see if this works:
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}
}

personally, i think it is an error to build something with USE=openmp and the host gcc doesnt support it (too old / user disabled it).  but i guess we should ewarn in that case rather than die.
use openmp && ! tc-has-openmp && ewarn "Your toolchain (gcc) lacks openmp support, disabling openmp support"
Comment 4 Samuli Suominen (RETIRED) gentoo-dev 2010-05-22 20:49:00 UTC
Mike, nice! this worked for me. i'm using gcc-4.5.0 with USE="openmp".

and that's what I had in mind, ewarn but avoid || die on build failure etc. in case users has switched gcc by accident or something like that... use it as a safe-kludge.
Comment 6 Sébastien Fabbro (RETIRED) gentoo-dev 2010-07-20 20:32:18 UTC
(In reply to comment #3)
> i'd go with tc-has-openmp() since this can be used with fortran code, and in

the implemented test is so far C code only. should we bloat it with fortran code as well?

>     $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" >&/dev/null

-fopenmp is a gcc specific. is the plan doing it multi-compilers, or should we add a test to check CC is gcc? see [1] for other flags.

also not so sure it is the role of an eclass to do autoconf macros like.

[1] http://git.savannah.gnu.org/cgit/autoconf-archive.git/tree/m4/ax_openmp.m4

Comment 7 SpanKY gentoo-dev 2010-07-20 21:58:38 UTC
i dont think it matters as i dont believe it is possible to emerge gcc with openmp support in the C frontend but not the fortran frontend.  so use the tc-has-openmp function in fortran packages.
Comment 8 Sébastien Fabbro (RETIRED) gentoo-dev 2010-07-20 22:34:58 UTC
assuming toolchain-funcs is only for gcc suite, and no mixing of family compilers, i agree.

now take the situation gcc-config set to a gcc < 4.2 and a user sets FC=ifort while installing a package. this test would fail while openmp was actually supported by ifort.


Comment 9 SpanKY gentoo-dev 2010-07-20 22:48:28 UTC
is that a realistic case ?  i'm not inclined to extend toolchain-funcs.eclass to support every random toolchain out there considering the consumers of them are so minuscule.

also, not everyone uses autotools.  so if you have an autotooled package, then yes, you should be bugging the upstream package to fix things on their side.
Comment 10 Sébastien Fabbro (RETIRED) gentoo-dev 2010-07-20 23:08:22 UTC
yes it can be realistic, although i don't foresee another use than in science packages.

many people in science do not use gfortran because it does not compile some legacy fortran 77 codes.

my point with the link to the ax_openmp macro was to show something we could get inspiration from and translate the m4 to the eclass. 
Comment 11 Sébastien Fabbro (RETIRED) gentoo-dev 2010-07-20 23:18:29 UTC
why not adding a simple test such as 

if [[ $(tc-getCC) != *gcc* ]] && [[ $(tc-getFC) != *gfortran* ]]; then
  # not a gcc based toolchain, let the user on his own
  return
fi

before anything else in the tc-has-openmp function?