Skip to content

Commit

Permalink
Replace Numerial Recipes LU-decomp routines with LAPACK ones
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRichert-NOAA committed Jan 31, 2024
1 parent 13d948f commit c472d3c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:

- name: build
run: |
sudo apt install libopenblas-dev
cd ip
mkdir build
cd build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/MacOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:

- name: build
run: |
brew install openblas
cd ip
mkdir build
cd build
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/Spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:

- name: spack-build-and-test
run: |
sudo apt install libopenblas-dev
git clone -c feature.manyFiles=true https://github.com/spack/spack
. spack/share/spack/setup-env.sh
spack env create ip-env
Expand All @@ -42,7 +43,7 @@ jobs:
spack add ip@develop%gcc@11 ${{ matrix.variants }} target=x86_64
precision=$(echo ${{ matrix.variants }} | grep -oP " precision=\K[4d8]")
if [ "$precision" == "d" ]; then spack add grib-util@develop ; fi
spack external find cmake gmake
spack external find cmake gmake openblas
spack concretize
# Run installation and run CTest suite
spack install --verbose --fail-fast --test root
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install doxygen
sudo apt-get install doxygen libopenblas-dev
python3 -m pip install gcovr
- name: checkout
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ endif()
if(OPENMP)
find_package(OpenMP REQUIRED COMPONENTS Fortran)
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
set(BLA_VENDOR Intel10_64lp)
endif()
find_package(LAPACK)

# Set compiler flags.
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|IntelLLVM)$")
Expand Down
1 change: 1 addition & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Ip(CMakePackage):
depends_on("sp precision=4", when="@4.1:4 precision=4")
depends_on("sp precision=d", when="@4.1:4 precision=d")
depends_on("sp precision=8", when="@4.1:4 precision=8")
depends_on("lapack", when="@develop")

def cmake_args(self):
args = [
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ foreach(kind ${kinds})
if(OpenMP_Fortran_FOUND)
target_link_libraries(${lib_name} PUBLIC OpenMP::OpenMP_Fortran)
endif()
target_link_libraries(${lib_name} PUBLIC LAPACK::LAPACK)

list(APPEND LIB_TARGETS ${lib_name})

Expand Down
22 changes: 17 additions & 5 deletions src/splat.F
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SUBROUTINE SPLAT(IDRT,JMAX,SLAT,WLAT)
$ 146.870307625, 150.011882457, 153.153458019, 156.295034268 /
REAL:: DLT,D1=1.
REAL AWORK((JMAX+1)/2,((JMAX+1)/2)),BWORK(((JMAX+1)/2))
INTEGER:: JHE,JHO,J0=0
INTEGER:: JHE,JHO,J0=0, INFO
INTEGER IPVT((JMAX+1)/2)
PARAMETER(PI=3.14159265358979,C=(1.-(2./PI)**2)*0.25)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -133,8 +133,14 @@ SUBROUTINE SPLAT(IDRT,JMAX,SLAT,WLAT)
BWORK(JS)=-D1/(4*(JS-1)**2-1)
ENDDO

call ludcmp(awork,jho,jhe,ipvt)
call lubksb(awork,jho,jhe,ipvt,bwork)
! Call LAPACK routines
#if (LSIZE==4)
CALL SGETRF(JHO, JHO, AWORK, JHE, IPVT, INFO)
CALL SGETRS('N', JHO, 1, AWORK, JHE, IPVT, BWORK, JHO, INFO)
#else
CALL DGETRF(JHO, JHO, AWORK, JHE, IPVT, INFO)
CALL DGETRS('N', JHO, 1, AWORK, JHE, IPVT, BWORK, JHO, INFO)
#endif

WLAT(1)=0.
DO J=1,JHO
Expand Down Expand Up @@ -170,8 +176,14 @@ SUBROUTINE SPLAT(IDRT,JMAX,SLAT,WLAT)
BWORK(JS)=-D1/(4*(JS-1)**2-1)
ENDDO

call ludcmp(awork,jho,jhe,ipvt,d)
call lubksb(awork,jho,jhe,ipvt,bwork)
! Call LAPACK routines
#if (LSIZE==4)
CALL SGETRF(JHO, JHO, AWORK, JHE, IPVT, INFO)
CALL SGETRS('N', JHO, 1, AWORK, JHE, IPVT, BWORK, JHO, INFO)
#else
CALL DGETRF(JHO, JHO, AWORK, JHE, IPVT, INFO)
CALL DGETRS('N', JHO, 1, AWORK, JHE, IPVT, BWORK, JHO, INFO)
#endif

WLAT(1)=0.
DO J=1,JHO
Expand Down

0 comments on commit c472d3c

Please sign in to comment.