1

My goal is by compiling (pun not intended) a list of causes for LNK2038 "mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'" that others may follow methodically to debug their own situations, my situation will be resolved

My situation:

Requirements:

  • Windows 10
  • CMake
  • MSVS 2017
  • Intel Paralax Studio XE
  • CUDA

To reproduce:

  1. Download MAGMA
  2. Run CMake GUI

    • Manually set GPU_TARGET=Pascal (My Card: GeForce GTX 1070 Compute Capability: 6.1)
    • Manually set MKLROOT=D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl (as instructed in the README-Windows)
    • LAPACK_LIBRARIES: use https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor to determine

      • My choice
      • 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
  3. From the generated VS solution, compile in Debug mode magma and magma_sparse projects (no need to compile the 600+ test projects)

  4. In a separate folder put the example code and the CMakeLists.txt

    add_executable(magma-test example_sparse.cpp)
    
    find_package( CUDA ) # just to set CUDA_INCLUDE_DIRS
    
    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})
    target_link_libraries(magma-test 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)
    
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
    
  5. Run CMake (Configure, Generate)

  6. Open VS solution, and compile in Debug mode

Problematic outcome:

1>magma_sparse.lib(magma_sparse_generated_djacobisetup.cu.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in magma.lib(interface.obj)

1>magma_sparse.lib(magma_sparse_generated_djacobisetup.cu.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in magma.lib(interface.obj)

----------

Things to check upon LNK2038:

  1. All dependencies (*.lib files) were compiled with the same "Debug/Release" flags
    • Double check the dependencies actually being used by Right-click on your Project -> Properties -> Linker -> Input -> Additional Dependencies
    • Go to each dependency project and to your project, and check the build flags by Right-click on Project -> Properties -> C/C++ -> Code Generation -> Runtime Library
WurmD
  • 1,231
  • 5
  • 21
  • 42
  • For me, my example project "Additional Dependencies" lists D:\Work\Magma\magma-2.4.0\build\lib\Debug\magma.lib;D:\Work\Magma\magma-2.4.0\build\lib\Debug\magma_sparse.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib, and both my example code project, plus magma and magma_sparse project are "MTd" :(, what should I check next? – WurmD Nov 03 '18 at 14:11
  • You are mixing Debug and Release. Everything must be Release or Debug no mixing is allowed unless the library was written in `c`. – drescherjm Nov 03 '18 at 14:12
  • I've deleted all the whole Release folder of MAGMA :( @drescherjm – WurmD Nov 03 '18 at 14:14
  • and I've renamed magma.lib and magma_sparse.lib in the Debug folder to make sure they are the ones being used and , indeed it says "1>LINK : fatal error LNK1104: cannot open file 'D:\Work\Magma\magma-2.4.0\build\lib\Debug\magma_sparse.lib' – WurmD Nov 03 '18 at 14:15
  • After fixing the settings you probably have to do a clean build. – drescherjm Nov 03 '18 at 14:15
  • Did a "clean", and "rebuild" of MAGMA, and of my example project, three times already :/ @drescherjm – WurmD Nov 03 '18 at 14:21
  • `target_link_libraries(magma-test debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma.lib D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma_sparse.lib)` there should be an entry for optimized if you want release. – drescherjm Nov 03 '18 at 15:23
  • I expect your problem is the libs in the Debug folder were not debug libraries. Not sure why. – drescherjm Nov 03 '18 at 15:25
  • Or perhaps the Debug libs have some Release dependency. – drescherjm Nov 03 '18 at 21:20
  • If magma_sparse.lib has a Release dependency, would it even compile in Debug mode? (bc it does compile; and I just deleted the MAGMA folder and did a complete rebuild from scratch *only* in Debug mode) @drescherjm – WurmD Nov 03 '18 at 21:41
  • @WurmD any solution to this issue? I'm having the exact same issue :-( – Vahid Noormofidi Jan 09 '19 at 01:23
  • @Vahid :( no, I gave up on MAGMA after I realized that their claim of "we'll determine where your code should run automatically (CPU or GPU)" was false for Sparse Matrixes (it's always in GPU). And they don't even standardize the code. The code to deal with sparse matrixes was different than the dense examples. – WurmD Jan 23 '19 at 20:03

1 Answers1

1

A CMakeLists.txt that "resolves" the above error, compiles and runs is:

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)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

The CUDA and MKL libraries that MAGMA uses upon compilation seemingly also have to be provided for code that uses MAGMA libraries

EDIT: Wait, no. It's compiling and running in Release, but not in Debug..

WurmD
  • 1,231
  • 5
  • 21
  • 42
  • I would have told you about using optimized in `target_link_libraries` but I thought you were building the Debug configuration. – drescherjm Nov 07 '18 at 18:17
  • Lol @drescherjm, txs. What was missing was not that, was the target_include_directories(magma-test ${CUDA_INCLUDE_DIRS} ${MKLROOT}/include), and the target_link_libraries(magma-test ${CUDA_CUDART_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${LAPACK_LIBRARIES} – WurmD Nov 08 '18 at 11:37