summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/mpi/package.py
blob: 409331e6a375dd6ea439593a4e0c2745bad58be3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os

from spack.package import *


class Mpi(Package):
    """Virtual package for the Message Passing Interface."""

    homepage = "https://www.mpi-forum.org/"
    virtual = True

    def test_mpi_hello(self):
        """build and run mpi hello world"""
        for lang in ("c", "f"):
            filename = self.test_suite.current_test_data_dir.join("mpi_hello." + lang)

            compiler_var = "MPICC" if lang == "c" else "MPIF90"
            compiler = which(os.environ[compiler_var])
            mpirun = which(self.prefix.bin.mpirun)

            exe_name = "mpi_hello_%s" % lang

            with test_part(self, f"test_mpi_hello_{lang}", purpose=f"build and run {filename}"):
                compiler("-o", exe_name, filename)
                out = mpirun("-np", "1", exe_name, output=str.split, error=str.split)
                expected = [r"Hello world! From rank \s*0 of \s*1"]
                check_outputs(expected, out)