summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/elk/package.py
blob: 1d9216fd1a9c182d7ee4864d34e5db3bc8c1d58f (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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from spack import *
import spack

class Elk(Package):
    '''An all-electron full-potential linearised augmented-plane wave
    (FP-LAPW) code with many advanced features.'''

    homepage = 'http://elk.sourceforge.net/'
    url      = 'https://sourceforge.net/projects/elk/files/elk-3.3.17.tgz'

    version('3.3.17', 'f57f6230d14f3b3b558e5c71f62f0592')

    # Elk provides these libraries, but allows you to specify your own
    variant('blas',   default=True, description='Build with custom BLAS library')
    variant('lapack', default=True, description='Build with custom LAPACK library')
    variant('fft',    default=True, description='Build with custom FFT library')

    # Elk does not provide these libraries, but allows you to use them
    variant('mpi',    default=True, description='Enable MPI parallelism')
    variant('openmp', default=True, description='Enable OpenMP support')
    variant('libxc',  default=True, description='Link to Libxc functional library')

    depends_on('blas',   when='+blas')
    depends_on('lapack', when='+lapack')
    depends_on('fftw',   when='+fft')
    depends_on('mpi',    when='+mpi')
    depends_on('libxc',  when='+libxc')

    # Cannot be built in parallel
    parallel = False


    def configure(self, spec):
        # Dictionary of configuration options
        config = {
            'MAKE':      'make',
            'F90':       join_path(spack.build_env_path, 'f90'),
            'F77':       join_path(spack.build_env_path, 'f77'),
            'AR':        'ar',
            'LIB_FFT':   'fftlib.a',
            'SRC_MPI':   'mpi_stub.f90',
            'SRC_OMP':   'omp_stub.f90',
            'SRC_libxc': 'libxcifc_stub.f90',
            'SRC_FFT':   'zfftifc.f90'
        }

        # Compiler-specific flags
        flags = ''
        if   self.compiler.name == 'intel':
            flags = '-O3 -ip -unroll -no-prec-div -openmp'
        elif self.compiler.name == 'gcc':
            flags = '-O3 -ffast-math -funroll-loops -fopenmp'
        elif self.compiler.name == 'pgi':
            flags = '-O3 -mp -lpthread'
        elif self.compiler.name == 'g95':
            flags = '-O3 -fno-second-underscore'
        elif self.compiler.name == 'nag':
            flags = '-O4 -kind=byte -dusty -dcfuns'
        elif self.compiler.name == 'xl':
            flags = '-O3 -qsmp=omp'
        config['F90_OPTS'] = flags
        config['F77_OPTS'] = flags

        # BLAS/LAPACK support
        blas   = 'blas.a'
        lapack = 'lapack.a'
        if '+blas'   in spec:
            blas   = join_path(spec['blas'].prefix.lib,   'libblas.so')
        if '+lapack' in spec:
            lapack = join_path(spec['lapack'].prefix.lib, 'liblapack.so')
        config['LIB_LPK'] = ' '.join([lapack, blas]) # lapack must come before blas

        # FFT support
        if '+fft' in spec:
            config['LIB_FFT'] = join_path(spec['fftw'].prefix.lib, 'libfftw3.so')
            config['SRC_FFT'] = 'zfftifc_fftw.f90'

        # MPI support
        if '+mpi' in spec:
            config.pop('SRC_MPI')
            config['F90'] = join_path(spec['mpi'].prefix.bin, 'mpif90')
            config['F77'] = join_path(spec['mpi'].prefix.bin, 'mpif77')

        # OpenMP support
        if '+openmp' in spec:
            config.pop('SRC_OMP')

        # Libxc support
        if '+libxc' in spec:
            config['LIB_libxc'] = ' '.join([
                join_path(spec['libxc'].prefix.lib, 'libxcf90.so'),
                join_path(spec['libxc'].prefix.lib, 'libxc.so')
            ])
            config['SRC_libxc'] = ' '.join([
                'libxc_funcs.f90',
                'libxc.f90',
                'libxcifc.f90'
            ])

        # Write configuration options to include file
        with open('make.inc', 'w') as inc:
            for key in config:
                inc.write('{0} = {1}\n'.format(key, config[key]))


    def install(self, spec, prefix):
        # Elk only provides an interactive setup script
        self.configure(spec)

        make()
        make('test')

        # The Elk Makefile does not provide an install target
        mkdirp(prefix.bin)

        install('src/elk',                   prefix.bin)
        install('src/eos/eos',               prefix.bin)
        install('src/spacegroup/spacegroup', prefix.bin)

        install_tree('examples', join_path(prefix, 'examples'))
        install_tree('species',  join_path(prefix, 'species'))