Merge pull request #3680 from akohlmey/cmake-fixup-linking
Address double linking issue with Kokkos libraries
This commit is contained in:
@ -538,7 +538,10 @@ set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine
|
|||||||
separate_arguments(CMAKE_TUNE_FLAGS)
|
separate_arguments(CMAKE_TUNE_FLAGS)
|
||||||
foreach(_FLAG ${CMAKE_TUNE_FLAGS})
|
foreach(_FLAG ${CMAKE_TUNE_FLAGS})
|
||||||
target_compile_options(lammps PRIVATE ${_FLAG})
|
target_compile_options(lammps PRIVATE ${_FLAG})
|
||||||
target_compile_options(lmp PRIVATE ${_FLAG})
|
# skip these flags when linking the main executable
|
||||||
|
if(NOT (("${_FLAG}" STREQUAL "-Xcudafe") OR (("${_FLAG}" STREQUAL "--diag_suppress=unrecognized_pragma"))))
|
||||||
|
target_compile_options(lmp PRIVATE ${_FLAG})
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
########################################################################
|
########################################################################
|
||||||
# Basic system tests (standard libraries, headers, functions, types) #
|
# Basic system tests (standard libraries, headers, functions, types) #
|
||||||
|
|||||||
@ -72,13 +72,11 @@ if(DOWNLOAD_KOKKOS)
|
|||||||
set_target_properties(LAMMPS::KOKKOSCONTAINERS PROPERTIES
|
set_target_properties(LAMMPS::KOKKOSCONTAINERS PROPERTIES
|
||||||
IMPORTED_LOCATION "${INSTALL_DIR}/lib/libkokkoscontainers.a")
|
IMPORTED_LOCATION "${INSTALL_DIR}/lib/libkokkoscontainers.a")
|
||||||
target_link_libraries(lammps PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS)
|
target_link_libraries(lammps PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS)
|
||||||
target_link_libraries(lmp PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS)
|
|
||||||
add_dependencies(LAMMPS::KOKKOSCORE kokkos_build)
|
add_dependencies(LAMMPS::KOKKOSCORE kokkos_build)
|
||||||
add_dependencies(LAMMPS::KOKKOSCONTAINERS kokkos_build)
|
add_dependencies(LAMMPS::KOKKOSCONTAINERS kokkos_build)
|
||||||
elseif(EXTERNAL_KOKKOS)
|
elseif(EXTERNAL_KOKKOS)
|
||||||
find_package(Kokkos 3.7.01 REQUIRED CONFIG)
|
find_package(Kokkos 3.7.01 REQUIRED CONFIG)
|
||||||
target_link_libraries(lammps PRIVATE Kokkos::kokkos)
|
target_link_libraries(lammps PRIVATE Kokkos::kokkos)
|
||||||
target_link_libraries(lmp PRIVATE Kokkos::kokkos)
|
|
||||||
else()
|
else()
|
||||||
set(LAMMPS_LIB_KOKKOS_SRC_DIR ${LAMMPS_LIB_SOURCE_DIR}/kokkos)
|
set(LAMMPS_LIB_KOKKOS_SRC_DIR ${LAMMPS_LIB_SOURCE_DIR}/kokkos)
|
||||||
set(LAMMPS_LIB_KOKKOS_BIN_DIR ${LAMMPS_LIB_BINARY_DIR}/kokkos)
|
set(LAMMPS_LIB_KOKKOS_BIN_DIR ${LAMMPS_LIB_BINARY_DIR}/kokkos)
|
||||||
@ -98,7 +96,6 @@ else()
|
|||||||
${LAMMPS_LIB_KOKKOS_BIN_DIR})
|
${LAMMPS_LIB_KOKKOS_BIN_DIR})
|
||||||
target_include_directories(lammps PRIVATE ${Kokkos_INCLUDE_DIRS})
|
target_include_directories(lammps PRIVATE ${Kokkos_INCLUDE_DIRS})
|
||||||
target_link_libraries(lammps PRIVATE kokkos)
|
target_link_libraries(lammps PRIVATE kokkos)
|
||||||
target_link_libraries(lmp PRIVATE kokkos)
|
|
||||||
if(BUILD_SHARED_LIBS_WAS_ON)
|
if(BUILD_SHARED_LIBS_WAS_ON)
|
||||||
set(BUILD_SHARED_LIBS ON)
|
set(BUILD_SHARED_LIBS ON)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
31
src/main.cpp
31
src/main.cpp
@ -13,9 +13,8 @@
|
|||||||
|
|
||||||
#include "lammps.h"
|
#include "lammps.h"
|
||||||
|
|
||||||
#include "accelerator_kokkos.h"
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "lmppython.h"
|
#include "library.h"
|
||||||
|
|
||||||
#if defined(LAMMPS_EXCEPTIONS)
|
#if defined(LAMMPS_EXCEPTIONS)
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
@ -35,6 +34,13 @@
|
|||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
|
// for convenience
|
||||||
|
static void finalize()
|
||||||
|
{
|
||||||
|
lammps_kokkos_finalize();
|
||||||
|
lammps_python_finalize();
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
main program to drive LAMMPS
|
main program to drive LAMMPS
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
@ -42,7 +48,6 @@ using namespace LAMMPS_NS;
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
|
|
||||||
MPI_Comm lammps_comm = MPI_COMM_WORLD;
|
MPI_Comm lammps_comm = MPI_COMM_WORLD;
|
||||||
|
|
||||||
#if defined(LMP_MDI)
|
#if defined(LMP_MDI)
|
||||||
@ -76,19 +81,21 @@ int main(int argc, char **argv)
|
|||||||
lammps->input->file();
|
lammps->input->file();
|
||||||
delete lammps;
|
delete lammps;
|
||||||
} catch (LAMMPSAbortException &ae) {
|
} catch (LAMMPSAbortException &ae) {
|
||||||
KokkosLMP::finalize();
|
finalize();
|
||||||
Python::finalize();
|
|
||||||
MPI_Abort(ae.universe, 1);
|
MPI_Abort(ae.universe, 1);
|
||||||
} catch (LAMMPSException &) {
|
} catch (LAMMPSException &) {
|
||||||
KokkosLMP::finalize();
|
finalize();
|
||||||
Python::finalize();
|
|
||||||
MPI_Barrier(lammps_comm);
|
MPI_Barrier(lammps_comm);
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
exit(1);
|
exit(1);
|
||||||
} catch (fmt::format_error &fe) {
|
} catch (fmt::format_error &fe) {
|
||||||
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
KokkosLMP::finalize();
|
finalize();
|
||||||
Python::finalize();
|
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||||
|
exit(1);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "Exception: %s\n", e.what());
|
||||||
|
finalize();
|
||||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -99,14 +106,12 @@ int main(int argc, char **argv)
|
|||||||
delete lammps;
|
delete lammps;
|
||||||
} catch (fmt::format_error &fe) {
|
} catch (fmt::format_error &fe) {
|
||||||
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
KokkosLMP::finalize();
|
finalize();
|
||||||
Python::finalize();
|
|
||||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
KokkosLMP::finalize();
|
finalize();
|
||||||
Python::finalize();
|
|
||||||
MPI_Barrier(lammps_comm);
|
MPI_Barrier(lammps_comm);
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user