From bb3a4ad69f2f826d89b7222186e60dbaa9a47efa Mon Sep 17 00:00:00 2001 From: Miro ILIAS Date: Sun, 12 Jul 2015 22:16:31 +0200 Subject: [PATCH] new test fc_openblas added (works on Linux only) --- .travis.yml | 2 +- test/fc_openblas/cmake/autocmake.cfg | 32 +++++++++++++++++++ test/fc_openblas/src/CMakeLists.txt | 6 ++++ test/fc_openblas/src/example.f90 | 47 ++++++++++++++++++++++++++++ test/test.py | 8 +++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 test/fc_openblas/cmake/autocmake.cfg create mode 100644 test/fc_openblas/src/CMakeLists.txt create mode 100644 test/fc_openblas/src/example.f90 diff --git a/.travis.yml b/.travis.yml index a10d796..741ffff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: cpp install: - - sudo apt-get install g++ cmake gfortran + - sudo apt-get install g++ cmake gfortran libopenblas-base libopenblas-dev - sudo pip install pytest pep8 script: - pep8 --ignore=E501 update.py diff --git a/test/fc_openblas/cmake/autocmake.cfg b/test/fc_openblas/cmake/autocmake.cfg new file mode 100644 index 0000000..917703e --- /dev/null +++ b/test/fc_openblas/cmake/autocmake.cfg @@ -0,0 +1,32 @@ +[project] +name: example + +[fc] +source: ../../../modules/fc.cmake +docopt: --fc= Fortran compiler [default: gfortran]. + --extra-fc-flags= Extra Fortran compiler flags [default: '']. +export: 'FC=%s' % arguments['--fc'] +define: '-DEXTRA_FCFLAGS="%s"' % arguments['--extra-fc-flags'] + +[int64] +source: ../../../modules/int64.cmake +docopt: --int64 Enable 64bit integers [default: False]. +define: '-DENABLE_64BIT_INTEGERS=%s' % arguments['--int64'] + +[math_libs] +source: ../../../modules/math_libs.cmake +docopt: --blas= Detect and link BLAS library (auto or off) [default: auto]. + --lapack= Detect and link LAPACK library (auto or off) [default: auto]. + --mkl= Pass MKL flag to the Intel compiler and linker and skip BLAS/LAPACK detection (sequential, parallel, cluster, or off) [default: off]. +define: '-DENABLE_BLAS=%s' % arguments['--blas'] + '-DENABLE_LAPACK=%s' % arguments['--lapack'] + '-DMKL_FLAG=%s' % arguments['--mkl'] + '-DMATH_LIB_SEARCH_ORDER="MKL;ESSL;ATLAS;ACML;SYSTEM_NATIVE"' + '-DBLAS_LANG=Fortran' + '-DLAPACK_LANG=Fortran' + +[default_build_paths] +source: ../../../modules/default_build_paths.cmake + +[src] +source: ../../../modules/src.cmake diff --git a/test/fc_openblas/src/CMakeLists.txt b/test/fc_openblas/src/CMakeLists.txt new file mode 100644 index 0000000..7172fe7 --- /dev/null +++ b/test/fc_openblas/src/CMakeLists.txt @@ -0,0 +1,6 @@ +if (BLAS_FOUND) + add_executable(example example.f90) + target_link_libraries(example blas) +else() + message(FATAL_ERROR "OpenBLAS library not found for the test fc_openblas !") +endif() diff --git a/test/fc_openblas/src/example.f90 b/test/fc_openblas/src/example.f90 new file mode 100644 index 0000000..e0eb32b --- /dev/null +++ b/test/fc_openblas/src/example.f90 @@ -0,0 +1,47 @@ +program example + implicit none + call dgemm_test + print *,'dgemm_test done' +end program + +subroutine dgemm_test + implicit none + integer :: i,j,k,AllocateStatus + integer :: n=10 + real*8, allocatable :: A(:,:),B(:,:),C(:,:) + real*8 :: diag, offdiag, asde,asode + + allocate (A(n,n),B(n,n),C(n,n),STAT=AllocateStatus) + if (AllocateStatus.ne.0) then + stop "error in main matrix allocations !" + endif + + ! fill matrixes A,B,C + do i=1,n + do j=1,n + if (i.eq.j) then ! A is unit matrix + A(i,j)=1.0d0 + else + A(i,j)=0.0d0 + endif + B(i,j)=dfloat(i+j) ! B is symmetric matrix + C(i,j)=0.0d0 + enddo + enddo + call dgemm('n','n',n,n,n,1.0d0,A,n,B,n,-2.0d0,C,n) + ! check the resulting C matrix + diag=0.0d0;offdiag=0.0d0 + do i=1,n + do j=1,n + if (i.eq.j) then + diag = diag + C(i,j) + else + offdiag = offdiag + C(i,j) + endif + enddo + enddo + + asde=diag/dfloat(n); asode=offdiag/(dfloat(n*n)-dfloat(n)) + +end subroutine dgemm_test + diff --git a/test/test.py b/test/test.py index ad4f434..5947e87 100644 --- a/test/test.py +++ b/test/test.py @@ -117,3 +117,11 @@ def test_cxx(): def test_fc(): stdout, stderr = boilerplate('fc', 'python setup.py --fc=gfortran') assert 'Hello World!' in stdout + +# ------------------------------------------------------------------------------ + + +def test_fc_openblas(): + if sys.platform != 'win32': + stdout, stderr = boilerplate('fc_openblas', 'python setup.py --fc=gfortran --blas=auto') + assert 'dgemm_test done'