[CMake] EXTERNAL: Difficulty making MPI and OpenMP Fortran shared library with CMake
Jim.Eliot at awe.co.uk
Jim.Eliot at awe.co.uk
Fri Mar 18 08:00:56 EDT 2016
Hi,
I’m not an expert but maybe I can help anyway.
I think that setting CMAKE_FORTRAN_COMPILER might be failing because it should be CMAKE_Fortran_COMPILER (case sensitive).
However, I am not sure that it is the best way to handle MPI code. I think that it might be better to use the MPI package which interrogates the system mpi wrappers (mpif90 etc.) and then uses the flags that it finds with the normal compiler (e.g. gfortran). Here is what works for me:
find_package(MPI REQUIRED)
…
include_directories(${MPI_Fortran_INCLUDE_PATH})
…
target_link_libraries(MIFF ${MPI_Fortran_LIBRARIES})
Kind regards,
Jim
Jim Eliot
High Performance Computing Group
AWE, Aldermaston, Reading, RG7 4PR
From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Rand Huso
Sent: 17 March 2016 21:46
To: cmake at cmake.org
Subject: EXTERNAL: [CMake] Difficulty making MPI and OpenMP Fortran shared library with CMake
I would like to use CMake for a personal project instead of make (which does work), but I can't seem to get CMake to work the way I think it should. The command "cmake ." runs fine, but the make produces this:
Scanning dependencies of target MIFF
Linking Fortran shared library libMIFF.so
gfortran: fatal error: no input files; unwilling to write output files
compilation terminated.
make[2]: *** [src/libMIFF.so] Error 4
make[1]: *** [src/CMakeFiles/MIFF.dir/all] Error 2
make: *** [all] Error 2
This surprises me because I don't think I should see "gfortran" - I expected to see "mpif90". And that particular message seems to happen when there are insufficient arguments to "gfortran". (the wrapper "mpif90" is configured to use "gfortran", but all compilation should use the "mpif90" - which doesn't appear to be the case when looking through the generated makefiles.)
Here's what my project looks like:
Directory structure:
MIFF
- src/
- - CMakeLists.txt
- - MIFFTest.f08
- - MIFFTestMessage.f08
- - MpiIocBaseMessage.f08
- - MpiIocControlMessage.f08
- - MpiIocFramework.f08
- - MpiIocLinkedListItem.f08
- CMakeLists.txt
My system is:
Ubuntu 14.04.4 LTS
The mpif90 compiler is:
GNU Fortran (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
CMake reports:
cmake version 2.8.12.2
Hopefully this is already fixed in newer versions of cmake - but this is the version currently installed - but that's difficult for me to test, as I'm working on a system that shouldn't deviate too far from our standard development platform.
The CMakeLists.txt file in the MIFF directory is:
cmake_minimum_required (VERSION 2.8.6)
project( MIFF_Project )
add_subdirectory( src )
the CMakeLists.txt file in the MIFF/src directory is:
cmake_minimum_required( VERSION 2.8.8 )
project( MIFF_Project )
enable_language( Fortran )
set( CMAKE_FORTRAN_COMPILER mpif90 )
file( GLOB MIFF_Code *.f* )
message( STATUS "MIFF_Code: ${MIFF_Code}" )
add_library( MIFF SHARED ${MIFF_Code} )
set_target_properties( MIFF PROPERTIES LINKER_LANGUAGE Fortran ) # OUTPUT_NAME MIFF )
I think I've exhausted Google looking for a solution, and I have a standard Makefile that seems to work fine:
.PHONY : all clean run
COMPILER = mpif90
FFLAGS = -shared -fPIC -g -I/usr/include
LIBRARY = MIFF.so
EXECUTABLE = MIFFTest
EXESOURCES = src/MIFFTest.f08 \
src/MIFFTestMessage.f08
LIBSOURCES = src/MpiIocBaseMessage.f08 \
src/MpiIocControlMessage.f08 \
src/MpiIocLinkedListItem.f08 \
src/MpiIocFramework.f08
src/MIFFTest.o : src/MIFFTest.f08 src/MIFFTestMessage.f08
all : $(LIBRARY) $(EXECUTABLE)
clean :
- rm -f *.o *.so *.mod $(EXECUTABLE)
run :
export LD_LIBRARY_PATH=~/workspace/MIFF
mpiexec -n 2 $(EXECUTABLE)
$(LIBRARY) : $(LIBSOURCES)
$(COMPILER) $(FFLAGS) $(LIBSOURCES) -o $(LIBRARY)
$(EXECUTABLE) : $(EXESOURCES) $(LIBRARY)
export LD_LIBRARY_PATH=~/workspace/MIFF
$(COMPILER) -o $(EXECUTABLE) $(EXESOURCES) $(LIBRARY)
Except for the problem of having to issue the "make all" twice because of a dependency problem I haven't worked out, this hand-crafted Makefile works. It's bad enough that I'm pushing the boundaries of polymorphism in MPI+OpenMP+Fortran.
I'd appreciate any assistance getting cmake to work for my project.
The information in this email and in any attachment(s) is
commercial in confidence. If you are not the named addressee(s)
or
if you receive this email in error then any distribution, copying or
use of this communication or the information in it is strictly
prohibited. Please notify us immediately by email at
admin.internet(at)awe.co.uk, and then delete this message from
your computer. While attachments are virus checked, AWE plc
does not accept any liability in respect of any virus which is not
detected.
AWE Plc
Registered in England and Wales
Registration No 02763902
AWE, Aldermaston, Reading, RG7 4PR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160318/2799ff4f/attachment-0001.html>
More information about the CMake
mailing list