Skip to content

Commit a0e1221

Browse files
committed
fixed spblas and added some flags for enabling fftpack (and preprocess)
1 parent e7fc1a3 commit a0e1221

13 files changed

+87
-185
lines changed

CMakeLists.txt

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
cmake_minimum_required(VERSION 3.15)
22

33
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
4-
54
option(BUILD_TESTING "Build tests" OFF)
5+
66
option(ENABLE_SPBLAS "Build with SPBLAS" ON)
7-
option(PFUNIT "ON - using pFUnit for unit tests, OFF - skip building pfunit tests" OFF)
8-
option(TEST_DRIVE "ON - Using test-drive for unittests, OFF - skip building test-drive tests" OFF)
7+
8+
option(ENABLE_FFTPACK "Build with fftpack" OFF)
9+
option(ENABLE_PFUNIT "Build with pFUnit" OFF)
10+
option(ENABLE_TEST_DRIVE "Build with test-drive" OFF)
911

1012

1113
project(
@@ -16,60 +18,24 @@ project(
1618
)
1719

1820
# Set paths to Intel oneAPI MKL
19-
# TODO: something wrong with spblas call??
2021
if(${ENABLE_SPBLAS})
2122
set(MKLROOT $ENV{MKLROOT}) # Assuming MKLROOT is already set in the environment
2223
if (NOT MKLROOT)
2324
message(FATAL_ERROR "MKLROOT environment variable is not set.")
2425
endif()
2526
set(MKLLIB ${MKLROOT}/lib CACHE PATH "Path to Intel MKL Libraries")
2627
set(MKLINCLUDE ${MKLROOT}/include CACHE PATH "Path to Intel MKL include files")
27-
28-
add_executable(
29-
test_root_spblas
30-
test_root_spblas.f90
31-
)
32-
33-
# Add include directories
34-
target_include_directories(
35-
test_root_spblas
36-
PRIVATE ${MKLINCLUDE}
37-
)
38-
39-
# Specify the MKL libraries for linking
40-
target_link_libraries(
41-
test_root_spblas
42-
PRIVATE
43-
# must be static
44-
${MKLLIB}/libmkl_blas95_ilp64.a
45-
46-
# must shared
47-
${MKLLIB}/libmkl_intel_ilp64.so
48-
${MKLLIB}/libmkl_sequential.so # or libmkl_intel_thread.so
49-
${MKLLIB}/libmkl_core.so
50-
51-
# standard shared libs
52-
pthread
53-
m
54-
dl
55-
)
56-
57-
target_compile_options(
58-
test_root_spblas
59-
PRIVATE
60-
-i8 # required, otherwise segfaults
61-
)
6228
endif()
6329

6430
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
6531

6632
# build externals with specified version corresponding to git tag
67-
#include(FetchContent)
68-
#message(STATUS "Build extern")
69-
#set(fftpack_GIT_TAG main)
70-
#set(pFUnit_GIT_TAG cf37fb694f7c015d3718c1b4f7f3e9a56613067a) # fixes fetch content
71-
#set(test-drive_GIT_TAG main)
72-
#add_subdirectory(extern)
33+
include(FetchContent)
34+
message(STATUS "Build extern")
35+
set(fftpack_GIT_TAG main)
36+
set(pFUnit_GIT_TAG cf37fb694f7c015d3718c1b4f7f3e9a56613067a) # fixes fetch content
37+
set(test-drive_GIT_TAG main)
38+
add_subdirectory(extern)
7339

7440
message(STATUS "Build src")
7541
include(GNUInstallDirs)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Demonstrate sparse matrix-vector multiplication with Intel MKL. Also has
44
various cmake structural components that are intended to be for generic
55
projects.
66

7-
Use either `pFUnit` or `test-drive` for unit testing.
7+
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).
1010

cmake/HelloSPBLASConfig.cmake.in

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
77

88
include(CMakeFindDependencyMacro)
9-
find_dependency(fftpack REQUIRED)
9+
if(${ENABLE_FFTPACK})
10+
find_dependency(fftpack REQUIRED)
11+
endif()
1012

11-
if(${PFUNIT})
13+
if(${ENABLE_PFUNIT})
1214
find_dependency(PFUNIT REQUIRED)
1315
endif()
1416

15-
if (${TEST_DRIVE})
17+
if (${ENABLE_TEST_DRIVE})
1618
find_dependency(test-drive REQUIRED)
1719
endif()
1820

config/intel_levante_pfunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cmake -S . -B build \
88
-DCMAKE_Fortran_COMPILER=mpiifort \
99
-DMKLLIB=/sw/spack-levante/intel-oneapi-mkl-2022.0.1-ttdktf/mkl/2022.0.1/lib/intel64/\
1010
-DCMAKE_INSTALL_PREFIX=build/installed\
11-
-DPFUNIT=ON
11+
-DENABLE_PFUNIT=ON
1212

1313
cmake --build build
1414
cd build

