[CMake] testing for MPI_IN_PLACE
Michael Wild
themiwi at gmail.com
Fri Jan 7 07:17:39 EST 2011
On 01/07/2011 11:36 AM, Mark Abraham wrote:
> Hi,
>
> When using MPI, our project needs to be able to test for the validity of
> MPI_IN_PLACE (http://redmine.gromacs.org/issues/594). Ideally we could
> use try_compile to compile a simple test program, however we need to be
> able to direct the use of the compiler information CMake found using the
> FindMPI module. I don't think this is possible at the moment.
>
> Is there a recommended procedure? Should I open a try_compile feature
> request in the issue tracker?
>
> Regards,
>
> Mark
Try this:
find_package(MPI REQUIRED)
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_DEFINITIONS ${MPI_COMPILE_FLAGS})
set(CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH})
set(CMAKE_REQUIRED_LIBRARIES ${MPI_LIBRARIES})
check_c_source_compiles(
"#include <mpi.h>
int main() {
void* buf;
MPI_Allreduce(MPI_IN_PLACE, buf, 10, MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
}" MPI_IN_PLACE_COMPILE_OK)
Works for me, on Ubuntu 10.10 with openmpi. Internally, the
CheckCSourceCompiles.cmake module also uses try_compile, but wraps it
nicely and makes sure the test is only run once, and then the result is
cached.
Michael
More information about the CMake
mailing list