Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 0 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,6 @@ if (CUDECOMP_BUILD_FORTRAN)

target_link_libraries(cudecomp_fort PUBLIC MPI::MPI_Fortran)

# Test for MPI_Comm_f2c/c2f
try_compile(
TEST_F2C_RESULT
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_mpi_f2c.f90
LINK_LIBRARIES MPI::MPI_Fortran
)
if (NOT TEST_F2C_RESULT)
message(STATUS "Could not link MPI_Comm_f2c in Fortran module. Setting -DMPICH flag during module compilation.")
target_compile_definitions(cudecomp_fort PRIVATE MPICH)
endif()

install(
TARGETS cudecomp_fort
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
Expand Down
48 changes: 0 additions & 48 deletions cmake/test_mpi_f2c.f90

This file was deleted.

8 changes: 8 additions & 0 deletions docs/api/c_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ ____________

------

.. _cudecompInit_F-ref:

cudecompInit_F
______________
.. doxygenfunction:: cudecompInit_F

------

.. _cudecompFinalize-ref:

cudecompFinalize
Expand Down
10 changes: 10 additions & 0 deletions include/cudecomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ typedef struct {
*/
cudecompResult_t cudecompInit(cudecompHandle_t* handle, MPI_Comm mpi_comm);

/**
* @brief Initializes the cuDecomp library from an existing MPI communicator
*
* @param[out] handle A pointer to an uninitialized cudecompHandle_t
* @param[in] mpi_comm_f MPI communicator, in Fortran integer format, containing ranks to use with cuDecomp
*
* @return CUDECOMP_RESULT_SUCCESS on success or error code on failure.
*/
cudecompResult_t cudecompInit_F(cudecompHandle_t* handle, MPI_Fint mpi_comm_f);

/**
* @brief Finalizes the cuDecomp library and frees associated resources
*
Expand Down
12 changes: 12 additions & 0 deletions src/cudecomp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,18 @@ cudecompResult_t cudecompFinalize(cudecompHandle_t handle) {
return CUDECOMP_RESULT_SUCCESS;
}

cudecompResult_t cudecompInit_F(cudecompHandle_t* handle_in, MPI_Fint mpi_comm_f) {
using namespace cudecomp;
try {
MPI_Comm mpi_comm = MPI_Comm_f2c(mpi_comm_f);
cudecompInit(handle_in, mpi_comm);
} catch (const cudecomp::BaseException& e) {
std::cerr << e.what();
return e.getResult();
}
return CUDECOMP_RESULT_SUCCESS;
}

cudecompResult_t cudecompGridDescCreate(cudecompHandle_t handle, cudecompGridDesc_t* grid_desc_in,
cudecompGridDescConfig_t* config,
const cudecompGridDescAutotuneOptions_t* options) {
Expand Down
68 changes: 7 additions & 61 deletions src/cudecomp_m.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,6 @@ module cudecomp

! types

! MPI-related types
#ifndef MPICH
type, bind(c) :: MPI_C_Comm
integer(c_int64_t) :: comm
end type MPI_C_Comm
#else
type, bind(c) :: MPI_C_Comm
integer(c_int) :: comm
end type MPI_C_Comm
#endif

type, bind(c) :: MPI_F_Comm
integer(c_int) :: comm
end type MPI_F_Comm

! Opaque handle to cuDecomp handle
type, bind(c) :: cudecompHandle
type(c_ptr) :: member
Expand Down Expand Up @@ -155,37 +140,20 @@ module cudecomp

! interfaces

! MPI_Comm conversion functions
#ifndef MPICH
interface
function MPI_Comm_f2c(fcomm) bind(C,name='MPI_Comm_f2c') result(res)
import
type(MPI_F_comm), value :: fcomm
type(MPI_C_comm) :: res
end function MPI_Comm_f2c

function MPI_Comm_c2f(ccomm) bind(C,name='MPI_Comm_c2f') result(res)
import
type(MPI_C_Comm), value :: ccomm
type(MPI_F_Comm) :: res
end function MPI_Comm_c2f
end interface
#endif

! cuDecomp initialization/finalization functions
! generic interface that takes either integer or type(MPI_F_Comm) communicator arguments
! generic interface that takes either integer or type(MPI_Comm) communicator arguments

interface cudecompInit
module procedure cudecompInit_MPI_F, cudecompInit_MPI_F08, cudecompInitType
module procedure cudecompInit_MPI_F, cudecompInit_MPI_F08
end interface cudecompInit

interface
function cudecompInitC(handle, mpi_comm) bind(C, name="cudecompInit") result(res)
function cudecompInit_FC(handle, mpi_comm) bind(C, name="cudecompInit_F") result(res)
import
type(cudecompHandle) :: handle
type(MPI_C_Comm), value :: mpi_comm ! conversion to MPI_C_Comm done in module procedures cudecompInit*()
integer, value :: mpi_comm
integer(c_int) :: res
end function cudecompInitC
end function cudecompInit_FC
end interface

interface
Expand Down Expand Up @@ -523,10 +491,7 @@ contains
integer :: comm
integer(c_int) :: res

type(MPI_F_Comm) :: fComm

fComm%comm = comm
res = cudecompInitType(handle, fComm)
res = cudecompInit_FC(handle, comm)
end function cudecompInit_MPI_F

function cudecompInit_MPI_F08(handle, comm) result(res)
Expand All @@ -538,28 +503,9 @@ contains
type(MPI_Comm) :: comm
integer(c_int) :: res

type(MPI_F_Comm) :: fComm

fComm%comm = comm%MPI_VAL
res = cudecompInitType(handle, fComm)
res = cudecompInit_FC(handle, comm%MPI_VAL)
end function cudecompInit_MPI_F08

function cudecompInitType(handle, fComm) result(res)
implicit none
type(cudecompHandle) :: handle
type(MPI_F_Comm) :: fComm
integer(c_int) :: res

type(MPI_C_Comm) :: cComm
#ifndef MPICH
cComm = MPI_Comm_f2c(fComm)
#else
cComm= fComm
#endif

res = cudecompInitC(handle, cComm)
end function cudecompInitType

! cudecompGridDesc creation/manipulation functions
function cudecompGridDescAutotuneOptionsSetDefaults(options) result(res)
type(cudecompGridDescAutotuneOptions) :: options
Expand Down