Skip to content

Commit 5534ed0

Browse files
author
Jared Frazier
committed
fixed downstream project, problem with test_spblas.f90
Since module uses mkl_spblas.mod that is precompiled... a potential problem could be the fact that the .mod file is not compiled properly and is therefore leading to a seg fault when calling functions from `use mkl_spblas`.... the test_spblas.f90 DOES work when you just include mkl_spblas.f90 directly instead of going through the include directories...
1 parent 656d07a commit 5534ed0

File tree

7 files changed

+44
-32
lines changed

7 files changed

+44
-32
lines changed

cmake/HelloSPBLASConfig.cmake.in

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
@PACKAGE_INIT@
33

44
# from libiconmath
5-
# note test-drive/template.cmake and fftpack/config/CMakeLists.txt uses IF guard)
5+
# note test-drive/template.cmake and fftpack/install/CMakeLists.txt uses IF guard)
66
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
77

88
include(CMakeFindDependencyMacro)
9-
if(${ENABLE_FFTPACK})
9+
if(@ENABLE_FFTPACK@)
1010
find_dependency(fftpack REQUIRED)
1111
endif()
1212

13-
if(${ENABLE_PFUNIT})
13+
if(@ENABLE_PFUNIT@)
1414
find_dependency(PFUNIT REQUIRED)
1515
endif()
1616

17-
if (${ENABLE_TEST_DRIVE})
17+
if (@ENABLE_TEST_DRIVE@)
1818
find_dependency(test-drive REQUIRED)
1919
endif()
2020

