21.1.3. Prototype Definitions

PreviousUpNext
Up: Defined Values and Handless Next: C Bindings Previous: Types


PreviousUpNext
Up: Defined Values and Handless Next: C Bindings Previous: Types


21.1.3.1. C Bindings

PreviousUpNext
Up: Prototype Definitions Next: Fortran 2008 Bindings with the mpi_f08 Module Previous: Prototype Definitions

The following are defined C typedefs for user-defined functions, also included in the file mpi.h.


/* prototypes for user-defined functions */ 
typedef void MPI_User_function(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype);
typedef void MPI_User_function_c(void *invec, void *inoutvec, MPI_Count *len, MPI_Datatype *datatype);

typedef int MPI_Comm_copy_attr_function(MPI_Comm oldcomm, int comm_keyval, void *extra_state, void *attribute_val_in, void *attribute_val_out, int *flag);
typedef int MPI_Comm_delete_attr_function(MPI_Comm comm, int comm_keyval, void *attribute_val, void *extra_state);

typedef int MPI_Win_copy_attr_function(MPI_Win oldwin, int win_keyval, void *extra_state, void *attribute_val_in, void *attribute_val_out, int *flag);
typedef int MPI_Win_delete_attr_function(MPI_Win win, int win_keyval, void *attribute_val, void *extra_state);

typedef int MPI_Type_copy_attr_function(MPI_Datatype oldtype, int type_keyval, void *extra_state, void *attribute_val_in, void *attribute_val_out, int *flag);
typedef int MPI_Type_delete_attr_function(MPI_Datatype datatype, int type_keyval, void *attribute_val, void *extra_state);

typedef void MPI_Comm_errhandler_function(MPI_Comm *comm, int *error_code, ...);
typedef void MPI_Win_errhandler_function(MPI_Win *win, int *error_code, ...);
typedef void MPI_File_errhandler_function(MPI_File *file, int *error_code, ...);
typedef void MPI_Session_errhandler_function(MPI_Session *session, int *error_code, ...);

typedef int MPI_Grequest_query_function(void *extra_state, MPI_Status *status);
typedef int MPI_Grequest_free_function(void *extra_state);
typedef int MPI_Grequest_cancel_function(void *extra_state, int complete);

typedef int MPI_Datarep_extent_function(MPI_Datatype datatype, MPI_Aint *extent, void *extra_state);
typedef int MPI_Datarep_conversion_function(void *userbuf, MPI_Datatype datatype, int count, void *filebuf, MPI_Offset position, void *extra_state);
typedef int MPI_Datarep_conversion_function_c(void *userbuf, MPI_Datatype datatype, MPI_Count count, void *filebuf, MPI_Offset position, void *extra_state);

typedef void MPI_T_event_cb_function(MPI_T_event_instance event_instance, MPI_T_event_registration event_registration, MPI_T_cb_safety cb_safety, void *user_data);
typedef void MPI_T_event_free_cb_function(MPI_T_event_registration event_registration, MPI_T_cb_safety cb_safety, void *user_data);
typedef void MPI_T_event_dropped_cb_function(MPI_Count count, MPI_T_event_registration event_registration, int source_index, MPI_T_cb_safety cb_safety, void *user_data);


PreviousUpNext
Up: Prototype Definitions Next: Fortran 2008 Bindings with the mpi_f08 Module Previous: Prototype Definitions


21.1.3.2. Fortran 2008 Bindings with the mpi_f08 Module

PreviousUpNext
Up: Prototype Definitions Next: Fortran Bindings with mpif.h or the mpi Modulee Previous: C Bindings

The callback prototypes when using the Fortran mpi_f08 module are shown below:

The user-function argument to MPI_Op_create and MPI_Op_create_c should be declared according to:

ABSTRACT INTERFACE
    SUBROUTINE MPI_User_function(invec, inoutvec, len, datatype)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
TYPE(C_PTR), VALUE :: invec, inoutvec
INTEGER :: len
TYPE(MPI_Datatype) :: datatype
ABSTRACT INTERFACE
    SUBROUTINE MPI_User_function_c(invec, inoutvec, len, datatype) !(_c)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
TYPE(C_PTR), VALUE :: invec, inoutvec
INTEGER(KIND=MPI_COUNT_KIND) :: len
TYPE(MPI_Datatype) :: datatype

The copy and delete function arguments to MPI_Comm_create_keyval should be declared according to:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Comm_copy_attr_function(oldcomm, comm_keyval, extra_state, attribute_val_in, attribute_val_out, flag, ierror)

TYPE(MPI_Comm) :: oldcomm
INTEGER :: comm_keyval, ierror
INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state, attribute_val_in, attribute_val_out
LOGICAL :: flag
ABSTRACT INTERFACE
    SUBROUTINE MPI_Comm_delete_attr_function(comm, comm_keyval, attribute_val, extra_state, ierror)

