libinstaller/lib/toolchain.py

109 lines
3.4 KiB
Python
Raw Normal View History

import os
2022-09-29 21:21:03 +02:00
import sys
from lib.shell import get_from_command
2022-09-22 01:51:47 +02:00
def get_compiler_version(compiler):
if compiler == "gnu":
2022-09-22 01:51:47 +02:00
cc = "gcc"
elif compiler == "intel":
2022-09-22 01:51:47 +02:00
cc = "icc"
elif compiler == "aocc":
2022-09-22 01:51:47 +02:00
cc = "clang"
compstr = get_from_command([cc, "-dumpversion"]).strip()
return compstr
2022-09-22 01:51:47 +02:00
def get_mpi_version(mpi):
if mpi == "hpcx":
hpcx_dir = os.getenv('HPCX_DIR')
ver_file = hpcx_dir + "/" + "VERSION"
with open(ver_file) as f:
lines = f.readlines()
mpistr = lines[0].split()[1].strip()
elif mpi == "openmpi":
rawstr = get_from_command(["ompi_info"]).splitlines()[1]
mpistr = rawstr[rawstr.find(":")+2:]
elif mpi == "intelmpi":
rawstr = get_from_command(["mpirun","--version"])
mpistr = rawstr.split()[7]
elif mpi == "mpich":
2022-09-22 01:51:47 +02:00
rawstr = get_from_command(["mpirun", "--version"])
mpistr = rawstr.split()[4]
return mpistr
2022-09-22 01:51:47 +02:00
def set_toolchain(compiler, mpi):
if compiler == "gnu":
if mpi == "hpcx" or mpi == "openmpi" or mpi == "mpich":
cc = "mpicc"
cxx = "mpic++"
fc = "mpifort"
elif mpi == "intelmpi":
cc = "mpicc"
cxx = "mpicxx"
fc = "mpif90"
2022-09-29 21:21:03 +02:00
elif mpi == "necmpi":
cc = "mpicc -vh"
cxx = "mpic++ -vh"
fc = "mpinfort -vh"
os.environ["NMPI_CC_H"] = "gcc"
os.environ["NMPI_CXX_H"] = "g++"
os.environ["NMPI_FC_H"] = "gfortran"
elif compiler == "aocc":
if mpi == "hpcx" or mpi == "openmpi":
cc = "mpicc"
cxx = "mpic++"
fc = "mpifort"
os.environ["OMPI_MPICC"] = "clang"
os.environ["OMPI_MPICXX"] = "clang++"
os.environ["OMPI_MPIFC"] = "flang"
os.environ["OMPI_MPIF90"] = "flang"
os.environ["OMPI_MPIF77"] = "flang"
elif (mpi == "intelmpi"):
cc = "\"mpicc -cc=clang\""
cxx = "\"mpicxx -cxx=clang++\""
fc = "\"mpif90 -fc=flang\""
2022-09-29 21:21:03 +02:00
elif mpi == "necmpi":
cc = "mpicc -vh"
cxx = "mpic++ -vh"
fc = "mpinfort -vh"
os.environ["NMPI_CC_H"] = "clang"
os.environ["NMPI_CXX_H"] = "clang++"
os.environ["NMPI_FC_H"] = "flang"
elif compiler == "intel":
if mpi == "hpcx" or mpi == "openmpi":
cc = "mpicc"
cxx = "mpic++"
fc = "mpifort"
os.environ["OMPI_MPICC"] = "icc"
os.environ["OMPI_MPICXX"] = "icpc"
os.environ["OMPI_MPIFC"] = "ifort"
os.environ["OMPI_MPIF90"] = "ifort"
os.environ["OMPI_MPIF77"] = "ifort"
elif mpi == "intelmpi":
cc = "mpiicc"
cxx = "mpiicpc"
fc = "mpiifort"
2022-09-29 21:21:03 +02:00
elif mpi == "necmpi":
cc = "mpicc -vh"
cxx = "mpic++ -vh"
fc = "mpinfort -vh"
os.environ["NMPI_CC_H"] = "icc"
os.environ["NMPI_CXX_H"] = "icpc"
os.environ["NMPI_FC_H"] = "ifort"
elif compiler == "nec":
# only NEC MPI
cc = "mpincc"
cxx = "mpinc++"
fc = "mpinfort"
# set environment variables
os.environ["CC"] = cc
os.environ["CXX"] = cxx
os.environ["FC"] = fc
os.environ["F90"] = fc
os.environ["F77"] = fc
return cc, cxx, fc