You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.6 KiB

[TOC]


MPI中的集合通信与广播

任务描述

本关任务使用MPI中的MPI_ReduceMPI_Bcast函数实现用户自定义输入的梯形法则近似计算积分面积。

相关知识

为了完成本关任务你需要掌握1.MPI中的梯形法则2.如何使用MPI_Bcast集合通信函数将单个进程的数据发送到通信域中所有进程3如何使用MPI_Reduce集合通信函数将通信域中所有进程的数据汇总。

梯形法则

梯形法则是指为了计算图a中从ab阴影部分的面积,将该区域划分为n个子区域,每个子区域用梯形面积计算公式计算,最终将n个小梯形汇总求和作为所求面积大小的近似结果。

MPI_Bcast

MPI_Bcast - Broadcasts a message from the process with rank root to all other processes of the group.

int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype,
    int root, MPI_Comm comm)

INPUT/OUTPUT PARAMETERS

  • buffer: Starting address of buffer (choice).
  • count: Number of entries in buffer (integer).
  • datatype: Data type of buffer (handle).
  • root: Rank of broadcast root (integer).
  • comm: Communicator (handle).
  • info: Info (handle, persistent only).

OUTPUT PARAMETERS

  • request: Request (handle, non-blocking and persistent only).
  • ierror: Fortran only: Error status (integer).

MPI_Reduce

MPI_Reduce - Reduces values on all processes within a group.

int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
               MPI_Datatype datatype, MPI_Op op, int root,
               MPI_Comm comm)

INPUT PARAMETERS

  • sendbuf: Address of send buffer (choice).
  • count: Number of elements in send buffer (integer).
  • datatype: Data type of elements of send buffer (handle).
  • op: Reduce operation (handle).
  • root: Rank of root process (integer).
  • comm: Communicator (handle).
  • info: Info (handle, persistent only).

OUTPUT PARAMETERS

  • recvbuf: Address of receive buffer (choice, significant only at root).
  • request: Request (handle, non-blocking and persistent only).
  • ierror: Fortran only: Error status (integer).

编程要求

根据提示,在右侧编辑器补充两处注释部分代码,计算并输出阴影面积的大小。

测试说明

平台会对你编写的代码进行测试:

测试输入:0 3 1024 预期输出: 9.000

测试输入:1 7 2048 预期输出: 114.000


开始你的任务吧,祝你成功!