diff options
author | Denis Davydov <davydden@gmail.com> | 2016-04-25 09:57:48 +0200 |
---|---|---|
committer | Denis Davydov <davydden@gmail.com> | 2016-04-25 13:30:20 +0200 |
commit | b81cb554f505c4075b9df79ab3db08be3d3b9e36 (patch) | |
tree | 20d6512499142295fdb5154942e1279cdd8441a5 /var | |
parent | 5c4bb69af9cceca0b3c4380357ab6e74e7554067 (diff) | |
download | spack-b81cb554f505c4075b9df79ab3db08be3d3b9e36.tar.gz spack-b81cb554f505c4075b9df79ab3db08be3d3b9e36.tar.bz2 spack-b81cb554f505c4075b9df79ab3db08be3d3b9e36.tar.xz spack-b81cb554f505c4075b9df79ab3db08be3d3b9e36.zip |
openblas: a small unit test to make sure Lapack symbols are compiled
Diffstat (limited to 'var')
-rw-r--r-- | var/spack/repos/builtin/packages/openblas/package.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/openblas/package.py b/var/spack/repos/builtin/packages/openblas/package.py index 4522130ccc..252f699652 100644 --- a/var/spack/repos/builtin/packages/openblas/package.py +++ b/var/spack/repos/builtin/packages/openblas/package.py @@ -1,6 +1,7 @@ from spack import * import sys import os +import shutil class Openblas(Package): """OpenBLAS: An optimized BLAS library""" @@ -64,6 +65,10 @@ class Openblas(Package): if '+shared' in spec: symlink('libopenblas.%s' % dso_suffix, 'liblapack.%s' % dso_suffix) + # Openblas may pass its own test but still fail to compile Lapack + # symbols. To make sure we get working Blas and Lapack, do a small test. + self.check_install(spec) + def setup_dependent_package(self, module, dspec): # This is WIP for a prototype interface for virtual packages. @@ -76,3 +81,53 @@ class Openblas(Package): if '+shared' in self.spec: self.spec.blas_shared_lib = join_path(libdir, 'libopenblas.%s' % dso_suffix) self.spec.lapack_shared_lib = self.spec.blas_shared_lib + + def check_install(self, spec): + "Build and run a small program to test that we have Lapack symbols" + print "Checking Openblas installation..." + checkdir = "spack-check" + with working_dir(checkdir, create=True): + source = r""" +#include <cblas.h> +#include <stdio.h> +int main(void) { +int i=0; +double A[6] = {1.0, 2.0, 1.0, -3.0, 4.0, -1.0}; +double B[6] = {1.0, 2.0, 1.0, -3.0, 4.0, -1.0}; +double C[9] = {.5, .5, .5, .5, .5, .5, .5, .5, .5}; +cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, + 3, 3, 2, 1, A, 3, B, 3, 2, C, 3); +for (i = 0; i < 8; i++) + printf("%lf ", C[i]); +printf("%lf", C[8]); +return 0; +} +""" + expected = """\ +11.000000 -9.000000 5.000000 -9.000000 21.000000 -1.000000 5.000000 -1.000000 3.000000\ +""" + with open("check.c", 'w') as f: + f.write(source) + cc = which('cc') + # TODO: Automate these path and library settings + cc('-c', "-I%s" % join_path(spec.prefix, "include"), "check.c") + cc('-o', "check", "check.o", + "-L%s" % join_path(spec.prefix, "lib"), "-llapack", "-lblas") + try: + check = Executable('./check') + output = check(return_output=True) + except: + output = "" + success = output == expected + if not success: + print "Produced output does not match expected output." + print "Expected output:" + print '-'*80 + print expected + print '-'*80 + print "Produced output:" + print '-'*80 + print output + print '-'*80 + raise RuntimeError("Openblas install check failed") + shutil.rmtree(checkdir) |