MPI send derived data type with pointer in Fortran

2019-08-10 19:20发布

问题:

I would like to send a user defined data type as:

TYPE CELL
    INTEGER :: NUM
    TYPE(CELL), POINTER :: NEXT => NULL()
END TYPE CELL

TYPE CELLLIST
    INTEGER :: NBCELL
    TYPE(CELL), POINTER :: BEGIN => NULL()
END TYPE CELLLIST

and the variable to be sent by MPI is defined as:

TYPE(CELLLIST) :: _CELLLIST

In this variable, _CELLIST%NBCELL denotes the length of the list, and a pointer of type CELL points to the head of the list.

I'd like to use MPI_send and MPI_recv to transfer the cell list via MPI. How to do that?

回答1:

Sending pointers from one MPI process to another is pointless.

The problem is that they, pointers, are process-specific. It's a reasonable analogy to think of a pointer as storing the memory address of its target. That memory address isn't portable, there is no concept of an address in one process's address space being the same as an address in another process's address space.

You will have to unravel the chain of pointers in your _CELLLIST, send across the CELLS, then rebuild the pointer chain on the target process(es).

I suppose that you might pack the CELLS into an array for transfer. Or you might send one CELL at a time on the understanding that the receiving process(es) will rebuild the dynamic data structure in the order in which it receives the messages containing the CELLs.



标签: mpi fortran90