Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes mock issue for testing with LLVM #135

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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

20 changes: 7 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -73,35 +73,29 @@ 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 $<STREQUAL:$<TARGET_PROPERTY:IS_TEST>,1>)
set(notTest $<NOT:${isTest}>)

target_link_libraries (pflogger PUBLIC
# $<BUILD_INTERFACE:mock-mpi>
$<${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)
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()


43 changes: 24 additions & 19 deletions src/MockMpi.F90
Original file line number Diff line number Diff line change
@@ -9,23 +9,28 @@ 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
public :: MPI_LOGICAL
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])
integer, parameter :: MPI_LOGICAL = 9
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
6 changes: 3 additions & 3 deletions src/MpiLock.F90
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -40,9 +40,11 @@ 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)
if (MPI_FOUND)
list(APPEND link_libraries mock-mpi)
list (APPEND link_libraries pflogger-with-mock mock-mpi)
else ()
list (APPEND link_libraries pflogger)
endif()

add_pfunit_ctest (pflogger_tests.x