Home > OS >  Is it ok for CMake to use c , rather than mpicxx, to compile my code?
Is it ok for CMake to use c , rather than mpicxx, to compile my code?

Time:01-16

I'm trying to build an executable from C source code which uses MPI, on a GNU/Linux Devuan Chimaera system. Now, I'm an MPI/OpenMP newbie, I'm just trying to adapt this code, which isn't mine, to be built with CMake - when before it had a Makefile. My build succeeds, but I'm seeing segfaults, so I want to make sure my problem isn't with the build phase, which bugs me.

My CMakeLists.txt has:

find_package(OpenMP REQUIRED)
find_package(MPI)

and my system has OpenMPI 4.1.1 installed, which is found. I do this for my target:

target_link_libraries(my_executable MPI::MPI_CXX OpenMP::OpenMP_CXX)

but nothing else which indicates its expecting to be compiled by mpicxx.

... and indeed, when I configure (with CMake 3.22.1) and then build, the usual c executable gets invoked to compile (and then link) the my_target executable.

Questions:

  • Can source code which originally was getting compiled with mpicxx be compiled with "just" a C compiler, with the appropriate includes?
  • Assuming there's any merit to using mpicxx for compilation - how do I get CMake to use it for my target?

CodePudding user response:

  • Can source code which originally was getting compiled with mpicxx be compiled with "just" a C compiler, with the appropriate includes?

Yes, and you're doing it correctly (provided you are handling not finding MPI correctly, as it is not marked REQUIRED).

The MPI systems I've used (Cori, Perlmutter, Stampede) have all provided implementations that work correctly with CMake's MPI support. However, it's possible that a sufficiently poorly administered system will break this.

  • Assuming there's any merit to using mpicxx for compilation - how do I get CMake to use it for my target?

This is a toolchain setting... set CMAKE_CXX_COMPILER to /path/to/mpicxx either at the command line, in a preset, or in a toolchain file.

  •  Tags:  
  • Related