From 70e4d439da2f1aa01a3377df2d7ae654a98b4d07 Mon Sep 17 00:00:00 2001 From: "Thomas L. Clune" Date: Fri, 30 Aug 2024 09:51:52 -0400 Subject: [PATCH] Fixes mock issue for testing with LLVM --- CMakeLists.txt | 7 +------ ChangeLog.md | 1 + src/CMakeLists.txt | 21 ++++++++------------- src/MockMpi.F90 | 43 ++++++++++++++++++++++++------------------- src/MpiLock.F90 | 6 +++--- tests/CMakeLists.txt | 7 +++++-- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d28ba4..aa12a9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,12 +68,7 @@ if (PFUNIT_FOUND) if (NOT TARGET tests) add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND}) endif () - # We found issues between LLVMFlang, tests, and MPI. Until - # this can be more fully explored, for now do not run the tests - # with LLVMFlang. - if (NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang") - add_subdirectory(tests EXCLUDE_FROM_ALL) - endif () + add_subdirectory(tests EXCLUDE_FROM_ALL) endif() add_subdirectory(examples EXCLUDE_FROM_ALL) diff --git a/ChangeLog.md b/ChangeLog.md index 895beab..d5ed8c7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Modified CMake logic to build entirely separate library (pflogger-with-mock) to support testing with mocks. Previous cheat to link pflogger against real MPI for runs but mock MPI for tests did not work with LLVM. Seems to be due to some encryption type protection on module info. - Update CI to have `gfortran-10` and `gfortran-11` only on `ubuntu-22.04` - Update CI NVIDIA to NVHPC 24.7 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 718fa10..2a2b484 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,35 +73,30 @@ if (MPI_FOUND) if (SUPPORT_FOR_MPI_ALLOC_MEM_CPTR) target_compile_definitions(${this} PRIVATE SUPPORT_FOR_MPI_ALLOC_MEM_CPTR) endif () + target_link_libraries (${this} PUBLIC MPI::MPI_Fortran) endif () if (MPI_FOUND) if (PFUNIT_FOUND) + add_library (pflogger-with-mock STATIC ${SRCS}) + set_target_properties(pflogger-with-mock PROPERTIES Fortran_MODULE_DIRECTORY ${PFLOGGER_BINARY_DIR}/mock-mpi) add_library (mock-mpi MockMpi.F90) set_target_properties(mock-mpi PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mock-mpi) # target_include_directories (mock-mpi PUBLIC ${MPI_Fortran_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/mock-mpi) target_include_directories (mock-mpi PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mock-mpi) target_include_directories (mock-mpi PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) - target_link_libraries (mock-mpi PUBLIC PFUNIT::funit) if (SUPPORT_FOR_C_LOC_ASSUMED_SIZE) target_compile_definitions(mock-mpi PRIVATE -DSUPPORT_FOR_C_LOC_ASSUMED_SIZE) endif () - # Complex linkage depending on target: - set(isTest $,1>) - set(notTest $) - - target_link_libraries (pflogger PUBLIC -# $ - $<${notTest}:MPI::MPI_Fortran> - $<${isTest}:mock-mpi> - $<${isTest}:PFUNIT::funit>) + target_link_libraries (mock-mpi PUBLIC PFUNIT::funit) + target_link_libraries (pflogger-with-mock + PUBLIC mock-mpi GFTL_SHARED::gftl-shared GFTL::gftl-v2 YAFYAML::yafyaml) + message("HUH: ${PFLOGGER_BINARY_DIR}/mock-mpi") + target_include_directories(pflogger-with-mock PUBLIC ${PFLOGGER_BINARY_DIR}/mock-mpi ${CMAKE_CURRENT_SOURCE_DIR}) - else () - target_link_libraries (pflogger PRIVATE MPI::MPI_Fortran) endif () - endif() diff --git a/src/MockMpi.F90 b/src/MockMpi.F90 index d14b746..f3cfed2 100644 --- a/src/MockMpi.F90 +++ b/src/MockMpi.F90 @@ -9,7 +9,8 @@ module mpi public :: set_mpi_rank public :: set_mpi_size public :: verify - + + public :: MPI_COMM_WORLD public :: MPI_ADDRESS_KIND public :: MPI_STATUS_SIZE public :: MPI_STATUS_IGNORE @@ -17,7 +18,11 @@ module mpi public :: MPI_SUCCESS public :: MPI_INFO_NULL public :: MPI_ANY_SOURCE + public :: MPI_LOCK_EXCLUSIVE + + public :: MPI_WIN_CREATE + integer, parameter :: MPI_COMM_WORLD = 0 integer, parameter :: MPI_ADDRESS_KIND = INT64 integer, parameter :: MPI_STATUS_SIZE = 6 integer, parameter :: MPI_STATUS_IGNORE(MPI_STATUS_SIZE) = reshape([0], shape=[MPI_STATUS_SIZE], pad=[0]) @@ -25,7 +30,7 @@ module mpi integer, parameter :: MPI_SUCCESS = 0 integer, parameter :: MPI_INFO_NULL = 0 integer, parameter :: MPI_ANY_SOURCE = -1 - + integer, parameter :: MPI_LOCK_EXCLUSIVE = 1 public :: MPI_Alloc_mem public :: MPI_Type_indexed @@ -67,6 +72,10 @@ end subroutine MPI_Type_commit end interface MPI_Type_Commit + interface MPI_Win_create + procedure :: win_create_1 +!!$ procedure :: win_create_2 + end interface MPI_Win_create type MockMpi integer :: rank @@ -160,7 +169,19 @@ subroutine verify() end subroutine verify - + subroutine Win_create_1(base, size, disp_unit, info, comm, win, ierror) +#ifdef SUPPORT_FOR_ASSUMED_TYPE + type(*) :: base(*) +#else + logical :: base(*) +#endif + integer(kind=MPI_ADDRESS_KIND) size + integer disp_unit, info, comm, win, ierror + + ierror = MPI_SUCCESS + mocker%call_count = mocker%call_count + 1 + + end subroutine Win_create_1 end module mpi @@ -363,22 +384,6 @@ subroutine MPI_Free_mem(base, ierror) end subroutine MPI_Free_mem -subroutine MPI_Win_create(base, size, disp_unit, info, comm, win, ierror) - use mpi -#ifdef SUPPORT_FOR_ASSUMED_TYPE - type(*) :: base(*) -#else - logical :: base(*) -#endif - integer(kind=MPI_ADDRESS_KIND) size - integer disp_unit, info, comm, win, ierror - - ierror = MPI_SUCCESS - mocker%call_count = mocker%call_count + 1 - -end subroutine MPI_Win_create - - ! This one is just a stub for now subroutine MPI_Comm_dup(comm, newcomm, ierror) use mpi diff --git a/src/MpiLock.F90 b/src/MpiLock.F90 index 7be86e2..4a03ce4 100644 --- a/src/MpiLock.F90 +++ b/src/MpiLock.F90 @@ -6,7 +6,7 @@ module PFL_MpiLock use PFL_Exception use PFL_AbstractLock use iso_fortran_env, only: INT64 - use iso_c_binding, only: c_ptr, c_f_pointer + use iso_c_binding, only: c_ptr, c_f_pointer, c_bool implicit none private @@ -90,7 +90,7 @@ subroutine init(this, rc) if (this%rank == 0) then block - logical, pointer :: scratchpad(:) + logical(kind=C_BOOL), pointer :: scratchpad(:) integer :: sizeof_logical call MPI_Type_extent(MPI_LOGICAL, sizeof_logical, status) @@ -210,7 +210,7 @@ subroutine destroy(this, rc) class (MpiLock), intent(inout) :: this integer, optional, intent(out) :: rc - logical, pointer :: scratchpad(:) + logical(kind=C_BOOL), pointer :: scratchpad(:) integer :: status ! Release resources diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a62c8f2..41d2c1d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,11 +40,14 @@ if (MPI_FOUND) endif () endif () -set (link_libraries pflogger GFTL_SHARED::gftl-shared GFTL::gftl-v2) +set (link_libraries GFTL_SHARED::gftl-shared GFTL::gftl mock-mpi) if (MPI_FOUND) - list(APPEND link_libraries mock-mpi) + list (APPEND link_libraries pflogger-with-mock) +else () + list (APPEND link_libraries pflogger) endif() +message("Link libs: ${link_libraries}") add_pfunit_ctest (pflogger_tests.x TEST_SOURCES ${pf_tests} OTHER_SOURCES ${srcs}