# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           mpi 1.0
PortGroup           linear_algebra 1.0

name                hpl
version             2.3
revision            2
categories          science benchmarks
license             BSD
maintainers         {dstrubbe @dstrubbe}

description         High Performance Computing Linpack Benchmark
long_description    See how your machine compares to the TOP500! \
                    HPL is a software package that solves a (random) dense linear \
                    system in double-precision (64-bit) arithmetic on \
                    distributed-memory computers. It can thus be regarded as a \
                    portable as well as freely available implementation of the \
                    High Performance Computing Linpack Benchmark.
homepage            http://www.netlib.org/benchmark/hpl
master_sites        ${homepage}

checksums           rmd160  02910b59a5a4378125b508b0a85013c998c35c74 \
                    sha256  32c5c17d22330e6f2337b681aded51637fb6008d3f0eb7c277b163fadd612830 \
                    size    660871

mpi.setup           require -fortran
linalg.setup        blas_only

#variant threads?

# patch enables parallel build
patchfiles          patch-Makefile.diff

use_configure       no

set archname        macos

pre-build {
    file copy ${worksrcpath}/setup/Make.FreeBSD_PIV_CBLAS ${worksrcpath}/Make.${archname}
}

build.args          ARCH=${archname} \
                    TOPdir=${worksrcpath} \
                    MPlib=
build.target        all-j arch=${archname}

pre-build {
    build.args-append \
                    CC=${mpi.cc} \
                    LINKER=${mpi.cc} \
                    LAlib="${linalglib}"
}

test.run  yes

destroot {
    xinstall -m 755 ${worksrcpath}/bin/${archname}/xhpl ${destroot}${prefix}/bin/
    xinstall -m 644 ${worksrcpath}/lib/${archname}/lib${name}.a ${destroot}${prefix}/lib/
    xinstall -m 644 {*}[glob -type f ${worksrcpath}/include/*.h] ${destroot}${prefix}/include/
    xinstall -d ${destroot}${prefix}/share/${name}
    xinstall -m 644 ${worksrcpath}/bin/${archname}/HPL.dat ${destroot}${prefix}/share/${name}/HPL.dat.example
    xinstall -m 644 ${worksrcpath}/TUNING ${destroot}${prefix}/share/${name}/
    xinstall -m 644 {*}[glob -type f ${worksrcpath}/man/man3/*] ${destroot}${prefix}/share/man/man3
}

post-activate {
    if {![file exists ${prefix}/share/hpl/HPL.dat]} {
        file copy ${prefix}/share/hpl/HPL.dat.example ${prefix}/share/hpl/HPL.dat
    }
}

pre-test {
    test.dir        ${worksrcpath}/bin/${archname}
    test.cmd        ${mpi.exec} -n ${build.jobs} ./xhpl
}


notes-append "
                   Execute as: \"cd ${prefix}/share/hpl && ${mpi.exec} -n ${build.jobs} xhpl\",\
                   or copy ${prefix}/share/hpl/HPL.dat to the working directory.\
                   See ${prefix}/share/hpl/TUNING on how to change benchmark settings.\
                   Changes to ${prefix}/share/hpl/HPL.dat will be preserved across upgrades.
"

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}