config/intel_ubuntu_pfunit

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ curdir=$(pwd)
55
[[ $curdir == *"config"* ]] && echo "must be in root project dir" && exit 1
66
cmake -S . -B build\
77
-DBUILD_TESTING=ON\
8-
-DCMAKE_Fortran_COMPILER=mpiifx -DCMAKE_INSTALL_PREFIX=build/installed\
9-
-DPFUNIT=ON
8+
-DENABLE_PFUNIT=ON\
9+
-DENABLE_SPBLAS=ON\
10+
-DENABLE_TEST_DRIVE=OFF\
11+
-DCMAKE_Fortran_COMPILER=mpiifx\
12+
-DCMAKE_INSTALL_PREFIX=build/installed
1013
cmake --build build
1114
cd build
1215
ctest -L myproject
16+
./build/test/test_spblas
1317
)

config/intel_ubuntu_spblas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/bash
2+
[[ -d build-spblas ]] && rm -rf build-spblas
23
cmake -S . -B build-spblas -DCMAKE_Fortran_COMPILER=ifx -DBUILD_TESTING=ON
34
cmake --build build-spblas
45
./build-spblas/test/test_spblas
5-
./build-spblas/test_root_spblas

config/intel_ubuntu_test_drive

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ curdir=$(pwd)
66
#[[ -d build ]] && rm -rf build
77
cmake -S . -B build\
88
-DBUILD_TESTING=ON\
9-
-DCMAKE_Fortran_COMPILER=ifx -DPFUNIT=OFF -DTEST_DRIVE=ON\
9+
-DENABLE_SPBLAS=ON\
10+
-DENABLE_PFUNIT=OFF\
11+
-DENABLE_TEST_DRIVE=ON\
12+
-DCMAKE_Fortran_COMPILER=ifx\
1013
-DCMAKE_INSTALL_PREFIX=build/installed
1114
cmake --build build
1215
cd build
1316
# name from test/CMakeLists.txt build_tests(FIRST_ARG ...)
1417
ctest -R test_drive_square_tests
15-
./test/test_spblas
18+
./build/test/test_spblas
1619
# build docs
1720
#cmake --build . --target doxygen_docs
1821
)

extern/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# from dynamics
22
# Get FFTPACK
3-
message(STATUS "Building fftpack")
4-
add_subdirectory(fftpack)
3+
if(${ENABLE_FFTPACK})
4+
message(STATUS "Building fftpack")
5+
add_subdirectory(fftpack)
6+
endif()
57

68
# Get test drive
7-
if (${TEST_DRIVE})
9+
if (${ENABLE_TEST_DRIVE})
810
message(STATUS "Building test-drive")
911
add_subdirectory(test-drive)
1012
set(test-drive_LIBRARY ${test-drive_LIBRARY} PARENT_SCOPE)
1113
set(test-drive_INCLUDE_DIR ${test-drive_INCLUDE_DIR} PARENT_SCOPE)
1214
endif()
1315

1416
# Get pfunit
15-
if (${PFUNIT})
17+
if(${ENABLE_PFUNIT})
1618
message(STATUS "Building pFUnit")
1719
add_subdirectory(pFUnit)
1820
endif()

src/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(${PROJECT_NAME} ${HelloSPBLAS_SOURCES})
1717
set_target_properties(
1818
${PROJECT_NAME}
1919
PROPERTIES
20+
Fortran_PREPROCESS ON
2021
POSITION_INDEPENDENT_CODE ON
2122
VERSION ${PROJECT_VERSION}
2223
Fortran_MODULE_DIRECTORY ${Fortran_MODULE_DIRECTORY}
@@ -27,8 +28,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC
2728
)
2829

2930
# Could use cmake/helpers.cmake::link_libraries but fftpack include dir is not needed
30-
# TODO:
31-
#target_link_libraries(${PROJECT_NAME} fftpack)
31+
if(${ENABLE_FFTPACK})
32+
target_compile_definitions(${PROJECT_NAME} PRIVATE __FFTPACK)
33+
target_link_libraries(${PROJECT_NAME} fftpack)
34+
endif()
3235

3336
# installation/configuration steps (modified from fotran-lang/stdlib)
3437
install(

src/mo_square.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
!!
66

77
MODULE mo_square
8-
!USE fftpack
8+
#ifdef __FFTPACK
9+
USE fftpack
10+
#endif
911
IMPLICIT NONE
1012

1113
CONTAINS

test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ if(${ENABLE_SPBLAS})
4444
m
4545
dl
4646
)
47+
48+
target_compile_options(
49+
test_spblas
50+
PRIVATE
51+
-i8 # required, otherwise segfaults
52+
)
4753
endif()
4854

4955
# Add pfunit tests

