复制 MPI 派生类型与将一种类型设置为等于另一种类型

Duplicating an MPI derived type vs. setting one type equal to another

假设我在 Fortran 代码中有一个 MPI 派生类型 type_a。我想要它的第二个副本,type_b

之间有实际区别吗
call mpi_type_dup(type_a, type_b, err)

type_b = type_a ?

我不想更改 MPI 标准提到的任何 "associated key values"。

其中之一优于另一个吗?另外,如果 type_a 已经提交,我还需要提交 type_b 吗?

在 Fortran 中,派生数据类型是一个整数(如果您使用 mpi_f08 绑定,它会被抽象化。

如果你type_b=type_a,那么你在使用它进行通信之前不必提交type_b,但是如果你以后call mpi_type_free(type_a),那么type_b就不能使用了没有了。

如果您重复 type_a,那么您必须在使用它进行通信之前提交 type_b,这两种类型都是独立的,并且在不再需要它们时都必须释放它们。

关于 "associated key values"

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_a 在使用 type_b 时不会被释放,那么 type_b=type_a 会更简单、更有效。