Unverified Commit 38edf20d authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add CMake support for building LAMMPS for windows with MPI

- Handle the MPI support as an External project.
- Also we can enable a few more packages now, that depend on MPI
- Improved dependency tracking for parallel builds
- cross compiler build can now also work with ninja
parent b1af0a5b
Loading
Loading
Loading
Loading
+30 −13
Original line number Original line Diff line number Diff line
@@ -167,11 +167,17 @@ if(PKG_USER-ADIOS)
  list(APPEND LAMMPS_LINK_LIBS adios2::adios2)
  list(APPEND LAMMPS_LINK_LIBS adios2::adios2)
endif()
endif()


# do MPI detection after language activation, if MPI for these language is required
# do MPI detection after language activation,
# in case MPI for these languages is required
set(MPI_CXX_SKIP_MPICXX TRUE)
set(MPI_CXX_SKIP_MPICXX TRUE)
find_package(MPI QUIET)
find_package(MPI QUIET)
option(BUILD_MPI "Build MPI version" ${MPI_FOUND})
option(BUILD_MPI "Build MPI version" ${MPI_FOUND})

if(BUILD_MPI)
if(BUILD_MPI)
  # We use a non-standard procedure to compile with MPI on windows
  if (CMAKE_SYSTEM_NAME STREQUAL Windows)
    include(MPI4WIN)
  else()
    find_package(MPI REQUIRED)
    find_package(MPI REQUIRED)
    include_directories(${MPI_CXX_INCLUDE_PATH})
    include_directories(${MPI_CXX_INCLUDE_PATH})
    add_definitions(-DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1)
    add_definitions(-DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1)
@@ -180,6 +186,7 @@ if(BUILD_MPI)
    if(LAMMPS_LONGLONG_TO_LONG)
    if(LAMMPS_LONGLONG_TO_LONG)
      add_definitions(-DLAMMPS_LONGLONG_TO_LONG)
      add_definitions(-DLAMMPS_LONGLONG_TO_LONG)
    endif()
    endif()
  endif()
else()
else()
  enable_language(C)
  enable_language(C)
  file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c)
  file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c)
@@ -335,11 +342,6 @@ include(Packages/MESSAGE)
include(Packages/MSCG)
include(Packages/MSCG)
include(Packages/COMPRESS)
include(Packages/COMPRESS)


# the windows version of LAMMPS requires a couple extra libraries
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  list(APPEND LAMMPS_LINK_LIBS -lwsock32 -lpsapi)
endif()

set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler specific optimization or instrumentation")
set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler specific optimization or instrumentation")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_TUNE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_TUNE_FLAGS}")
if(CMAKE_Fortran_FLAGS)
if(CMAKE_Fortran_FLAGS)
@@ -428,6 +430,9 @@ foreach(SIMPLE_LIB POEMS USER-ATC USER-AWPMD USER-H5MD)
      ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.c
      ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.c
      ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.cpp)
      ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.cpp)
    add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES})
    add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES})
    if(LAMMPS_USE_MPI4WIN)
      add_dependencies(${PKG_LIB} mpi4win_build)
    endif()
    list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB})
    list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB})
    if(PKG_LIB STREQUAL awpmd)
    if(PKG_LIB STREQUAL awpmd)
      target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include)
      target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include)
@@ -465,6 +470,18 @@ include(Packages/OPT)
include(Packages/USER-INTEL)
include(Packages/USER-INTEL)
include(Packages/GPU)
include(Packages/GPU)


######################################################################
# the windows version of LAMMPS requires a couple extra libraries
# and the MPI library - if use - has to be linked right before those
# and after everything else that is compiled locally
######################################################################
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  if(LAMMPS_USE_MPI4WIN)
    list(APPEND LAMMPS_LINK_LIBS ${MPI4WIN_LIBRARIES})
  endif()
  list(APPEND LAMMPS_LINK_LIBS -lwsock32 -lpsapi)
endif()

######################################################
######################################################
# Generate style headers based on global list of
# Generate style headers based on global list of
# styles registered during package selection
# styles registered during package selection
+23 −0
Original line number Original line Diff line number Diff line
# Download and configure custom MPICH files for Windows
message(STATUS "Downloading and configuring MPICH-1.4.1 for Windows")
include(ExternalProject)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  ExternalProject_Add(mpi4win_build
    URL https://download.lammps.org/thirdparty/mpich2-win64-devel.tar.gz
    URL_MD5 4939fdb59d13182fd5dd65211e469f14
    CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND ""
    BUILD_BYPRODUCTS <SOURCE_DIR>/lib/libmpi.a)
