# -*- 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
# $Id: Portfile 116359 2014-01-23 20:13:29Z sean@macports.org $

PortSystem          1.0
PortGroup           mpi 1.0

mpi.setup

name                hpl
version             2.1
revision            1
categories          science
platforms           darwin
license             BSD
maintainers         gmail.com: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 bits) 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  4d4a981e16ca12d52c31d5f5c9557bed01616081 \
                    sha156  460f7f36cc97a1a1fcc60e43d5833e6efb0aa03c

#variant threads?

# patch enables parallel build
patchfiles          patch-Makefile.diff

use_configure       no

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

build.args          ARCH=MacOS TOPdir=${worksrcpath} MPlib=
build.target        all-j arch=macos
use_parallel_build  yes

test.run  yes

destroot {
    xinstall ${worksrcpath}/bin/macos/xhpl ${destroot}${prefix}/bin/
    xinstall -d ${destroot}${prefix}/share/hpl
    xinstall ${worksrcpath}/bin/macos/HPL.dat ${destroot}${prefix}/share/hpl/
    xinstall ${worksrcpath}/TUNING ${destroot}${prefix}/share/hpl/
}

if {![mpi_variant_isset]} {
    default_variants    +mpich
}

if {![variant_isset atlas]} {
    default_variants    +accelerate
}

if {[mpi_variant_isset]} {
    pre-build {
        build.args-append      CC=${mpi.cc} \
                               LINKER=${mpi.cc}
    }

    pre-test {
        test.cmd cd bin/macos && ${mpi.exec} -n 4 ./xhpl
    }
}

variant atlas conflicts accelerate description {Use ATLAS for BLAS library} {
    depends_lib-append     port:atlas
    build.args-append      LAlib="${prefix}/lib/libsatlas.dylib"
}

variant accelerate conflicts atlas description {Use Accelerate for BLAS library} {
    build.args-append      LAlib="/usr/lib/libblas.dylib"
}

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