<div dir="ltr"><div>Thanks Robert - specific at the cmake -D [...] command seemsd to work. Is it possible to set this inside a CMakeLists.txt? I have tried:</div><div><br></div><div>set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER}) </div><div>set(CUDA_LINKER_PREFERENCE ${CMAKE_CXX_COMPILER}) </div><div><br></div><div>but it snaps back to gcc still.</div><div><br></div><div>Thanks,</div><div>QT<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 31 Jul 2018 at 13:12, Robert Maynard <<a href="mailto:robert.maynard@kitware.com">robert.maynard@kitware.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It is snapping back to g++ as that was the linker that nvcc uses when<br>
it builds an executable. CMake detects this as part of the compiler<br>
detection process.<br>
<br>
I haven't verified that this will work but you can try specifying the<br>
LINKER_LANGUAGE(<a href="https://cmake.org/cmake/help/v3.12/prop_tgt/LINKER_LANGUAGE.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/v3.12/prop_tgt/LINKER_LANGUAGE.html</a>)<br>
of the executable to be 'CXX'. You might also explore specifying<br>
'CMAKE_CUDA_HOST_COMPILER' as part of your initial cmake configuration<br>
options to be the same as your c++ compiler ( you will need a clean<br>
build directory for this to work).<br>
On Tue, Jul 31, 2018 at 1:43 PM Quang Ha <<a href="mailto:quang.t.ha.20@gmail.com" target="_blank">quang.t.ha.20@gmail.com</a>> wrote:<br>
><br>
> Hi all,<br>
><br>
> Currently using cmake/3.11.1, I want to try and compile MPI/CUDA application with cmake. I kept running into problems of 'undefined MPI_Init', so I take a look at `make VERBOSE=1`. The output looks something like this<br>
><br>
> ===============================================================================<br>
> /projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script CMakeFiles/tangram.dir/link.txt --verbose=1<br>
> /projects/opt/centos7/openmpi/2.1.2-gcc_6.4.0/bin/mpicc -fPIC -fopenmp -O3 -DNDEBUG -shared -Wl,-soname,libtangram.so -o libtangram.so CMakeFiles/tangram.dir/tangram/intersect/r3d.c.o<br>
> make[2]: Leaving directory `/home/qth20/develop/tangram/build'<br>
> [ 40%] Built target tangram<br>
> make -f app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/build.make app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/depend<br>
> make[2]: Entering directory `/home/qth20/develop/tangram/build'<br>
> cd /home/qth20/develop/tangram/build && /projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_depends "Unix Makefiles" /home/qth20/develop/tangram /home/qth20/develop/tangram/app/vfgen-cuda /home/qth20/develop/tangram/build /home/qth20/develop/tangram/build/app/vfgen-cud$<br>
> /home/qth20/develop/tangram/build/app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/DependInfo.cmake --color=<br>
> make[2]: Leaving directory `/home/qth20/develop/tangram/build'<br>
> make -f app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/build.make app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/build<br>
> make[2]: Entering directory `/home/qth20/develop/tangram/build'<br>
> [ 60%] Building CUDA object app/vfgen-cuda/CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o<br>
> cd /home/qth20/develop/tangram/build/app/vfgen-cuda && /projects/opt/centos7/cuda/9.0/bin/nvcc -DCUDA_CALLABLE="\"__host__ __device__\"" -DENABLE_MPI -DHAVE_LAPACKE -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX -DTHRUST -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA -DTHRUST$<br>
> HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP -I/home/qth20/develop/tangram -I/home/qth20/develop/tangram/build -I/home/qth20/develop/tangram/cinch/logging -I/home/qth20/installed/jali-gcc_6.4.0-openmpi-2.1.2/include -I/home/qth20/installed/jali-tpls-gcc_6.4.0-openmpi-2.1.2/include<br>
> -I/home/qth20/installed/jali-tpls-gcc_6.4.0-openmpi-2.1.2/trilinos-12-10-1/include -I/projects/opt/centos7/openmpi/2.1.2-gcc_6.4.0/include -I/home/qth20/installed/jali-tpls-gcc_6.4.0-openmpi-2.1.2/trilinos-12-10-1/lib/cmake/Zoltan/../../../include -I/home/qth20/installed$<br>
> jali-tpls-gcc_6.4.0-openmpi-2.1.2/include/UnitTest++ -I/usr/include/lapacke -I/home/qth20/installed/xmof2d-gcc_6.4.0-openmpi_2.1.2/include -I/projects/opt/centos7/cuda/9.0/include --expt-relaxed-constexpr --std=c++11 -Xcompiler -fPIC -lmpi -O3 -DNDEBUG -x cu -c /home$<br>
> qth20/develop/tangram/app/vfgen-cuda/<a href="http://vfgen-cuda.cu" rel="noreferrer" target="_blank">vfgen-cuda.cu</a> -o CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o<br>
> /home/qth20/develop/tangram/tangram/wrappers/mesh/AuxMeshTopology.h(1708): warning: variable "nnodes" was declared but never referenced<br>
><br>
> /home/qth20/develop/tangram/tangram/wrappers/mesh/AuxMeshTopology.h(1993): warning: variable "ncells" was declared but never referenced<br>
><br>
> /home/qth20/develop/tangram/tangram/wrappers/mesh/AuxMeshTopology.h(2070): warning: variable "ibndry" was declared but never referenced<br>
><br>
> [ 80%] Linking CUDA device code CMakeFiles/vfgen-cuda.dir/cmake_device_link.o<br>
> cd /home/qth20/develop/tangram/build/app/vfgen-cuda && /projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script CMakeFiles/vfgen-cuda.dir/dlink.txt --verbose=1<br>
> /projects/opt/centos7/cuda/9.0/bin/nvcc --expt-relaxed-constexpr --std=c++11 -Xcompiler -fPIC -lmpi -O3 -DNDEBUG -Xcompiler=-fPIC -Wno-deprecated-gpu-targets -shared -dlink CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o -o CMakeFiles/vfgen-cuda.dir/cmake_device_link.o<br>
> [100%] Linking CUDA executable vfgen-cuda<br>
> cd /home/qth20/develop/tangram/build/app/vfgen-cuda && /projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script CMakeFiles/vfgen-cuda.dir/link.txt --verbose=1<br>
> /projects/opt/centos7/gcc/6.4.0/bin/g++ CMakeFiles/vfgen-cuda.dir/vfgen-cuda.cu.o CMakeFiles/vfgen-cuda.dir/cmake_device_link.o -o vfgen-cuda /projects/opt/centos7/cuda/9.0/lib64/libcudart_static.a -ldl /usr/lib64/librt.so -L"/projects/opt/centos7/cuda/9.0/lib64/stubs"<br>
> -L"/projects/opt/centos7/cuda/9.0/lib64" -lcudadevrt -lcudart_static -lrt -lpthread -ldl<br>
> ===============================================================================<br>
><br>
> so apparently, mpicc is used other parts of the project, but when linking extension between object codes it snaps back to g++(!). I have already specified CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to be mpicc and mpic++, respectively. Inside the CMakeLists for this CUDA:<br>
><br>
> ===============================================================================<br>
> project(tangram LANGUAGES CXX CUDA)<br>
> [...]<br>
> if (CUDA_FOUND)<br>
> string(APPEND CMAKE_CUDA_FLAGS "--expt-relaxed-constexpr --std=c++11 ")<br>
> # Other CUDA flags<br>
> endif(CUDA_FOUND)<br>
><br>
> [... Inside CUDA app directory...]<br>
> add_executable(vfgen-cuda <a href="http://vfgen-cuda.cu" rel="noreferrer" target="_blank">vfgen-cuda.cu</a>)<br>
> target_link_libraries(vfgen-cuda ${EXTRA_LIBS} ${MPI_LIBRARIES})<br>
> ===============================================================================<br>
><br>
> Is something missed out?<br>
><br>
> Thanks,<br>
> Quang<br>
> --<br>
><br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
><br>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
><br>
> CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>