TYPE(MPI_Comm) :: comm
INTEGER :: comm_keyval, ierror
INTEGER(KIND=MPI_ADDRESS_KIND) :: attribute_val, extra_state

The copy and delete function arguments to MPI_Win_create_keyval should be declared according to:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Win_copy_attr_function(oldwin, win_keyval, extra_state, attribute_val_in, attribute_val_out, flag, ierror)

TYPE(MPI_Win) :: oldwin
INTEGER :: win_keyval, ierror
INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state, attribute_val_in, attribute_val_out
LOGICAL :: flag
ABSTRACT INTERFACE
    SUBROUTINE MPI_Win_delete_attr_function(win, win_keyval, attribute_val, extra_state, ierror)

TYPE(MPI_Win) :: win
INTEGER :: win_keyval, ierror
INTEGER(KIND=MPI_ADDRESS_KIND) :: attribute_val, extra_state

The copy and delete function arguments to MPI_Type_create_keyval should be declared according to:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Type_copy_attr_function(oldtype, type_keyval, extra_state, attribute_val_in, attribute_val_out, flag, ierror)

TYPE(MPI_Datatype) :: oldtype
INTEGER :: type_keyval, ierror
INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state, attribute_val_in, attribute_val_out
LOGICAL :: flag
ABSTRACT INTERFACE
    SUBROUTINE MPI_Type_delete_attr_function(datatype, type_keyval, attribute_val, extra_state, ierror)

TYPE(MPI_Datatype) :: datatype
INTEGER :: type_keyval, ierror
INTEGER(KIND=MPI_ADDRESS_KIND) :: attribute_val, extra_state

The handler-function argument to MPI_Comm_create_errhandler should be declared like this:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Comm_errhandler_function(comm, error_code)

TYPE(MPI_Comm) :: comm
INTEGER :: error_code

The handler-function argument to MPI_Win_create_errhandler should be declared like this:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Win_errhandler_function(win, error_code)

TYPE(MPI_Win) :: win
INTEGER :: error_code

The handler-function argument to MPI_File_create_errhandler should be declared like this:

ABSTRACT INTERFACE
    SUBROUTINE MPI_File_errhandler_function(file, error_code)

TYPE(MPI_File) :: file
INTEGER :: error_code

The handler-function argument to MPI_Session_create_errhandler should be declared like this:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Session_errhandler_function(session, error_code)

TYPE(MPI_Session) :: session
INTEGER :: error_code

The query, free, and cancel function arguments to MPI_Grequest_start should be declared according to:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Grequest_query_function(extra_state, status, ierror)

INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state
TYPE(MPI_Status) :: status
INTEGER :: ierror
ABSTRACT INTERFACE
    SUBROUTINE MPI_Grequest_free_function(extra_state, ierror)

INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state
INTEGER :: ierror
ABSTRACT INTERFACE
    SUBROUTINE MPI_Grequest_cancel_function(extra_state, complete, ierror)

INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state
LOGICAL :: complete
INTEGER :: ierror

The extent and conversion function arguments to MPI_Register_datarep and MPI_Register_datarep_c should be declared according to:

ABSTRACT INTERFACE
    SUBROUTINE MPI_Datarep_extent_function(datatype, extent, extra_state, ierror)

TYPE(MPI_Datatype) :: datatype
INTEGER(KIND=MPI_ADDRESS_KIND) :: extent, extra_state
INTEGER :: ierror
ABSTRACT INTERFACE
    SUBROUTINE MPI_Datarep_conversion_function(userbuf, datatype, count, filebuf, position, extra_state, ierror)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
TYPE(C_PTR), VALUE :: userbuf, filebuf
TYPE(MPI_Datatype) :: datatype
INTEGER :: count, ierror
INTEGER(KIND=MPI_OFFSET_KIND) :: position
INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state
ABSTRACT INTERFACE
    SUBROUTINE MPI_Datarep_conversion_function_c(userbuf, datatype, count, filebuf, position, extra_state, ierror) !(_c)

USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR
TYPE(C_PTR), VALUE :: userbuf, filebuf
TYPE(MPI_Datatype) :: datatype
INTEGER(KIND=MPI_COUNT_KIND) :: count
INTEGER(KIND=MPI_OFFSET_KIND) :: position
INTEGER(KIND=MPI_ADDRESS_KIND) :: extra_state
INTEGER :: ierror


PreviousUpNext
Up: Prototype Definitions Next: Fortran Bindings with mpif.h or the mpi Modulee Previous: C Bindings


21.1.3.3. Fortran Bindings with mpif.h or the mpi Modulee

PreviousUpNext
Up: Prototype Definitions Next: Deprecated Prototype Definitions Previous: Fortran 2008 Bindings with the mpi_f08 Module

With the Fortran mpi module or (deprecated) mpif.h, here are examples of how each of the user-defined subroutines should be declared.

