Skip to content

Commit 5a063d4

Browse files
author
Jared Frazier
committed
better doc by wrapping @cond on include mkl spblas, private find_package(MKL) compile options fixes build fail for test-drive
1 parent 6885a65 commit 5a063d4

7 files changed

+37
-63
lines changed

CMakeLists.txt

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ project(
2020
# Set paths to Intel oneAPI MKL
2121
if(${ENABLE_SPBLAS})
2222
if (${ENABLE_FIND_INTEL_MKL})
23-
find_package(MKL CONFIG)
24-
get_target_property(MKLINCLUDE MKL::MKL INTERFACE_INCLUDE_DIRECTORIES)
23+
#find_package(MKL CONFIG)
24+
find_package(MKL REQUIRED)
25+
#get_target_property(MKLINCLUDE MKL::MKL INTERFACE_INCLUDE_DIRECTORIES)
2526
endif()
2627

2728
# manually set MKL vars
@@ -36,33 +37,6 @@ if(${ENABLE_SPBLAS})
3637
else()
3738
message(STATUS "Found MKL")
3839
endif()
39-
40-
if(NOT EXISTS "${MKLINCLUDE}/mkl_spblas.mod")
41-
set(NO_MKL_SPBLAS_MOD "
42-
=======================================================================
43-
${MKLINCLUDE} does not contain mkl_spblas.mod
44-
If you installed Intel MKL to a directory
45-
that requires root permissions,
46-
(e.g., /opt/intel/oneapi/mkl/latest/)
47-
```
48-
# alternatively... you could update secure path in sudo visudo
49-
sudo -i
50-
echo 'source /opt/intel/oneapi/setvars.sh > /dev/null' >> ~/.bashrc
51-
source ~/.bashrc
52-
your_mkl_include=/opt/intel/oneapi/mkl/latest/include
53-
ifx -c your_mkl_include/mkl_spblas.f90
54-
```
55-
otherwise if you installed to a directory
56-
that does not require root permissions, it
57-
should be sufficient to call
58-
```
59-
cd /your/mkl/include # replace with your local path
60-
ifx -c mkl_spblas.f90
61-
```
62-
=======================================================================
63-
")
64-
message(FATAL_ERROR "${NO_MKL_SPBLAS_MOD}")
65-
endif()
6640
endif()
6741

6842
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ projects.
77
Can easily use `pFUnit` or `test-drive` for unit testing.
88

99
Make sure you have the [Intel oneAPI HPC Toolkit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html?packages=hpc-toolkit&hpc-toolkit-os=linux&hpc-toolkit-lin=apt) or [Intel Fortran Essentials](https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html?packages=fortran-essentials&fortran-essentials-os=linux&fortran-essentials-lin=apt).
10-
11-
Make sure also that in your `${MKLROOT}/include` directory there is a file
12-
called `mkl_spblas.mod`. The most up to date version of Intel MKL does not
13-
ship with `mkl_spblas.mod` by default, so you have to compile it separately
14-
via `ifx -c /path/to/mkl_spblas.f90`.
1510

1611
Then, you can configure, build, and run tests for the project.
1712

1813
```shell
1914
# test-drive builds faster than pfunit
20-
./config/intel_ubuntu_test_drive
15+
./config/intel_ubuntu_test_drive_fftpack_spblas
2116
```
2217

2318
Alternatively, if on a system where you need to specify a different MKL library

cmake/helper.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
function(link_spblas targ)
99
if (MKL_FOUND)
1010
# https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-macos/2023-0/cmake-config-for-onemkl.html
11-
target_compile_options(
12-
${targ} PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS>)
1311
target_include_directories(
1412
${targ} PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
1513
target_link_libraries(
1614
${targ} PUBLIC $<LINK_ONLY:MKL::MKL>)
15+
16+
# NOTE: If these are PUBLIC, it means(?) the unit tests inherit these
17+
# options and this leads to an error where `CALL check` is unrecognized...
18+
target_compile_options(
19+
${targ} PRIVATE $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS>)
1720
else()
1821
# Add include directories
1922
target_include_directories(
@@ -107,7 +110,7 @@ endfunction()
107110

108111
# Links the supplied library
109112
function(link_library targ lib include_dir)
110-
target_link_libraries(${targ} ${lib})
113+
target_link_libraries(${targ} PUBLIC ${lib})
111114
target_include_directories(${targ} PUBLIC $<BUILD_INTERFACE:${include_dir}>)
112115
endfunction()
113116

config/intel_ubuntu_test_drive renamed to config/intel_ubuntu_test_drive_fftpack_spblas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/bash
22
# @brief Baseline configuration assuming standard oneapi installation via apt.
33
builddocs=$1
4+
DEFAULT_FIND_INTEL_MKL="ON"
5+
FIND_INTEL_MKL="${FIND_INTEL_MKL:-$DEFAULT_FIND_INTEL_MKL}"
46
(
57
curdir=$(pwd)
68
[[ $curdir == *"config"* ]] && echo "must be in root project dir" && exit 1
@@ -11,15 +13,15 @@ cmake -S . -B build\
1113
-DENABLE_TEST_DRIVE=ON\
1214
-DENABLE_FFTPACK=ON\
1315
-DENABLE_SPBLAS=ON\
14-
-DENABLE_FIND_INTEL_MKL=OFF\
16+
-DENABLE_FIND_INTEL_MKL=${FIND_INTEL_MKL}\
1517
-DENABLE_PFUNIT=OFF\
1618
-DCMAKE_INSTALL_PREFIX=build/installed
1719
cmake --build build
1820
cmake --build build --target install
1921
cd build
2022
# name from test/CMakeLists.txt build_tests(FIRST_ARG ...)
2123
ctest -R test_drive_square_tests
22-
# test/test_spblas
24+
test/test_spblas
2325
# build docs
2426
[[ -n $builddocs ]] && cmake --build . --target doxygen_docs
2527
)

src/mo_square.f90

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
!> @file mo_square.f90
2-
!! @brief Defines a module of simple mathematical operations.
3-
4-
!! \cond
1+
! Prevents doxygen from documenting the included module
2+
!! @cond
53
#ifdef INTEL_SPBLAS
64
INCLUDE "mkl_spblas.f90"
75
#endif
8-
!! \endcond
6+
!! @endcond
97

8+
!> Defines a module of simple mathematical operations.
109
MODULE mo_square
1110

1211
#ifdef FFTPACK
@@ -22,6 +21,7 @@ MODULE mo_square
2221
PRIVATE
2322

2423
PUBLIC :: sum_cube_square
24+
PUBLIC :: square
2525

2626
CONTAINS
2727

@@ -35,7 +35,6 @@ END FUNCTION square
3535

3636
!> @brief Computes the cube of a real number.
3737
PURE REAL FUNCTION cube(x) result(r)
38-
! An undocumented function
3938
REAL, INTENT(in) :: x
4039
r = x**3
4140
END FUNCTION cube

test/test_spblas.f90

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616
!
1717
! In the MKL Cookbook (cookbook_index.htm) many different example problems are
1818
! solved... could use that also as a reference.
19-
include "mkl_spblas.f90" ! TODO: remove this!
19+
!! @cond
20+
include "mkl_spblas.f90"
21+
!! @endcond
2022
PROGRAM TEST_SPBLAS
21-
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_FLOAT, C_INT, C_LONG, C_DOUBLE
23+
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_FLOAT, C_LONG, C_INT, C_DOUBLE
2224
USE MKL_SPBLAS
2325

2426
IMPLICIT NONE
2527

26-
INTEGER(KIND=C_INT), PARAMETER :: rows = 4
27-
INTEGER(KIND=C_INT), PARAMETER :: cols = 6
28+
INTEGER(KIND=C_LONG), PARAMETER :: rows = 4
29+
INTEGER(KIND=C_LONG), PARAMETER :: cols = 6
2830

29-
INTEGER(KIND=C_INT), PARAMETER :: nnz = 8
31+
INTEGER(KIND=C_LONG), PARAMETER :: nnz = 8
3032

31-
!INTEGER(KIND=C_INT) :: ia(rows+1), ja(nnz) ! include->segfault,w/o include->type err
3233
INTEGER(KIND=C_LONG) :: ia(rows+1), ja(nnz) ! works with include 'mkl_spblas.f90'
3334
INTEGER :: stat
3435
REAL(KIND=C_DOUBLE) :: values(nnz), x(6), y(4), y_coo(4), alpha, beta
@@ -38,8 +39,8 @@ PROGRAM TEST_SPBLAS
3839

3940
TYPE(SPARSE_MATRIX_T) :: A_coo
4041

41-
INTEGER(KIND=C_INT), ALLOCATABLE :: row_indx(:)
42-
INTEGER(KIND=C_INT), ALLOCATABLE :: col_indx(:)
42+
INTEGER(KIND=C_LONG), ALLOCATABLE :: row_indx(:)
43+
INTEGER(KIND=C_LONG), ALLOCATABLE :: col_indx(:)
4344

4445
! Matrix example taken from:
4546
! https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_(CSR,_CRS_or_Yale_format)
@@ -62,11 +63,11 @@ PROGRAM TEST_SPBLAS
6263
descr%type = SPARSE_MATRIX_TYPE_GENERAL
6364

6465
!! create coo
65-
!row_indx = [1, 1, 2, 2, 3, 3, 3, 4]
66-
!col_indx = [1, 2, 2, 4, 3, 4, 5, 6]
67-
!stat = mkl_sparse_d_create_coo(&
68-
!A_coo, SPARSE_INDEX_BASE_ONE, rows, cols, nnz, row_indx, col_indx,&
69-
!values)
66+
row_indx = [1, 1, 2, 2, 3, 3, 3, 4]
67+
col_indx = [1, 2, 2, 4, 3, 4, 5, 6]
68+
stat = mkl_sparse_d_create_coo(&
69+
A_coo, SPARSE_INDEX_BASE_ONE, rows, cols, nnz, row_indx, col_indx,&
70+
values)
7071

7172
! spmv:
7273
x = [1,1,1,1,1,1]
@@ -79,8 +80,8 @@ PROGRAM TEST_SPBLAS
7980
print *, "expected = ", [30., 70., 180., 80.]
8081

8182
!! spmv coo
82-
!stat = mkl_sparse_d_mv(&
83-
!SPARSE_OPERATION_NON_TRANSPOSE, alpha, A_coo, descr, x, beta, y_coo)
84-
!print *, "result coo = ", y_coo
83+
stat = mkl_sparse_d_mv(&
84+
SPARSE_OPERATION_NON_TRANSPOSE, alpha, A_coo, descr, x, beta, y_coo)
85+
print *, "result coo = ", y_coo
8586

8687
END PROGRAM TEST_SPBLAS

test/test_square_with_test_drive.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! Example module that includes mo_square and performs a dummy unit test
22
MODULE test_square_with_test_drive
33

4-
use mo_square
4+
USE mo_square
55
USE testdrive, ONLY: new_unittest, unittest_type, error_type, check
66
IMPLICIT NONE
77
PRIVATE

0 commit comments

Comments
 (0)