How to get CMake to build a Fortran program with MPI support? -


i trying parallelize fortran program using mpi. use cmake build of program. difficult find support on getting cmake create working makefile fortran mpi support on google, gather, added following commands cmakelists.txt script:

find_package(mpi required) add_definitions(${mpi_fortran_compile_flags}) include_directories(${mpi_fortran_include_dirs}) link_directories(${mpi_fortranlibrary_dirs}) 

this locate mpi on system , set variables found in following 3 commands. in linking line, added mpi libraries variable list of other libraries program needed build.

target_link_libraries(${exe_name} otherlibs ${mpi_fortranlibrary_dirs}) 

doing cmake , make worked build program , program ran; however, when tried add more source required me include mpif.h include file, compilation failed due not being able find header file. not use mpi because compiler cannot find mpi.mod file in path.

i inserted "message" commands cmakelists.txt file , printed out values of variables using including , linking. turns out variables, mpi_fortran_include_dirs , mpi_fortranlibrary_dirs weren't set anything. check of module cmake using set these variables (findmpi.cmake) showed these variables non-existent. changed cmakelists.txt file use correct variables:

find_package(mpi required) add_definitions(${mpi_fortran_compile_flags}) include_directories(${mpi_fortran_include_path}) link_directories(${mpi_fortran_libraries}) target_link_libraries(${exe_name} otherlibs ${mpi_fortran_libraries}) 

now when execute make, compiler find both mpif.h mpi.mod.

update:

i want mention solution worked cmake version 2.8.10.1. when moved cmakelists.txt scripts different machine has cmake version 2.8.4, same error mpi.mod missing during link stage. checked findmpi.cmake module and, sure enough, there no variables specify language (i.e. there no mpi_fortran_libraries variable, mpi_libraries variable, , variable not getting set correct location of mpi library on system. solution dependent on cmake version.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -