Skip to content

Commit 3a30d19

Browse files
committed
MPI detection: support Intel MPI on Windows
1 parent c42881a commit 3a30d19

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

mesonbuild/dependencies/mpi.py

+54
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from ..environment import detect_cpu_family
1212
from ..mesonlib import Popen_safe
13+
from ..options import OptionKey
1314
from .base import DependencyException, DependencyMethods, detect_compiler, SystemDependency
1415
from .configtool import ConfigToolDependency
1516
from .detect import packages
@@ -82,6 +83,8 @@ def mpi_factory(env: 'Environment',
8283
if DependencyMethods.SYSTEM in methods and env.machines[for_machine].is_windows():
8384
candidates.append(functools.partial(
8485
MSMPIDependency, 'msmpi', env, kwargs, language=language))
86+
candidates.append(functools.partial(
87+
IMPIDependency, 'impi', env, kwargs, language=language))
8588

8689
# Only OpenMPI has pkg-config, and it doesn't work with the intel compilers
8790
# for MPI, environment variables and commands like mpicc should have priority
@@ -244,3 +247,54 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any],
244247
self.compile_args = ['-I' + incdir, '-I' + os.path.join(incdir, post)]
245248
if self.language == 'fortran':
246249
self.link_args.append('-l' + os.path.join(libdir, 'msmpifec'))
250+
251+
252+
class IMPIDependency(SystemDependency):
253+
254+
"""Intel(R) MPI for Windows."""
255+
256+
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any],
257+
language: T.Optional[str] = None):
258+
super().__init__(name, env, kwargs, language=language)
259+
# only for windows
260+
if not self.env.machines[self.for_machine].is_windows():
261+
return
262+
# only for x86 and x64
263+
arch = detect_cpu_family(self.env.coredata.compilers.host)
264+
if arch not in ('x86', 'x86_64'):
265+
self.is_found = False # TODO: is this line correct?
266+
return
267+
268+
rootdir = os.environ.get('I_MPI_ROOT')
269+
if rootdir is None:
270+
self.is_found = False
271+
return
272+
273+
subdir = 'ia32' if arch == 'x86' else 'intel64'
274+
prefix = os.path.join(rootdir, subdir)
275+
if not os.path.isdir(prefix):
276+
prefix = rootdir
277+
278+
incdir = os.path.join(prefix, 'include')
279+
libdir = os.path.join(prefix, 'lib')
280+
281+
buildtype = env.coredata.optstore.get_value_for(OptionKey('buildtype'))
282+
assert isinstance(buildtype, str)
283+
libdir_post = 'debug' if buildtype.startswith('debug') else 'release'
284+
for subdirs in (['mpi', libdir_post], [libdir_post]):
285+
libdir_buildtype = os.path.join(libdir, *subdirs)
286+
if os.path.isdir(libdir_buildtype):
287+
libdir = libdir_buildtype
288+
break
289+
290+
found_header = os.path.isfile(os.path.join(incdir, 'mpi.h'))
291+
found_library = os.path.isfile(os.path.join(libdir, 'impi.lib'))
292+
if not found_header or not found_library:
293+
self.is_found = False
294+
return
295+
296+
self.is_found = True
297+
self.compile_args = ['-I' + incdir]
298+
self.link_args = ['-l' + os.path.join(libdir, 'impi')]
299+
if self.language == 'cpp':
300+
self.link_args = ['-l' + os.path.join(libdir, 'impicxx')]

0 commit comments

Comments
 (0)