The user-function argument to MPI_OP_CREATE should be declared like this:

SUBROUTINE USER_FUNCTION(INVEC, INOUTVEC, LEN, DATATYPE)

<type> INVEC(LEN), INOUTVEC(LEN)
INTEGER LEN, DATATYPE

The copy and delete function arguments to MPI_COMM_CREATE_KEYVAL should be declared like these:

SUBROUTINE COMM_COPY_ATTR_FUNCTION(OLDCOMM, COMM_KEYVAL, EXTRA_STATE, ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT, FLAG, IERROR)

INTEGER OLDCOMM, COMM_KEYVAL, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE, ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT
LOGICAL FLAG
SUBROUTINE COMM_DELETE_ATTR_FUNCTION(COMM, COMM_KEYVAL, ATTRIBUTE_VAL, EXTRA_STATE, IERROR)

INTEGER COMM, COMM_KEYVAL, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) ATTRIBUTE_VAL, EXTRA_STATE

The copy and delete function arguments to MPI_WIN_CREATE_KEYVAL should be declared like these:

SUBROUTINE WIN_COPY_ATTR_FUNCTION(OLDWIN, WIN_KEYVAL, EXTRA_STATE, ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT, FLAG, IERROR)

INTEGER OLDWIN, WIN_KEYVAL, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE, ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT
LOGICAL FLAG
SUBROUTINE WIN_DELETE_ATTR_FUNCTION(WIN, WIN_KEYVAL, ATTRIBUTE_VAL, EXTRA_STATE, IERROR)

INTEGER WIN, WIN_KEYVAL, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) ATTRIBUTE_VAL, EXTRA_STATE

The copy and delete function arguments to MPI_TYPE_CREATE_KEYVAL should be declared like these:

SUBROUTINE TYPE_COPY_ATTR_FUNCTION(OLDTYPE, TYPE_KEYVAL, EXTRA_STATE, ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT, FLAG, IERROR)

INTEGER OLDTYPE, TYPE_KEYVAL, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE, ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT
LOGICAL FLAG
SUBROUTINE TYPE_DELETE_ATTR_FUNCTION(DATATYPE, TYPE_KEYVAL, ATTRIBUTE_VAL, EXTRA_STATE, IERROR)

INTEGER DATATYPE, TYPE_KEYVAL, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) ATTRIBUTE_VAL, EXTRA_STATE

The handler-function argument to MPI_COMM_CREATE_ERRHANDLER should be declared like this:

SUBROUTINE COMM_ERRHANDLER_FUNCTION(COMM, ERROR_CODE)

INTEGER COMM, ERROR_CODE

The handler-function argument to MPI_WIN_CREATE_ERRHANDLER should be declared like this:

SUBROUTINE WIN_ERRHANDLER_FUNCTION(WIN, ERROR_CODE)

INTEGER WIN, ERROR_CODE

The handler-function argument to MPI_FILE_CREATE_ERRHANDLER should be declared like this:

SUBROUTINE FILE_ERRHANDLER_FUNCTION(FILE, ERROR_CODE)

INTEGER FILE, ERROR_CODE

The handler-function argument to MPI_SESSION_CREATE_ERRHANDLER should be declared like this:

SUBROUTINE SESSION_ERRHANDLER_FUNCTION(SESSION, ERROR_CODE)

INTEGER SESSION, ERROR_CODE

The query, free, and cancel function arguments to MPI_GREQUEST_START should be declared like these:

SUBROUTINE GREQUEST_QUERY_FUNCTION(EXTRA_STATE, STATUS, IERROR)

INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE
INTEGER STATUS(MPI_STATUS_SIZE), IERROR
SUBROUTINE GREQUEST_FREE_FUNCTION(EXTRA_STATE, IERROR)

INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE
INTEGER IERROR
SUBROUTINE GREQUEST_CANCEL_FUNCTION(EXTRA_STATE, COMPLETE, IERROR)

INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE
LOGICAL COMPLETE
INTEGER IERROR

The extent and conversion function arguments to MPI_REGISTER_DATAREP should be declared like these:

SUBROUTINE DATAREP_EXTENT_FUNCTION(DATATYPE, EXTENT, EXTRA_STATE, IERROR)

INTEGER DATATYPE, IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) EXTENT, EXTRA_STATE
SUBROUTINE DATAREP_CONVERSION_FUNCTION(USERBUF, DATATYPE, COUNT, FILEBUF, POSITION, EXTRA_STATE, IERROR)

<TYPE> USERBUF(*), FILEBUF(*)
INTEGER DATATYPE, COUNT, IERROR
INTEGER(KIND=MPI_OFFSET_KIND) POSITION
INTEGER(KIND=MPI_ADDRESS_KIND) EXTRA_STATE


PreviousUpNext
Up: Prototype Definitions Next: Deprecated Prototype Definitions Previous: Fortran 2008 Bindings with the mpi_f08 Module


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023