add tests whether simple examples for coupling to the LAMMPS library can run
This commit is contained in:
@ -37,11 +37,11 @@ set(MPI_CXX_SKIP_MPICXX TRUE)
|
||||
|
||||
##########################
|
||||
|
||||
add_executable(simple simple.c liblammpsplugin.c)
|
||||
target_link_libraries(simple PRIVATE MPI::MPI_C)
|
||||
target_compile_definitions(simple PRIVATE LAMMPS_LIB_MPI)
|
||||
add_executable(simple-plugin simple.c liblammpsplugin.c)
|
||||
target_link_libraries(simple-plugin PRIVATE MPI::MPI_C)
|
||||
target_compile_definitions(simple-plugin PRIVATE LAMMPS_LIB_MPI)
|
||||
|
||||
# link with -ldl or equivalent for plugin loading; except on Windows
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(simple PRIVATE ${CMAKE_DL_LIBS})
|
||||
target_link_libraries(simple-plugin PRIVATE ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
|
||||
@ -13,7 +13,7 @@ like below.
|
||||
|
||||
mpicc -c -O -DLAMMPS_LIB_MPI -Wall -g liblammpsplugin.c
|
||||
mpicc -c -O -DLAMMPS_LIB_MPI -Wall -g simple.c
|
||||
mpicc simple.o liblammpsplugin.o -ldl -o simpleC
|
||||
mpicc simple.o liblammpsplugin.o -ldl -o simple-plugin
|
||||
|
||||
or using the provided CMake file with:
|
||||
|
||||
@ -36,14 +36,14 @@ cd build-shared
|
||||
cmake -D BUILD_MPI=on -D BUILD_SHARED_LIBS=on ../cmake
|
||||
make
|
||||
|
||||
You then run simpleC on a parallel machine
|
||||
You then run simple-plugin on a parallel machine
|
||||
on some number of processors Q with 3 arguments:
|
||||
|
||||
% mpirun -np Q simpleC P in.lj $HOME/lammps/src/liblammps.so
|
||||
% mpirun -np Q simple-plugin P in.lj $HOME/lammps/src/liblammps.so
|
||||
|
||||
or
|
||||
|
||||
% mpirun -np Q simpleC P in.lj $HOME/lammps/build-shared/liblammps.so
|
||||
% mpirun -np Q simple-plugin P in.lj $HOME/lammps/build-shared/liblammps.so
|
||||
|
||||
P is the number of procs you want LAMMPS to run on (must be <= Q) and
|
||||
in.lj is a LAMMPS input script and the last argument is the path to
|
||||
|
||||
@ -1,17 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(simple CXX)
|
||||
|
||||
set(LAMMPS_SRC_DIRECTORY "" CACHE PATH "Path for lammps source")
|
||||
if(NOT LAMMPS_SRC_DIRECTORY STREQUAL "" AND EXISTS ${LAMMPS_SRC_DIRECTORY}/cmake/CMakeLists.txt)
|
||||
option(BUILD_LIB "Build LAMMPS library" ON)
|
||||
add_subdirectory(${LAMMPS_SRC_DIRECTORY}/cmake lammps)
|
||||
else()
|
||||
# enforce out-of-source build
|
||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||
message(FATAL_ERROR "In-source builds are not allowed. You must create and use a build directory. "
|
||||
"Please remove CMakeCache.txt and CMakeFiles first.")
|
||||
endif()
|
||||
|
||||
project(couple-simple VERSION 1.0 LANGUAGES C CXX)
|
||||
|
||||
# by default, install into $HOME/.local (not /usr/local),
|
||||
# so that no root access (and sudo) is needed
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "Default install path" FORCE)
|
||||
endif()
|
||||
|
||||
# ugly hacks for MSVC which by default always reports an old C++ standard in the __cplusplus macro
|
||||
# and prints lots of pointless warnings about "unsafe" functions
|
||||
if(MSVC)
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||
if(LAMMPS_EXCEPTIONS)
|
||||
add_compile_options(/EHsc)
|
||||
endif()
|
||||
endif()
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
find_package(MPI QUIET)
|
||||
# do not include the (obsolete) MPI C++ bindings which makes
|
||||
# for leaner object files and avoids namespace conflicts
|
||||
set(MPI_CXX_SKIP_MPICXX TRUE)
|
||||
|
||||
##########################
|
||||
|
||||
# build within LAMMPS build system
|
||||
if(NOT LAMMPS_SOURCE_DIR)
|
||||
find_package(LAMMPS REQUIRED)
|
||||
endif()
|
||||
|
||||
add_executable(simpleCC simple.cpp)
|
||||
target_link_libraries(simpleCC LAMMPS::lammps)
|
||||
|
||||
enable_language(C)
|
||||
add_executable(simpleC simple.c)
|
||||
target_link_libraries(simpleC LAMMPS::lammps)
|
||||
|
||||
@ -71,3 +71,23 @@ add_executable(test_library_mpi test_library_mpi.cpp)
|
||||
target_link_libraries(test_library_mpi PRIVATE lammps GTest::GMock)
|
||||
target_compile_definitions(test_library_mpi PRIVATE ${TEST_CONFIG_DEFS})
|
||||
add_mpi_test(NAME LibraryMPI NUM_PROCS 4 COMMAND $<TARGET_FILE:test_library_mpi>)
|
||||
|
||||
# simple run tests for coupling to the LAMMPS library
|
||||
if(BUILD_MPI)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_subdirectory(${LAMMPS_DIR}/examples/COUPLE/plugin ${CMAKE_BINARY_DIR}/build-couple)
|
||||
add_test(NAME RunCoupleSimplePlugin
|
||||
COMMAND $<TARGET_FILE:simple-plugin> 1 ${LAMMPS_DIR}/examples/COUPLE/plugin/in.lj $<TARGET_FILE:lammps>)
|
||||
set_tests_properties(RunCoupleSimplePlugin 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()
|
||||
add_subdirectory(${LAMMPS_DIR}/examples/COUPLE/simple ${CMAKE_BINARY_DIR}/build-simple)
|
||||
add_test(NAME RunCoupleSimpleC
|
||||
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)
|
||||
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]+)?\\)")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user