diff --git a/var/spack/repos/builtin/packages/openblas/package.py b/var/spack/repos/builtin/packages/openblas/package.py index 14f0395c4b..d147533491 100644 --- a/var/spack/repos/builtin/packages/openblas/package.py +++ b/var/spack/repos/builtin/packages/openblas/package.py @@ -94,48 +94,33 @@ def setup_dependent_package(self, module, dspec): 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" + # TODO: Pull this out to the framework function which recieves a pair of xyz.c and xyz.output print "Checking Openblas installation..." - checkdir = "spack-check" - with working_dir(checkdir, create=True): - source = r""" -#include -#include -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 < 9; i++) - printf("%f\n", C[i]); -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", "-lpthread") - try: - check = Executable('./check') - output = check(return_output=True) - except: - output = "" + source_file = join_path(os.path.dirname(self.module.__file__), + 'test_cblas_dgemm.c') + output_file = join_path(os.path.dirname(self.module.__file__), + 'test_cblas_dgemm.output') + + with open(output_file, 'r') as f: + expected = f.read() + + cc = which('cc') + cc('-c', "-I%s" % join_path(spec.prefix, "include"), source_file) + link_flags = ["-L%s" % join_path(spec.prefix, "lib"), + "-llapack", + "-lblas", + "-lpthread" + ] + if '+openmp' in spec: + link_flags.extend([self.compiler.openmp_flag]) + cc('-o', "check", "test_cblas_dgemm.o", + *link_flags) + + 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." @@ -148,4 +133,3 @@ def check_install(self, spec): print output print '-'*80 raise RuntimeError("Openblas install check failed") - shutil.rmtree(checkdir) diff --git a/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.c b/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.c index 634e99d20b..3813a23b69 100644 --- a/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.c +++ b/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.c @@ -1,13 +1,49 @@ #include #include -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 < 9; i++) - printf("%f\n", C[i]); -return 0; + +double m[] = { + 3, 1, 3, + 1, 5, 9, + 2, 6, 5 +}; + +double x[] = { + -1, 3, -3 +}; + +#ifdef __cplusplus +extern "C" { +#endif + + void dgesv_(int *n, int *nrhs, double *a, int *lda, + int *ipivot, double *b, int *ldb, int *info); + +#ifdef __cplusplus +} +#endif + +int main(void) { + int i; + // blas: + 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 < 9; i++) + printf("%f\n", C[i]); + + // lapack: + int ipiv[3]; + int j; + int info; + int n = 1; + int nrhs = 1; + int lda = 3; + int ldb = 3; + dgesv_(&n,&nrhs, &m[0], &lda, ipiv, &x[0], &ldb, &info); + for (i=0; i<3; ++i) + printf("%5.1f %3d\n", x[i], ipiv[i]); + + return 0; } diff --git a/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.output b/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.output index b8316d7477..9c235e314f 100644 --- a/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.output +++ b/var/spack/repos/builtin/packages/openblas/test_cblas_dgemm.output @@ -7,3 +7,6 @@ 5.000000 -1.000000 3.000000 + -0.3 1 + 3.0 1499101120 + -3.0 32767