| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2013-2019 The Meson development team |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
|
| 6 |
import typing as T |
| 7 |
|
| 8 |
from .base import DependencyCandidate, DependencyMethods, detect_compiler, SystemDependency |
| 9 |
from .cmake import CMakeDependency |
| 10 |
from .detect import packages |
| 11 |
from .pkgconfig import PkgConfigDependency |
| 12 |
from .factory import factory_methods |
| 13 |
|
| 14 |
if T.TYPE_CHECKING: |
| 15 |
from . factory import DependencyGenerator |
| 16 |
from ..environment import Environment |
| 17 |
from .base import DependencyObjectKWs |
| 18 |
|
| 19 |
|
| 20 |
@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE, DependencyMethods.SYSTEM}) |
| 21 |
def coarray_factory(env: 'Environment', |
| 22 |
kwargs: DependencyObjectKWs, |
| 23 |
methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']: |
| 24 |
kwargs['language'] = 'fortran' |
| 25 |
for_machine = kwargs['native'] |
| 26 |
fcid = detect_compiler('coarray', env, for_machine, 'fortran').get_id() |
| 27 |
candidates: T.List['DependencyGenerator'] = [] |
| 28 |
|
| 29 |
if fcid == 'gcc': |
| 30 |
# OpenCoarrays is the most commonly used method for Fortran Coarray with GCC |
| 31 |
if DependencyMethods.PKGCONFIG in methods: |
| 32 |
for pkg in ['caf-openmpi', 'caf']: |
| 33 |
candidates.append(DependencyCandidate.from_dependency( |
| 34 |
pkg, PkgConfigDependency, (env, kwargs))) |
| 35 |
|
| 36 |
if DependencyMethods.CMAKE in methods: |
| 37 |
nkwargs = kwargs |
| 38 |
if not kwargs.get('modules'): |
| 39 |
nkwargs = kwargs.copy() |
| 40 |
nkwargs['modules'] = ['OpenCoarrays::caf_mpi'] |
| 41 |
candidates.append(DependencyCandidate.from_dependency( |
| 42 |
'OpenCoarrays', CMakeDependency, (env, nkwargs))) |
| 43 |
|
| 44 |
if DependencyMethods.SYSTEM in methods: |
| 45 |
candidates.append(DependencyCandidate.from_dependency( |
| 46 |
'coarray', CoarrayDependency, (env, kwargs))) |
| 47 |
|
| 48 |
return candidates |
| 49 |
|
| 50 |
|
| 51 |
packages['coarray'] = coarray_factory |
| 52 |
|
| 53 |
|
| 54 |
class CoarrayDependency(SystemDependency): |
| 55 |
""" |
| 56 |
Coarrays are a Fortran 2008 feature. |
| 57 |
|
| 58 |
Coarrays are sometimes implemented via external library (GCC+OpenCoarrays), |
| 59 |
while other compilers just build in support (Cray, IBM, Intel, NAG). |
| 60 |
Coarrays may be thought of as a high-level language abstraction of |
| 61 |
low-level MPI calls. |
| 62 |
""" |
| 63 |
def __init__(self, name: str, environment: 'Environment', kwargs: DependencyObjectKWs) -> None: |
| 64 |
kwargs['language'] = 'fortran' |
| 65 |
super().__init__(name, environment, kwargs) |
| 66 |
|
| 67 |
cid = self.get_compiler().get_id() |
| 68 |
if cid == 'gcc': |
| 69 |
# Fallback to single image |
| 70 |
self.compile_args = ['-fcoarray=single'] |
| 71 |
self.version = 'single image (fallback)' |
| 72 |
self.is_found = True |
| 73 |
elif cid == 'intel': |
| 74 |
# Coarrays are built into Intel compilers, no external library needed |
| 75 |
self.is_found = True |
| 76 |
self.link_args = ['-coarray=shared'] |
| 77 |
self.compile_args = self.link_args |
| 78 |
elif cid == 'intel-cl': |
| 79 |
# Coarrays are built into Intel compilers, no external library needed |
| 80 |
self.is_found = True |
| 81 |
self.compile_args = ['/Qcoarray:shared'] |
| 82 |
elif cid == 'nagfor': |
| 83 |
# NAG doesn't require any special arguments for Coarray |
| 84 |
self.is_found = True |