test/test_spblas.f90

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,65 @@
1818
! solved... could use that also as a reference.
1919
INCLUDE "mkl_spblas.f90"
2020
PROGRAM TEST_SPBLAS
21-
USE mkl_spblas
22-
!ONLY: sparse_matrix_t, matrix_descr, &
23-
!mkl_sparse_s_create_csr, mkl_sparse_s_create_coo, mkl_sparse_s_mv, &
24-
!SPARSE_INDEX_BASE_ONE, SPARSE_MATRIX_TYPE_GENERAL, &
25-
!SPARSE_OPERATION_NON_TRANSPOSE
26-
21+
USE mkl_spblas, ONLY: sparse_matrix_t, matrix_descr, &
22+
mkl_sparse_s_create_csr, mkl_sparse_s_create_coo, mkl_sparse_s_mv, &
23+
SPARSE_INDEX_BASE_ONE, SPARSE_MATRIX_TYPE_GENERAL, &
24+
SPARSE_OPERATION_NON_TRANSPOSE
25+
2726
IMPLICIT NONE
2827

2928
INTEGER, PARAMETER :: rows = 4
3029
INTEGER, PARAMETER :: cols = 6
3130

3231
INTEGER, PARAMETER :: nnz = 8
3332

34-
INTEGER :: ia(rows + 1), ja(nnz), stat
33+
INTEGER :: ia(rows+1), ja(nnz), stat
3534
REAL :: values(nnz), x(6), y(4), y_coo(4)
3635

3736
TYPE(sparse_matrix_t) :: a
3837
TYPE(matrix_descr) :: descr
3938

4039
TYPE(sparse_matrix_t) :: A_coo
4140

42-
INTEGER, ALLOCATABLE :: row_indx(:)
43-
INTEGER, ALLOCATABLE :: col_indx(:)
41+
INTEGER, ALLOCATABLE :: row_indx(:)
42+
INTEGER, ALLOCATABLE :: col_indx(:)
4443

45-
! Matrix example taken from:
44+
! Matrix example taken from:
4645
! https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_(CSR,_CRS_or_Yale_format)
4746
!
4847
! | 10 20 0 0 0 0 |
4948
! A = | 0 30 0 40 0 0 |
5049
! | 0 0 50 60 70 0 |
51-
! | 0 0 0 0 0 80 |
52-
53-
x = [1, 1, 1, 1, 1, 1] ! for spmv
54-
values = [10, 20, 30, 40, 50, 60, 70, 80] ! for matrix values
50+
! | 0 0 0 0 0 80 |
5551

56-
!! create csr
57-
ia = [1, 3, 5, 8, 9]
58-
ja = [1, 2, 2, 4, 3, 4, 5, 6]
52+
! create csr
53+
ia = [1,3,5,8,9]
54+
ja = [1,2,2,4,3,4,5,6]
55+
values = [10, 20, 30, 40, 50, 60, 70, 80]
5956

6057
stat = mkl_sparse_s_create_csr(&
61-
a, SPARSE_INDEX_BASE_ONE, rows, cols, ia(1:4), ia(2:5), ja, values)
62-
63-
!PRINT *, "stat create = ", stat
64-
descr%TYPE = SPARSE_MATRIX_TYPE_GENERAL
58+
a,SPARSE_INDEX_BASE_ONE,rows,cols,ia(1:4),ia(2:5),ja,values)
6559

60+
print *, "stat create = ", stat
61+
descr%type = SPARSE_MATRIX_TYPE_GENERAL
62+
6663
! create coo
67-
!row_indx = [1, 1, 2, 2, 3, 3, 3, 4]
68-
!col_indx = [1, 2, 2, 4, 3, 4, 5, 6]
69-
!stat = mkl_sparse_s_create_coo(A_coo, SPARSE_INDEX_BASE_ONE, rows, cols, nnz, row_indx, col_indx, values)
70-
71-
!PRINT *, "stat create = ", stat
72-
!descr%TYPE = SPARSE_MATRIX_TYPE_GENERAL
73-
!PRINT *, "descr%TYPE", descr%TYPE
74-
75-
! spmv csr
76-
!stat = mkl_sparse_s_mv(SPARSE_OPERATION_NON_TRANSPOSE, 1.0, a, descr, x, 0.0, y)
77-
!PRINT *, "stat mv = ", stat
78-
!PRINT *, "result csr = ", y
79-
!PRINT *, "expected = ", [30., 70., 180., 80.]
80-
81-
!! spmv coo
82-
!stat = mkl_sparse_s_mv( &
83-
!SPARSE_OPERATION_NON_TRANSPOSE, 1.0, A_coo, descr, x, 0.0, y_coo)
84-
!PRINT *, "result coo = ", y_coo
85-
86-
END PROGRAM TEST_SPBLAS
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)
69+
70+
! spmv csr
71+
x = [1,1,1,1,1,1]
72+
stat = mkl_sparse_s_mv(SPARSE_OPERATION_NON_TRANSPOSE,1.0,a,descr,x,0.0,y)
73+
print *, "stat mv = ", stat
74+
print *, "result csr = ", y
75+
print *, "expected = ", [30., 70., 180., 80.]
76+
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
81+
82+
END PROGRAM TEST_SPBLAS

0 commit comments

Comments
 (0)