summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/minigmg/package.py
blob: 8bf54c52aa27cb313234009cf490540bd912408d (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
# Copyright 2013-2022 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)


class Minigmg(Package):
    """miniGMG is a compact benchmark for understanding the performance
    challenges associated with geometric multigrid solvers
    found in applications built from AMR MG frameworks
    like CHOMBO or BoxLib when running
    on modern multi- and manycore-based supercomputers.
    It includes both productive reference examples as well as
    highly-optimized implementations for CPUs and GPUs.
    It is sufficiently general that it has been used to evaluate
    a broad range of research topics including PGAS programming models
    and algorithmic tradeoffs inherit in multigrid. miniGMG was developed
    under the CACHE Joint Math-CS Institute.

    Note, miniGMG code has been supersceded by HPGMG. """

    homepage = "http://crd.lbl.gov/departments/computer-science/PAR/research/previous-projects/miniGMG/"
    url      = "https://crd.lbl.gov/assets/Uploads/FTG/Projects/miniGMG/miniGMG.tar.gz"

    version('master', sha256='1c2d27496a881f655f5e849d6a7a132625e535739f82575991c511cc2cf899ac')

    variant('vec', default='ompif', description='Which method of vectorisation to use',
            values=('ompif', 'sse', 'avx', 'simde'), multi=False)

    variant('opt', default=False, description='Enable optimization flags for improved OpenMP')

    depends_on('mpi')

    # Set up SIMD Everywhere config
    depends_on('simde', when='vec=simde')
    patch('simde.patch', when='vec=simde')

    # Patch to add timer for Aarch64 rather than rdtsc
    patch('aarch64_time.patch', when='target=aarch64:')

    # Replaces inline with inline static, for correct syntax
    patch('inline_static.patch')

    def install(self, spec, prefix):

        cc = Executable(spec['mpi'].mpicc)

        args = []

        # Default optimisation level
        if spec.satisfies('+opt'):
            if self.spec.satisfies('%nvhpc'):
                args.append('-fast')
            else:
                args.append('-Ofast')
        else:
            args.append('-O3')

        # Add OpenMP flag
        args += [self.compiler.openmp_flag]

        args += ['miniGMG.c', 'mg.c', 'box.c', 'solver.c']

        # Set the correct operators file - using the vec variant
        if spec.satisfies('vec=sse'):
            args += ['operators.sse.c']
        elif spec.satisfies('vec=avx'):
            args += ['operators.avx.c']
        elif spec.satisfies('vec=simde'):
            args += ['operators.simde.c']
        else:
            args += ['operators.ompif.c']

        # Switch out timer file (depends on patch)
        if spec.satisfies('target=aarch64:'):
            args += ['timer.aarch64.c']
        else:
            args += ['timer.x86.c']

        args += ['-D__MPI']

        if spec.satisfies('+opt'):
            args += ['-D__PREFETCH_NEXT_PLANE_FROM_DRAM']
            args += ['-D__FUSION_RESIDUAL_RESTRICTION']
        else:
            args += ['-D__COLLABORATIVE_THREADING=6']

        args += ['-D__TEST_MG_CONVERGENCE', '-D__PRINT_NORM', '-D__USE_BICGSTAB']
        args += ['-o', 'run.miniGMG', '-lm']

        cc(*args)

        mkdir(prefix.bin)
        install('run.miniGMG', prefix.bin)
        mkdir(prefix.jobs)
        install('job*', prefix.jobs)