-
Notifications
You must be signed in to change notification settings - Fork 1
/
_compile.py
95 lines (67 loc) · 2.25 KB
/
_compile.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
""" Compile script for Fortran """
import os
import subprocess
import sys
from pathlib import Path
f90_modules = {
"representations/frepresentations": ["frepresentations.f90"],
"representations/facsf": ["facsf.f90"],
"representations/fslatm": ["fslatm.f90"],
"representations/arad/farad_kernels": ["farad_kernels.f90"],
"representations/fchl/ffchl_module": [
"ffchl_module.f90",
"ffchl_scalar_kernels.f90",
"ffchl_kernel_types.f90",
"ffchl_kernels.f90",
"ffchl_electric_field_kernels.f90",
"ffchl_force_kernels.f90",
],
"solvers/fsolvers": ["fsolvers.f90"],
"kernels/fdistance": ["fdistance.f90"],
"kernels/fkernels": ["fkernels.f90", "fkpca.f90"],
"kernels/fgradient_kernels": ["fgradient_kernels.f90"],
}
def find_mkl():
return
def find_flags(fcc: str):
"""Find compiler flags"""
# TODO Find math lib
# TODO Find os
# -lgomp", "-lpthread", "-lm", "-ldl
# ["-L${MKLROOT}/lib/intel64", "-lmkl_rt"]
# COMPILER_FLAGS = ["-O3", "-fopenmp", "-m64", "-march=native", "-fPIC",
# "-Wno-maybe-uninitialized", "-Wno-unused-function", "-Wno-cpp"]
# LINKER_FLAGS = ["-lgomp"]
extra_flags = ["-lgomp", "-lpthread", "-lm", "-ldl"]
flags = ["-L/usr/lib/", "-lblas", "-llapack"] + extra_flags
return flags
def find_fcc():
"""Find the fortran compiler. Either gnu or intel"""
# fcc = "ifort"
fcc = "gfortran"
return fcc
def main():
"""Compile f90 in src/qmllib"""
fcc = find_fcc()
flags = find_flags(fcc)
os.environ["FCC"] = fcc
for module_name, module_sources in f90_modules.items():
path = Path(module_name)
parent = path.parent
stem = path.stem
cwd = Path("src/qmllib") / parent
cmd = (
[sys.executable, "-m", "numpy.f2py", "-c"] + flags + module_sources + ["-m", str(stem)]
)
print(cwd, " ".join(cmd))
proc = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
stdout = proc.stdout
stderr = proc.stderr
exitcode = proc.returncode
if exitcode > 0:
print(stdout)
print()
print(stderr)
exit(exitcode)
if __name__ == "__main__":
main()