为什么使用 `MPI_Type_vector` 来指定步幅差距?
Why using `MPI_Type_vector` for specifying a stride gap?
在 MPI 文档中,我读到 MPI_Type_vector
和 MPI_Type_contiguos
之间的区别是第一个允许指定数组元素之间的步幅间隙。
为什么人们应该有兴趣这样做而不是简单地使用 MPI_Type_contiguous
?
您可以将 MPI_Type_contiguous()
视为 MPI_Type_vector()
的特例,没有步幅。
例如,在 Fortran 中,数组以列为主。所以如果你考虑下面的数组
integer :: A(n,m)
列的派生数据类型可以通过
获得
CALL MPI_Type_contiguous(n, MPI_INTEGER, newtype, ierr)
或
CALL MPI_Type_vector(n, 1, 1, MPI_INTEGER, newtype, ierr)
或
CALL MPI_Type_vector(1, n, n, MPI_INTEGER, newtype, ierr)
但是描述一行的唯一方法是通过 MPI_Type_vector()
CALL MPI_Type_vector(m, 1, n, MPI_INTEGER, newtype, ierr)
请注意,如果您想一次 send/receive 多行,则需要调整数据类型的大小,因此完整序列为
CALL MPI_Type_vector(m, 1, n, MPI_INTEGER, tmptype, ierr)
CALL MPI_Type_size(MPI_INTEGER, integer_size, ierr)
CALL MPI_Type_create_resized(tmptype, 0, integer_size, newtype, ierr)
CALL MPI_Type_free(tmptype, ierr)
在 MPI 文档中,我读到 MPI_Type_vector
和 MPI_Type_contiguos
之间的区别是第一个允许指定数组元素之间的步幅间隙。
为什么人们应该有兴趣这样做而不是简单地使用 MPI_Type_contiguous
?
您可以将 MPI_Type_contiguous()
视为 MPI_Type_vector()
的特例,没有步幅。
例如,在 Fortran 中,数组以列为主。所以如果你考虑下面的数组
integer :: A(n,m)
列的派生数据类型可以通过
获得CALL MPI_Type_contiguous(n, MPI_INTEGER, newtype, ierr)
或
CALL MPI_Type_vector(n, 1, 1, MPI_INTEGER, newtype, ierr)
或
CALL MPI_Type_vector(1, n, n, MPI_INTEGER, newtype, ierr)
但是描述一行的唯一方法是通过 MPI_Type_vector()
CALL MPI_Type_vector(m, 1, n, MPI_INTEGER, newtype, ierr)
请注意,如果您想一次 send/receive 多行,则需要调整数据类型的大小,因此完整序列为
CALL MPI_Type_vector(m, 1, n, MPI_INTEGER, tmptype, ierr)
CALL MPI_Type_size(MPI_INTEGER, integer_size, ierr)
CALL MPI_Type_create_resized(tmptype, 0, integer_size, newtype, ierr)
CALL MPI_Type_free(tmptype, ierr)