参照 MPI_Scatterv
的 man 文档,做了一个示例程序。
输出的效果是,将一个数组中的数组分散到 4 个进程,每个进程收到的数据长度不同,并且有重叠部分:
[mindle@master shared_folder]$ mpicc MPIScatterv_demo.c
[mindle@master shared_folder]$ mpirun -n 4 ./a.out
Sum data at rank 0 = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
Scattered data at rank 0 = {
1, 2, 3}
Scattered data at rank 1 = {
3, 4, 5, 6}
Scattered data at rank 2 = {
6, 7, 8, 9, 10}
Scattered data at rank 3 = {
10, 11, 12, 13, 14, 15}
int MPI_Scatterv(const void *sendbuf, const int *sendcounts, const int *displs,
MPI_Datatype sendtype, void *recvbuf, int recvcount,
MPI_Datatype recvtype,
int root, MPI_Comm comm)
- sendbuf:address of send buffer (choice, significant only at root)
- sendcounts:integer array (of length group size) specifying the number of elements to send to each processor
- displs:integer array (of length group size). Entry i specifies the displacement (relative to sendbuf from which to take the outgoing data to process i
- sendtype: data type of send buffer elements (handle)
- recvcount: number of elements in receive buffer (integer)
- recvtype:data type of receive buffer elements (handle)
- root:rank of sending process (integer)
- comm:communicator (handle)
示例程序(MPIScatterv_demo.c):
#include <stdio.h>
#include <stdlib.h>