compile test for coupling to the LAMMPS library via fortran, check if it runs

This commit is contained in:
Axel Kohlmeyer
2023-01-13 06:26:06 -05:00
parent aa2d2509d8
commit a1f5d8420a
3 changed files with 56 additions and 4 deletions

View File

@ -38,7 +38,46 @@ if(NOT LAMMPS_SOURCE_DIR)
endif()
add_executable(simpleCC simple.cpp)
target_link_libraries(simpleCC LAMMPS::lammps)
target_link_libraries(simpleCC PRIVATE LAMMPS::lammps MPI::MPI_CXX)
add_executable(simpleC simple.c)
target_link_libraries(simpleC LAMMPS::lammps)
target_link_libraries(simpleC PRIVATE LAMMPS::lammps MPI::MPI_C)
if(LAMMPS_SOURCE_DIR)
include(CheckGeneratorSupport)
if(NOT CMAKE_GENERATOR_SUPPORT_FORTRAN)
message(STATUS "Skipping Test for the LAMMPS Fortran Module Coupling: no Fortran support in build tool")
return()
endif()
include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER AND MPI_Fortran_FOUND AND MPI_Fortran_HAVE_F90_MODULE)
enable_language(Fortran)
if(NOT CMAKE_Fortran_COMPILER_ID)
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: cannot identify Fortran compiler")
return()
endif()
# GNU Fortran 4.8.x on RHEL/CentOS 7.x is not sufficient to compile the Fortran module.
# Work around flang being detected as GNU
get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME)
if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0) AND NOT (_tmp_fc STREQUAL "flang"))
message(FATAL_ERROR "Need GNU Fortran compiler version 6.x or later for unit testing")
endif()
get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE)
add_executable(simpleF90 ${LAMMPS_FORTRAN_MODULE} simple.f90)
target_link_libraries(simpleF90 PRIVATE MPI::MPI_Fortran LAMMPS::lammps)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
target_compile_options(simpleF90 PRIVATE -fallow-argument-mismatch)
endif()
get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME)
if (_tmp_fc STREQUAL "flang")
target_link_libraries(simpleF90 PRIVATE gfortran)
endif()
endif()
endif()

View File

@ -18,8 +18,8 @@
! See README for compilation instructions
PROGRAM f_driver
USE mpi
USE liblammps
USE mpi
IMPLICIT NONE
INTEGER, PARAMETER :: fp=20
@ -129,7 +129,10 @@ PROGRAM f_driver
! free LAMMPS object
IF (color == 1) CALL lmp%close()
IF (color == 1) THEN
CALL lmp%CLOSE()
CALL mpi_comm_free(comm_lammps,ierr)
END IF
! close down MPI

View File

@ -87,6 +87,16 @@ if(BUILD_MPI)
COMMAND $<TARGET_FILE:simpleC> 1 ${LAMMPS_DIR}/examples/COUPLE/simple/in.lj)
add_test(NAME RunCoupleSimpleCC
COMMAND $<TARGET_FILE:simpleCC> 1 ${LAMMPS_DIR}/examples/COUPLE/simple/in.lj)
find_package(MPI QUIET)
if(CMAKE_Fortran_COMPILER AND MPI_Fortran_FOUND AND MPI_Fortran_HAVE_F90_MODULE)
add_test(NAME RunCoupleSimpleF90
COMMAND $<TARGET_FILE:simpleF90> 1 ${LAMMPS_DIR}/examples/COUPLE/simple/in.lj)
set_tests_properties(RunCoupleSimpleF90 PROPERTIES
ENVIRONMENT "TSAN_OPTIONS=ignore_noninstrumented_modules=1;HWLOC_HIDE_ERRORS=2"
PASS_REGULAR_EXPRESSION "LAMMPS \\([0-9]+ [A-Za-z]+ 2[0-9][0-9][0-9]( - Update [0-9]+)?\\)")
endif()
set_tests_properties(RunCoupleSimpleC RunCoupleSimpleCC PROPERTIES
ENVIRONMENT "TSAN_OPTIONS=ignore_noninstrumented_modules=1;HWLOC_HIDE_ERRORS=2"
PASS_REGULAR_EXPRESSION "LAMMPS \\([0-9]+ [A-Za-z]+ 2[0-9][0-9][0-9]( - Update [0-9]+)?\\)")