假设我有一个 MPI 派生类型,Fortran 代码中的 type_a
。我想要它的第二个副本,type_b
。之间有实际区别吗
call mpi_type_dup(type_a, type_b, err)
和
type_b = type_a
?
我不想更改 MPI 标准提到的任何“关联键值”。
其中一个是否优先于另一个?另外,如果 type_a
已经提交,我还需要提交 type_b
吗?
最佳答案
在 Fortran 中,派生数据类型是整数(如果使用 mpi_f08
绑定(bind),则该数据类型是抽象的。
如果您type_b=type_a
,则在使用它进行通信之前不必提交type_b
,但如果您稍后调用 mpi_type_free(type_a)
,则type_b
不能再使用。
如果您复制 type_a
,那么您必须在使用它进行通信之前提交 type_b
,这两种类型都是独立的,并且当它们不再存在时必须将其释放需要。
关于“关联键值”
MPI_Type_dup is a type constructor that duplicates the existing type with associated key values. For each key value, the respective copy callback function determines the attribute value associated with this key in the new communicator. One particular action that a copy callback may take is to delete the attribute from the new data type.
因此,只要所有复制回调函数都保留了属性,就可以使用该子例程。
如果您知道使用 type_b
时 type_a
不会被释放,那么 type_b=type_a
就简单多了高效。
关于fortran - 复制 MPI 派生类型与将一种类型设置为等于另一种类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57210186/