fpm icon indicating copy to clipboard operation
fpm copied to clipboard

Preprocess macros not work when building via `fpm build` or `fpm run`

Open LaplaceSoda opened this issue 9 months ago • 1 comments

Description

If we create a new project via fpm and then add following codes in fpm.toml to support openblas:

link = ["openblas"]
....
[dependencies]
stdlib = "*"
[preprocess]
[preprocess.cpp]
macros = ["STDLIB_EXTERNAL_BLAS", "STDLIB_EXTERNAL_LAPACK"]

Then add a flag in subroutine stdlib_dgemm in stdlib_linalg_blas_d.F90 to show if the stdlib_dgemm is called

454    subroutine stdlib_dgemm(transa,transb,m,n,k,alpha,a,lda,b,ldb,beta,c,ldc)
            ......
613           write(*,*)"stdlib_dgemm called!"
614           return
615     end subroutine stdlib_dgemm

And call gemm in main program:

program main
    use stdlib_linalg_blas, only: gemm
    use iso_fortran_env, only: dp => real64
    implicit none
    real(dp) :: AA(3, 4), BB(4, 4), CC(3, 4)
    integer :: i, j
    AA = reshape([1._dp, 5._dp, 9._dp, 2._dp, 6._dp, 10._dp, 3._dp, 7._dp, 11._dp, 4._dp, 8._dp, 12._dp], [3, 4])
    BB = reshape([0._dp, 0._dp, 0._dp, 1._dp, 0._dp, 0._dp, 1._dp, 0._dp, 0._dp, 1._dp, 0._dp, 0._dp, 1._dp, 0._dp, 0._dp, 0._dp], [4, 4])
    call gemm('N', 'N', 3, 4, 4, 1.0_dp, AA, 3, BB, 4, 0._dp, CC, 3)
    write (*, '(4ES8.1)') ((CC(i, j), j=1, 4), i=1, 3)
end program main

Launch the program via fpm run, and the result will show that the dgemm in openblas is not called while the stdlib_dgemm in stdlib is called. image

If we build directly via compiler flags fpm build --flag "-DSTDLIB_EXTERNAL_BLAS -DSTDLIB_EXTERNAL_LAPACK -lopenblas", the result will show that the dgemm in openblas is correctly called.

Expected Behaviour

preprocess macros works normally

Version of fpm

0.10.1, alpha

Platform and Architecture

Windows

Additional Information

No response

LaplaceSoda avatar May 25 '24 14:05 LaplaceSoda