diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 42e6d12ffb..60b1bcfc0a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -220,6 +220,7 @@ if(BUILD_OMP) endif() if (((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") OR ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)) OR ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0))) # GCC 9.x and later plus Clang 10.x and later implement strict OpenMP 4.0 semantics for consts. diff --git a/cmake/presets/pgi.cmake b/cmake/presets/pgi.cmake new file mode 100644 index 0000000000..b34cb05331 --- /dev/null +++ b/cmake/presets/pgi.cmake @@ -0,0 +1,16 @@ +# preset that will enable clang/clang++ with support for MPI and OpenMP (on Linux boxes) + +set(CMAKE_CXX_COMPILER "pgc++" CACHE STRING "" FORCE) +set(CMAKE_C_COMPILER "pgcc" CACHE STRING "" FORCE) +set(CMAKE_Fortran_COMPILER "pgfortran" CACHE STRING "" FORCE) +set(MPI_CXX "pgc++" CACHE STRING "" FORCE) +set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) +unset(HAVE_OMP_H_INCLUDE CACHE) + +set(OpenMP_C "pgcc" CACHE STRING "" FORCE) +set(OpenMP_C_FLAGS "-mp" CACHE STRING "" FORCE) +set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE) +set(OpenMP_CXX "pgc++" CACHE STRING "" FORCE) +set(OpenMP_CXX_FLAGS "-mp" CACHE STRING "" FORCE) +set(OpenMP_CXX_LIB_NAMES "omp" CACHE STRING "" FORCE) +set(OpenMP_omp_LIBRARY "libomp.so" CACHE PATH "" FORCE) diff --git a/doc/src/Build_basics.rst b/doc/src/Build_basics.rst index 8f40d3e5ba..cb6bd9f6aa 100644 --- a/doc/src/Build_basics.rst +++ b/doc/src/Build_basics.rst @@ -236,12 +236,15 @@ LAMMPS. cmake ../cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DCMAKE_Fortran_COMPILER=ifort # Building with LLVM/Clang Compilers: cmake ../cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_Fortran_COMPILER=flang + # Building with PGI/Nvidia Compilers: + cmake ../cmake -DCMAKE_C_COMPILER=pgcc -DCMAKE_CXX_COMPILER=pgc++ -DCMAKE_Fortran_COMPILER=pgfortran For compiling with the Clang/LLVM compilers a CMake preset is provided that can be loaded with `-C ../cmake/presets/clang.cmake`. Similarly, `-C ../cmake/presets/intel.cmake` should switch the compiler - toolchain to the Intel compilers. + toolchain to the Intel compilers and `-C ../cmake/presets/pgi.cmake` + should switch the compiler to the PGI compilers. In addition you can set ``CMAKE_TUNE_FLAGS`` to specifically add compiler flags to tune for optimal performance on given hosts. By diff --git a/doc/src/Build_package.rst b/doc/src/Build_package.rst index 18d9ab5f19..63312d7aa8 100644 --- a/doc/src/Build_package.rst +++ b/doc/src/Build_package.rst @@ -1,4 +1,5 @@ Include packages in build + ========================= In LAMMPS, a package is a group of files that enable a specific set of @@ -160,6 +161,7 @@ one of them as a starting point and customize it to your needs. cmake -C ../cmake/presets/clang.cmake [OPTIONS] ../cmake # change settings to use the Clang compilers by default cmake -C ../cmake/presets/gcc.cmake [OPTIONS] ../cmake # change settings to use the GNU compilers by default cmake -C ../cmake/presets/intel.cmake [OPTIONS] ../cmake # change settings to use the Intel compilers by default + cmake -C ../cmake/presets/pgi.cmake [OPTIONS] ../cmake # change settings to use the PGI compilers by default cmake -C ../cmake/presets/all_on.cmake [OPTIONS] ../cmake # enable all packages cmake -C ../cmake/presets/all_off.cmake [OPTIONS] ../cmake # disable all packages mingw64-cmake -C ../cmake/presets/mingw-cross.cmake [OPTIONS] ../cmake # compile with MinGW cross compilers diff --git a/src/fmt/os.h b/src/fmt/os.h index d44ea0c904..823173c8e3 100644 --- a/src/fmt/os.h +++ b/src/fmt/os.h @@ -375,7 +375,11 @@ struct ostream_params { }; } // namespace detail +#if defined(__PGI) +static detail::buffer_size buffer_size; +#else static constexpr detail::buffer_size buffer_size; +#endif // A fast output stream which is not thread-safe. class ostream final : private detail::buffer { diff --git a/src/info.cpp b/src/info.cpp index 63ea4dccce..085e4e65ea 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1179,6 +1179,8 @@ std::string Info::get_compiler_info() std::string buf; #if __clang__ buf = fmt::format("Clang C++ {}", __VERSION__); +#elif __PGI + buf = fmt::format("PGI C++ {}.{}",__PGIC__,__PGIC_MINOR__); #elif __INTEL_COMPILER double version = static_cast(__INTEL_COMPILER)*0.01; buf = fmt::format("Intel C++ {:.2f}.{} / {}", version, diff --git a/src/lmptype.h b/src/lmptype.h index e5dba94be0..264b93a329 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -268,6 +268,8 @@ The typecasts prevent compiler warnings about possible truncation issues. # define _noopt __attribute__((optnone)) #elif defined(__INTEL_COMPILER) # define _noopt +#elif defined(__PGI) +# define _noopt #elif defined(__GNUC__) # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) # if defined(_FORTIFY_SOURCE) && (_FORTIFY_SOURCE > 0) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index cb3f7d79a4..b9957c6732 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -32,7 +32,7 @@ #include #if !defined(_FORTIFY_SOURCE) || (_FORTIFY_SOURCE == 0) -#if defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) || (__PGI) #define _do_nothing #elif defined(__clang__) #pragma clang optimize off diff --git a/unittest/fortran/test_fortran_commands.f90 b/unittest/fortran/test_fortran_commands.f90 index 748bc5774a..b5cffe698f 100644 --- a/unittest/fortran/test_fortran_commands.f90 +++ b/unittest/fortran/test_fortran_commands.f90 @@ -1,12 +1,12 @@ MODULE keepcmds USE liblammps TYPE(LAMMPS) :: lmp - CHARACTER(len=*), DIMENSION(*), PARAMETER :: demo_input = & + CHARACTER(len=40), DIMENSION(3), PARAMETER :: demo_input = & [ CHARACTER(len=40) :: & 'region box block 0 $x 0 2 0 2', & 'create_box 1 box', & 'create_atoms 1 single 1.0 1.0 ${zpos}' ] - CHARACTER(len=*), DIMENSION(*), PARAMETER :: cont_input = & + CHARACTER(len=40), DIMENSION(2), PARAMETER :: cont_input = & [ CHARACTER(len=40) :: & 'create_atoms 1 single &', & ' 0.2 0.1 0.1' ] @@ -19,7 +19,7 @@ FUNCTION f_lammps_with_args() BIND(C, name="f_lammps_with_args") IMPLICIT NONE TYPE(c_ptr) :: f_lammps_with_args - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=12), DIMENSION(12), PARAMETER :: args = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none', & '-echo','screen','-nocite','-var','zpos','1.5','-var','x','2'] diff --git a/unittest/fortran/test_fortran_create.f90 b/unittest/fortran/test_fortran_create.f90 index 694646e9bd..e1df7502cb 100644 --- a/unittest/fortran/test_fortran_create.f90 +++ b/unittest/fortran/test_fortran_create.f90 @@ -22,7 +22,7 @@ FUNCTION f_lammps_no_mpi_with_args() BIND(C, name="f_lammps_no_mpi_with_args") IMPLICIT NONE TYPE(c_ptr) :: f_lammps_no_mpi_with_args - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=12), DIMENSION(4), PARAMETER :: args = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none', '-nocite' ] lmp = lammps(args) @@ -54,7 +54,7 @@ FUNCTION f_lammps_open_with_args() BIND(C, name="f_lammps_open_with_args") TYPE(c_ptr) :: f_lammps_open_with_args INTEGER :: color, key, ierr - CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = & + CHARACTER(len=12), DIMENSION(4), PARAMETER :: args = & [ CHARACTER(len=12) :: 'liblammps', '-log', 'none', '-nocite' ] color = 2 @@ -73,7 +73,7 @@ SUBROUTINE f_lammps_close() BIND(C, name="f_lammps_close") CALL lmp%close() lmp%handle = c_null_ptr END SUBROUTINE f_lammps_close - + FUNCTION f_lammps_get_comm() BIND(C, name="f_lammps_get_comm") USE liblammps USE keepcreate, ONLY: mycomm @@ -82,5 +82,3 @@ FUNCTION f_lammps_get_comm() BIND(C, name="f_lammps_get_comm") f_lammps_get_comm = mycomm END FUNCTION f_lammps_get_comm - - diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index 47fdbbfb2d..575b64252b 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -57,10 +57,13 @@ if (Python_EXECUTABLE) WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonOpen PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") - add_test(NAME PythonCommands - COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v - WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) - set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") + # some of the tests in this file will fail without exceptions enabled + if(LAMMPS_EXCEPTIONS) + add_test(NAME PythonCommands + COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") + endif() add_test(NAME PythonNumpy COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-numpy.py -v