21+
if (@ENABLE_FIND_INTEL_MKL@)
22+
find_dependency(MKL REQUIRED)
23+
endif()
24+
2125
include(FindPackageHandleStandardArgs)
2226
find_package_handle_standard_args(
2327
@PROJECT_NAME@ REQUIRED_VARS @PROJECT_NAME@_DIR

cmake/helper.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function(link_spblas targ)
2424
# Specify the MKL libraries for linking
2525
target_link_libraries(
2626
${targ}
27-
PRIVATE
27+
PUBLIC
2828
# must be static
2929
${MKLLIB}/libmkl_blas95_ilp64.a
3030

config/intel_ubuntu_spblas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cmake -S . -B build-spblas\
77
-DCMAKE_Fortran_COMPILER=ifx\
88
-DBUILD_TESTING=ON\
99
-DENABLE_SPBLAS=ON\
10-
-DENABLE_FIND_INTEL_MKL=ON
10+
-DENABLE_FIND_INTEL_MKL=OFF
1111
cmake --build build-spblas
1212
./build-spblas/test/test_spblas
1313
[[ -n $builddocs ]] && cmake --build build-spblas --target doxygen_docs

config/intel_ubuntu_test_drive

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ curdir=$(pwd)
66
[[ $curdir == *"config"* ]] && echo "must be in root project dir" && exit 1
77
#[[ -d build ]] && rm -rf build
88
cmake -S . -B build\
9+
-DCMAKE_Fortran_COMPILER=ifx\
910
-DBUILD_TESTING=ON\
10-
-DENABLE_SPBLAS=OFF\
11-
-DENABLE_PFUNIT=OFF\
1211
-DENABLE_TEST_DRIVE=ON\
13-
-DCMAKE_Fortran_COMPILER=ifx\
12+
-DENABLE_FFTPACK=ON\
13+
-DENABLE_SPBLAS=ON\
14+
-DENABLE_FIND_INTEL_MKL=OFF\
15+
-DENABLE_PFUNIT=OFF\
1416
-DCMAKE_INSTALL_PREFIX=build/installed
1517
cmake --build build
18+
cmake --build build --target install
1619
cd build
1720
# name from test/CMakeLists.txt build_tests(FIRST_ARG ...)
1821
ctest -R test_drive_square_tests

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
3030

3131
if(${ENABLE_FFTPACK})
3232
target_compile_definitions(${PROJECT_NAME} PRIVATE FFTPACK)
33-
target_link_libraries(${PROJECT_NAME} PRIVATE fftpack)
33+
target_link_libraries(${PROJECT_NAME} PUBLIC fftpack)
3434
endif()
3535

3636
if(${ENABLE_SPBLAS})

test/downstream_project/hello.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
! Use external library HelloSPBLAS
22
PROGRAM main
3-
USE mo_square, ONLY: square
3+
USE mo_square, ONLY: sum_cube_square
44
REAL :: x = 2
55
REAL :: y
66
PRINT *, "Hello, world!"
7-
y = square(x)
8-
PRINT *, "square(x) =", y
7+
y = sum_cube_square(x)
8+
PRINT *, y
99
END PROGRAM main

test/test_spblas.f90

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,33 @@
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"
19+
include "mkl_spblas.f90" ! TODO: remove this!
2020
PROGRAM TEST_SPBLAS
21+
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_FLOAT, C_INT, C_LONG
2122
USE mkl_spblas, ONLY: sparse_matrix_t, matrix_descr, &
2223
mkl_sparse_s_create_csr, mkl_sparse_s_create_coo, mkl_sparse_s_mv, &
2324
SPARSE_INDEX_BASE_ONE, SPARSE_MATRIX_TYPE_GENERAL, &
2425
SPARSE_OPERATION_NON_TRANSPOSE
2526

2627
IMPLICIT NONE
2728

28-
INTEGER, PARAMETER :: rows = 4
29-
INTEGER, PARAMETER :: cols = 6
29+
INTEGER(KIND=C_INT), PARAMETER :: rows = 4
30+
INTEGER(KIND=C_INT), PARAMETER :: cols = 6
3031

31-
INTEGER, PARAMETER :: nnz = 8
32+
INTEGER(KIND=C_INT), PARAMETER :: nnz = 8
3233

33-
INTEGER :: ia(rows+1), ja(nnz), stat
34-
REAL :: values(nnz), x(6), y(4), y_coo(4)
34+
!INTEGER(KIND=C_INT) :: ia(rows+1), ja(nnz)
35+
INTEGER(KIND=C_LONG) :: ia(rows+1), ja(nnz)
36+
INTEGER :: stat
37+
REAL(KIND=C_FLOAT) :: values(nnz), x(6), y(4), y_coo(4)
3538

3639
TYPE(sparse_matrix_t) :: a
3740
TYPE(matrix_descr) :: descr
3841

3942
TYPE(sparse_matrix_t) :: A_coo
4043

41-
INTEGER, ALLOCATABLE :: row_indx(:)
42-
INTEGER, ALLOCATABLE :: col_indx(:)
44+
INTEGER(KIND=C_INT), ALLOCATABLE :: row_indx(:)
45+
INTEGER(KIND=C_INT), ALLOCATABLE :: col_indx(:)
4346

4447
! Matrix example taken from:
4548
! https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_(CSR,_CRS_or_Yale_format)
@@ -49,6 +52,7 @@ PROGRAM TEST_SPBLAS
4952
! | 0 0 50 60 70 0 |
5053
! | 0 0 0 0 0 80 |
5154

55+
! create:
5256
! create csr
5357
ia = [1,3,5,8,9]
5458
ja = [1,2,2,4,3,4,5,6]
@@ -60,23 +64,24 @@ PROGRAM TEST_SPBLAS
6064
print *, "stat create = ", stat
6165
descr%type = SPARSE_MATRIX_TYPE_GENERAL
6266

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

70-
! spmv csr
74+
! spmv:
7175
x = [1,1,1,1,1,1]
76+
! spmv csr
7277
stat = mkl_sparse_s_mv(SPARSE_OPERATION_NON_TRANSPOSE,1.0,a,descr,x,0.0,y)
7378
print *, "stat mv = ", stat
7479
print *, "result csr = ", y
7580
print *, "expected = ", [30., 70., 180., 80.]
7681

77-
! spmv coo
78-
stat = mkl_sparse_s_mv(&
79-
SPARSE_OPERATION_NON_TRANSPOSE, 1.0, A_coo, descr, x, 0.0, y_coo)
80-
print *, "result coo = ", y_coo
82+
!! spmv coo
83+
!stat = mkl_sparse_d_mv(&
84+
!SPARSE_OPERATION_NON_TRANSPOSE, 1.0, A_coo, descr, x, 0.0, y_coo)
85+
!print *, "result coo = ", y_coo
8186

8287
END PROGRAM TEST_SPBLAS

0 commit comments

Comments
 (0)