MPI send derived data type with pointer in Fortran 90

放肆的年华 提交于 2019-12-24 07:45:41

问题


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.



来源:https://stackoverflow.com/questions/18830608/mpi-send-derived-data-type-with-pointer-in-fortran-90

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!