else()
  ExternalProject_Add(mpi4win_build
    URL https://download.lammps.org/thirdparty/mpich2-win32-devel.tar.gz
    URL_MD5 a61d153500dce44e21b755ee7257e031
    CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND ""
    BUILD_BYPRODUCTS <SOURCE_DIR>/lib/libmpi.a)
endif()

ExternalProject_get_property(mpi4win_build SOURCE_DIR)
add_definitions(-DMPICH_SKIP_MPICXX)
include_directories("${SOURCE_DIR}/include")
set(MPI4WIN_LIBRARIES "${SOURCE_DIR}/lib/libmpi.a")
list(APPEND LAMMPS_DEPS mpi4win_build)
set(LAMMPS_USE_MPI4WIN ON)
+6 −0
Original line number Original line Diff line number Diff line
@@ -108,6 +108,9 @@ if(PKG_GPU)
      endif()
      endif()


      list(APPEND LAMMPS_LINK_LIBS gpu)
      list(APPEND LAMMPS_LINK_LIBS gpu)
      if(LAMMPS_USE_MPI4WIN)
        add_dependencies(gpu mpi4win_build)
      endif()


      add_executable(nvc_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp)
      add_executable(nvc_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp)
      target_compile_definitions(nvc_get_devices PRIVATE -DUCL_CUDADR)
      target_compile_definitions(nvc_get_devices PRIVATE -DUCL_CUDADR)
@@ -169,6 +172,9 @@ if(PKG_GPU)
      target_compile_definitions(gpu PRIVATE -DUSE_OPENCL)
      target_compile_definitions(gpu PRIVATE -DUSE_OPENCL)


      list(APPEND LAMMPS_LINK_LIBS gpu)
      list(APPEND LAMMPS_LINK_LIBS gpu)
      if(LAMMPS_USE_MPI4WIN)
        add_dependencies(gpu mpi4win_build)
      endif()


      add_executable(ocl_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp)
      add_executable(ocl_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp)
      target_compile_definitions(ocl_get_devices PRIVATE -DUCL_OPENCL)
      target_compile_definitions(ocl_get_devices PRIVATE -DUCL_OPENCL)
+7 −1
Original line number Original line Diff line number Diff line
@@ -3,7 +3,7 @@ set(WIN_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL DIPOLE GPU
                 POEMS QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI
                 POEMS QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI
                 USER-ATC USER-AWPMD USER-BOCS USER-CGDNA USER-CGSDK
                 USER-ATC USER-AWPMD USER-BOCS USER-CGDNA USER-CGSDK
                 USER-COLVARS USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF
                 USER-COLVARS USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF
                 USER-FEP USER-INTEL USER-MANIFOLD USER-MEAMC USER-MESO
                 USER-FEP USER-INTEL USER-MANIFOLD USER-MEAMC USER-MESODPD
                 USER-MISC USER-MGPT USER-MOFFF USER-MOLFILE USER-OMP
                 USER-MISC USER-MGPT USER-MOFFF USER-MOLFILE USER-OMP
                 USER-PHONON USER-PTM USER-QTB USER-REACTION USER-REAXC
                 USER-PHONON USER-PTM USER-QTB USER-REACTION USER-REAXC
                 USER-SDPD USER-SMD USER-SMTBQ USER-SPH USER-TALLY USER-UEF
                 USER-SDPD USER-SMD USER-SMTBQ USER-SPH USER-TALLY USER-UEF
@@ -13,6 +13,12 @@ foreach(PKG ${WIN_PACKAGES})
  set(PKG_${PKG} ON CACHE BOOL "" FORCE)
  set(PKG_${PKG} ON CACHE BOOL "" FORCE)
endforeach()
endforeach()


# these two packages require a full MPI implementation
if(BUILD_MPI)
  set(PKG_MPIIO ON CACHE BOOL "" FORCE)
  set(PKG_USER-LB ON CACHE BOOL "" FORCE)
endif()

set(DOWNLOAD_VORO ON CACHE BOOL "" FORCE)
set(DOWNLOAD_VORO ON CACHE BOOL "" FORCE)
set(DOWNLOAD_EIGEN3 ON CACHE BOOL "" FORCE)
set(DOWNLOAD_EIGEN3 ON CACHE BOOL "" FORCE)
set(LAMMPS_MEMALIGN "0" CACHE STRING "" FORCE)
set(LAMMPS_MEMALIGN "0" CACHE STRING "" FORCE)