[CMake] testing for MPI_IN_PLACE

Mark Abraham Mark.J.Abraham at gmail.com
Fri Jan 7 09:26:23 EST 2011


On 7/01/2011 11:17 PM, Michael Wild wrote:
> 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.

Hi,

Thanks for your suggestion. I tried it using gmxTestMPI_IN_PLACE.cmake 
containing

find_package(MPI REQUIRED)

MACRO(GMX_TEST_MPI_IN_PLACE VARIABLE)
     MESSAGE(STATUS "Checking for MPI_IN_PLACE with 
'${MPI_COMPILE_FLAGS}', '${MPI_INCLUDE_PATH}', '${MPI_LIBRARIES}'")

     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)

     if(MPI_IN_PLACE_COMPILE_OK)
         MESSAGE(STATUS "Checking for MPI_IN_PLACE - yes")
             set(${VARIABLE} ${MPI_IN_PLACE_COMPILE_OK}
                 "Result of test for MPI_IN_PLACE")
     else(MPI_IN_PLACE_COMPILE_OK)
         MESSAGE(STATUS "Checking for MPI_IN_PLACE - no")
     endif(MPI_IN_PLACE_COMPILE_OK)
ENDMACRO(GMX_TEST_MPI_IN_PLACE VARIABLE)

and received as (abbreviated) output from "cmake .. --trace":

...<snip>...
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(8): 
find_package(MPI REQUIRED )
/home/mxa224/builds/gromacs/cmake/FindMPI.cmake(75): 
TRY_COMPILE(MPI_FOUND ${CMAKE_BINARY_DIR} 
${CMAKE_SOURCE_DIR}/cmake/TestMPI.c COMPILE_DEFINITIONS )
...<snip>...
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(10): 
MACRO(GMX_TEST_MPI_IN_PLACE VARIABLE )
/home/mxa224/builds/gromacs/CMakeLists.txt(193):  if(GMX_MPI_IN_PLACE )
/home/mxa224/builds/gromacs/CMakeLists.txt(194): 
gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(11): 
MESSAGE(STATUS Checking for MPI_IN_PLACE with '${MPI_COMPILE_FLAGS}', 
'${MPI_INCLUDE_PATH}', '${MPI_LIBRARIES}' )
-- Checking for MPI_IN_PLACE with '', '/apps/openmpi/1.4.3/include', 
'/apps/openmpi/1.4.3/lib/libmpi_cxx.so;/apps/openmpi/1.4.3/lib/libmpi.so;/apps/openmpi/1.4.3/lib/libopen-rte.so;/apps/openmpi/1.4.3/lib/libopen-pal.so;/usr/lib64/libdl.so;/usr/lib64/libnsl.so;/usr/lib64/libutil.so;/usr/lib64/libm.so;/usr/lib64/libdl.so'
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(13): 
include(CheckCSourceCompiles )
/apps/CMake/2.8.2/share/cmake-2.8/Modules/CheckCSourceCompiles.cmake(27): 
MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(14): 
set(CMAKE_REQUIRED_DEFINITIONS ${MPI_COMPILE_FLAGS} )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(15): 
set(CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH} )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(16): 
set(CMAKE_REQUIRED_LIBRARIES ${MPI_LIBRARIES} )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(17): 
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 )
/apps/CMake/2.8.2/share/cmake-2.8/Modules/CheckCSourceCompiles.cmake(28): 
IF(MPI_IN_PLACE_COMPILE_OK MATCHES ^MPI_IN_PLACE_COMPILE_OK$ )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(24): 
if(MPI_IN_PLACE_COMPILE_OK )
/home/mxa224/builds/gromacs/cmake/gmxTestMPI_IN_PLACE.cmake(29): 
MESSAGE(STATUS Checking for MPI_IN_PLACE - no )
-- Checking for MPI_IN_PLACE - no
...<snip>...

It appears that FindMPI.cmake works fine, but then the CMake macro 
CHECK_C_SOURCE_COMPILES seems to fail its "check variable name for 
sanity" test. I can conceive of no reason for this happening. What have 
I done wrong, please?

Regards,

Mark


More information about the CMake mailing list