<div dir="ltr"><div>Hi all,</div><div><br></div><div>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></div><div><br></div><div>===============================================================================<br></div><div>/projects/opt/centos7/cmake/3.11.1/bin/cmake -E cmake_link_script CMakeFiles/tangram.dir/link.txt --verbose=1<br><b>/projects/opt/centos7/openmpi/2.1.2-gcc_6.4.0/bin/mpicc</b> -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">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><b>/projects/opt/centos7/gcc/6.4.0/bin/g++</b>   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>===============================================================================</div><div><br></div><div>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:</div><div><br></div><div>===============================================================================</div><div>project(tangram LANGUAGES CXX CUDA) </div><div>[...]</div><div>if (CUDA_FOUND)</div><div>   string(APPEND CMAKE_CUDA_FLAGS "--expt-relaxed-constexpr --std=c++11 ")</div><div>   # Other CUDA flags<br></div><div>endif(CUDA_FOUND)</div><div><br></div><div>[... Inside CUDA app directory...]</div><div>add_executable(vfgen-cuda <a href="http://vfgen-cuda.cu">vfgen-cuda.cu</a>)<br>target_link_libraries(vfgen-cuda ${EXTRA_LIBS} ${MPI_LIBRARIES})<br></div><div>===============================================================================</div><div><br></div><div>Is something missed out?</div><div><br></div><div>Thanks,</div><div>Quang<br></div></div>