如何在Visual Studio中编译使用MAGMA的代码

时间:2018-11-08 11:44:01

标签: c++ visual-studio magma

鉴于MAGMA随附的example code,如何在Visual Studio(或您使用MAGMA的任何其他代码)中进行编译?

1 个答案:

答案 0 :(得分:0)

我首选的方式是使用CMake。

注意1:,还必须包括并链接CUDA和LAPACK(如果最初是用来编译MAGMA的,则还包括MKL)

注2::如果您不想静态链接,则需要在运行时使DLL可被发现,方法是将其复制到项目文件夹中,或者将其位置添加到PATH < / p>

以下CMakeLists.txt生成一个VS项目,该项目可编译并运行示例代码。

add_executable(magma-test example_sparse.cpp)

find_package( CUDA ) 
set( MKLROOT "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl" )
set( LAPACK_LIBRARIES 
   "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_lp64.lib"
   "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_thread.lib"
   "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_core.lib"
   "D:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.0.117/windows/compiler/lib/intel64_win/libiomp5md.lib")

target_include_directories(magma-test PUBLIC 
   "D:/Work/Magma/magma-2.4.0/include" 
   "D:/Work/Magma/magma-2.4.0/sparse/include" 
   ${CUDA_INCLUDE_DIRS}
   ${MKLROOT}/include)
target_link_libraries(magma-test 
   ${CUDA_CUDART_LIBRARY}
   ${CUDA_CUBLAS_LIBRARIES}
   ${CUDA_cusparse_LIBRARY}
   ${LAPACK_LIBRARIES}
   debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma.lib 
   debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma_sparse.lib
   optimized D:/Work/Magma/magma-2.4.0/build/lib/Release/magma.lib 
   optimized D:/Work/Magma/magma-2.4.0/build/lib/Release/magma_sparse.lib)

# Sets flags that cause static linking
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") 
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

编辑:不,不。它是在Release中编译并运行的,而不是在Debug中运行的。