MPI学习(四)-广播、散播、收集、归约和全归约的MPI语法

MPI-广播、散播、收集、归约和全归约的MPI语法

广播:MPI_Bcast

1
2
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
//int root 广播数据的根进程的标识号(整型)

散播:MPI_Scatter

1
2
3
4
int MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int root, MPI_Comm comm)
//void *sendbuf 发送消息缓冲区的起始地址(可选数据类型)
//void *recvbuf 接收消息缓冲区的起始地址(可选数据类型)

收集:MPI_Gather

1
int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)

归约:MPI_Reduce

1
2
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,  MPI_Comm comm)
//MPI_Op op 归约操作符(句柄)

全归约:MPI_Allreduce

1
int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)