MPI学习小结

PhoenixGS
Jul 19, 2022
Last edited: 2022-7-19
type
Post
status
Published
date
Jul 19, 2022
slug
mpi
summary
对使用MPI时需要用到的各种函数等进行整理
tags
CS
高性能计算
category
icon
password
Property
Jul 19, 2022 08:35 AM

MPI环境配置函数

MPI_Init(&argc, &argv) MPI_Finalize() MPI_Comm_size(comm, &size) MPI_Comm_rank(comm, &rank) MPI::Init(&argc, &argv); MPI::COMM_WORLD.Get_rank(); MPI::COMM_WORLD.Get_size(); MPI::Finalize();

点对点通信

MPI_Send(buffer, count, type, dest, tag, comm) 描述数据内容(buffer, count, type) 接受进程dest 消息标签tag
MPI_Recv(buffer, count, type, source, tag, comm, status) 匹配的信息(匹配source和tag) 接受少于count的type status包含更多信息
通配符 source: MPI_ANY_SOURCE tag: MPI_ANY_TAG
 

点对点通信(非阻塞)

MPI_Isend(buffer, count, type, dest, tag, comm, request) request为返回的非阻塞通信对象(句柄),用以查询非阻塞发送是否完成
MPI_Irecv(buffer, count, type, source, tag, comm, request) request为返回的非阻塞通信对象(句柄),用以查询非阻塞接收是否完成
MPI_Wait(request, status) MPI_Waitall(count, array_of_requests, array_of_statuses)
目的:实现计算和通信重叠

MPI数据类型

notion image
来源:翟老师课件

MPI集合通信

notion image
来源:翟老师课件

广播

MPI_Bcast(&buffer, count, datatype, root, comm)

归约

MPI_Reduce(&sendbuf, &recvbuf, count, datatype, op, dest, comm)
notion image
来源:翟老师课件

分散

MPI_Scatter(&sendbuf, sendcnt, sendtype, &recvbuf, recvcnt, recvtype, root, comm)

收集

MPI_Gather(&sendbuf, sendcnt, sendtype, &recvbuf, recvcnt, recvtype, root, comm)

其他MPI集合通信

MPI_Allgather(&sendbuf, sendcount, sendtype, &recvbuf, recvcount, recvtype, comm) MPI_Allreduce(&sendbuf, &recvbuf, count, datatype, op, comm) MPI_Alltoall(&sendbuf, sendcount, sendtype, &recvbuf, recvcount, recvtype, comm) MPI_Barrier(comm)

MPI通信域和组

MPI_Comm_group(Comm, &Group) MPI_Group_incl(Group, size, ranks[], &NewGroup) MPI_Comm_create(Comm, NewGroup, &NewComm)

MPI-IO

MPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh) MPI_File_close(MPI_File *fh) MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status) MPI_File_write(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status) MPI_File_read_all(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status) MPI_File_write_all(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status) MPI_File_sync(MPI_File fh) MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence) MPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype, MPI_Status *status)

编译运行

如果是C程序,使用如下命令进行编译: mpicc helloworld.c -o helloworld 如果是C++程序,使用如下命令进行编译: mpicxx hellowprld.cpp -o helloworld 编译完成后,使用如下命令运行 mpirun -np 4 ./helloworld 其中"-np"用来指定进程数
 
tmux使用OpenMP学习小结