mpi教程

mpi学习随记

根据mpi教程:   学习并总结出的mpi学习随记,希望对你有所帮助。学习原文见:A Comprehensive MPI Tutorial Resource · MPI Tutorial

目录

mpi学习随记

一、MPI简介与安装

二、blocking point-to-point communication

三、Basic collective communication

四、Advanced collective communication

五、Introduction to Groups and Communicators

一、MPI简介与安装

1.Introduction

mpi是一个跨语言的通讯协议,用于编写并行计算机

2.mpich的安装参见:MPICH下载安装_CSDN博客(非常有用!)

3.在这一步时,由于我没有一张信用卡or借记卡无法完成对Amazon EC2的完整注册工作hhhhh。。。所以这一步未完成。【但是不影响下面所有章节的阅读学习】

4.在“运行 MPI hello world 程序”这一环节中,我们已经在安装时添加了环境变量,所以不用做。

可以参见以下博客对mpi_hello_world.c代码做编译:mpi编译参见_CSDN博客(第三步中的测试可以基本了解mpi的使用运行方法)

mpicxx -g -Wall -o mpi_hello_world.o mpi_hello_world.cpp 
mpirun -n 4 ./mpi_hello_world.o {适用于下面所有希望使用mpi运行的代码的编译}

这里全部显示ubuntu的原因是无法启动Amazon EC2,使用的全部是本机。

知识点:

  • MPI_Init 的过程中,所有 MPI 的全局变量或者内部变量都会被创建;

  • MPI_COMM_WORLD是一个 communicator 且是 MPI 帮我们生成的)这个变量包含了当前 MPI 任务中所有的进程;

  • MPI_Comm_size 会返回 communicator 的大小,也就是 communicator 中可用的进程数量;

  • MPI_Comm_rank 这个函数会返回 communicator 中当前进程的 rank。

二、blocking point-to-point communication

1.MPI send and receive

The structure of Mpi sending and receiving function:

MPI_Send(void* data,
         int count, 
         MPI_Datatype datatype, 
         int destination,
         int tag,
         MPI_Comm communicator) 
MPI_Recv(void* data,
         int count,
         MPI_Datatype datatype,
         int source,int tag,
         MPI_Comm communicator,
         MPI_Status* status)

这里面的ping_pong.c运行结果如下图更容易理解一些:

2.Dynamic Receiving with MPI Probe

MPI_Status/MPI_Probe —— Aim: solve the problem of uncertainty about the length of the message

MPI_Status是一个结构体,而MPI_Probe是一个函数。而MPI_Probe的优点在于分配空间更加合理。

MPI_Probe(int source,
        int tag,
        MPI_Comm comm,
        MPI_Status* status)

3.Point-to-Point Communication Application - Random Walk

推荐看一下原始代码,可能会有更多收获与感想:

int maximum_sends_recvs = max_walk_size / (domain_size / world_size) + 1;
   //question:【137行】关于这里百思不得其解?

三、Basic collective communication

1.MPI Broadcast and Collective Communication

Be attention! : 假如MPI_Bcast中的root为process 0,则0进程广播是将data的值发送给其余所有进程,而其他进程广播data的值会被赋成从0进程接收到的消息。

hhhhh诡异的事情发生了,经测试:当使用MPI_Bcast发送更少的消息时,性能更加(example:100000->1000)

2.MPI Scatter, Gather, and Allgather

3.Performing Parallel Rank with MPI

这篇中的代码很有意思,仔细阅读下会有很多收获!!!

四、Advanced collective communication

MPI Reduce and Allreduce

MPI_Reduce与MPI_Allreduce的关系和MPI_Gather与MPI_Allgather的关系类似。

五、Introduction to Groups and Communicators

最好先看 Overview of groups再看Other communicators creation functions。

注意:MPI_Comm_createMPI_Comm_create_group的主要区别在于创建新的communicator时作用的对象不一样。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值