Skip to content

Commit

Permalink
Compilation works!
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslb committed Sep 9, 2019
1 parent 85d3112 commit 0ece509
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.so
*.o
*.mod
_psiesta.c
11 changes: 6 additions & 5 deletions psiesta/_psiesta.pyx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cimport numpy as np
import numpy as np
from collections import Namedtuple
from collections import namedtuple
from mpi4py import MPI

RunOutput = Namedtuple("RunOutput", "e forces")
RunOutput = namedtuple("RunOutput", "e forces")

cdef extern:
void fpsiesta_launch(char* label, int* mpi_comm)
Expand All @@ -30,12 +30,13 @@ class FSiesta:
if self.locations is not None and locations.shape != self.locations.shape:
raise ValueError()
self.locations = locations
cdef double[::1] loc_view = locations
print(locations.shape)
cdef double[:, ::1] loc_view = locations
cdef int na = locations.shape[0]
cdef double e = 0
forces = np.zeros_like(locations)
cdef double[::1] force_view = forces
fpsiesta_forces(self.label.encode(), &na, &loc_view[0], &e, &force_view[0])
cdef double[:, ::1] force_view = forces
fpsiesta_forces(self.label.encode(), &na, &loc_view[0, 0], &e, &force_view[0, 0])
return RunOutput(e, forces)

def quit(self):
Expand Down
48 changes: 21 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python3
""" PSiesta: Siesta as a Python library
To install, please follow these instructions:
"""PSiesta: Siesta as a Python library
To build, please follow these instructions:
0. Have intel compiler and mkl: The linking is not setup to work with foss (yet)
1. Compile the 'SiestaSubroutine' library in your Siesta Obj dir: `make lib`
2. OBJ=/my/libraries/siesta/Obj ./setup.py install [--user] [--prefix=/custom/prefix/]
2. OBJ=/my/libraries/siesta/Obj CC=mpiicc ./setup.py build_ext --inplace
The _psiesta python library is dumped at the root of the repository. Which is not the best place but it works.
It is a todo to make this work 'better' and with gnu as well.
"""
import setuptools # noqa
from distutils.core import setup
Expand All @@ -14,15 +17,14 @@
import os
import subprocess as sp
from itertools import chain
import sys


# 1. in your siesta obj dir: `make lib`
# 2. OBJ=/my/siesta/Obj/ FC=mpiifort ./setup.py
if any(x in sys.argv for x in ("build", "install", "develop")):
print(__doc__)
print()
sys.exit("-- You provided some argument, but only build_ext --inplace works properly right now")

# Need to $FC -o fpsiesta.a -c psiesta/c_bindings/fpsiesta.f90 $OBJ/{libSiestaForces.a,*.mod}
# then $CC -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python3.7\
# -o _psiesta.so _psiesta/psiesta.c psiesta/c_bindings/fpsiesta.a -lgfortran
# possibly -lifcore for intel (other flags i dont know)

SIESTAOBJ = Path(os.environ.get("OBJ"))
if SIESTAOBJ == Path(""):
Expand All @@ -40,37 +42,29 @@ def cd(where):
args = \
"-qopenmp -lmkl_intel_thread -lmkl_core -lmkl_intel_lp64 -lmkl_blas95_lp64 "\
"-lmkl_lapack95_lp64 -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -lnetcdff -lnetcdf "\
"-lhdf5_fortran -lhdf5 -lz "
"-lhdf5_fortran -lhdf5 -lz -lmkl_avx512 -lmkl_def "

siestalib = "libSiestaForces.a libfdf.a libwxml.a libxmlparser.a MatrixSwitch.a libSiestaXC.a "\
"libmpi_f90.a libncdf.a libfdict.a"
siestalib = [str(SIESTAOBJ/t) for t in siestalib.split(" ")]

test = "libSiestaForces.a libfdf.a libwxml.a libxmlparser.a MatrixSwitch.a libSiestaXC.a libmpi_f90.a libncdf.a libfdict.a"
test = [str(SIESTAOBJ/t) for t in test.split(" ")]

def build_fortran():
# TODO: Make this nice and all? Like the cython extension
with cd(Path(__file__).parent/"psiesta"/"c_bindings"):
cmd = f"mpiifort -fPIC -c -O3 -xHost -I{SIESTAOBJ!s}/ -fp-model source -qopenmp -o fpsiesta.o fpsiesta.f90"
print(cmd)
sp.run(cmd, shell=True, check=True)
cmd = f"mpiifort -fPIC -O3 -xHost -I{SIESTAOBJ!s}/ -o fpsiesta.a fpsiesta.o "
fmods = chain(SIESTAOBJ.glob("*.a"),) # SIESTAOBJ.glob("*.mod")
fmods = test
# lets see if -l{all the libs} is necessary or what
cmd += " ".join(str(fmod) for fmod in fmods)
cmd += " " + args
print(cmd)
sp.run(cmd, shell=True, check=True)


ext_modules = [
Extension(
'_psiesta', # name
['psiesta/_psiesta.pyx'], # source
# other compile args for the compiler (icc for now)
'_psiesta',
['psiesta/_psiesta.pyx'],
extra_compile_args=['-fPIC', '-O3', '-xHost', "-qopenmp"],
# other files to link to
# extra_link_args=["psiesta/c_bindings/fpsiesta.a"],
# i think! needed -lgfortran at least
# TODO: In gcc use -lgfortran instead of ifcore
libraries=["ifcore"] + [lib[2:] for lib in args.split(" ") if lib.startswith("-l")],
extra_objects=["psiesta/c_bindings/fpsiesta.a"],
extra_objects=["psiesta/c_bindings/fpsiesta.o"] + siestalib,
include_dirs=[str(SIESTAOBJ)],
)
]
Expand Down

0 comments on commit 0ece509

Please sign in to comment.