From f23b01ef35628f9519b5b64977650baa635a1997 Mon Sep 17 00:00:00 2001 From: pyvawtjzl Date: Wed, 12 Mar 2025 09:55:38 +0800 Subject: [PATCH] ADD file via upload --- Lab1-2.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Lab1-2.md diff --git a/Lab1-2.md b/Lab1-2.md new file mode 100644 index 0000000..4d9aede --- /dev/null +++ b/Lab1-2.md @@ -0,0 +1,88 @@ +[TOC] + +--- + +## MPI中的集合通信与广播 + +### 任务描述 + +本关任务:使用MPI中的`MPI_Reduce`和`MPI_Bcast`函数实现用户自定义输入的梯形法则近似计算积分面积。 + +### 相关知识 + +为了完成本关任务,你需要掌握:1.MPI中的梯形法则,2.如何使用`MPI_Bcast`集合通信函数将单个进程的数据发送到通信域中所有进程,3如何使用`MPI_Reduce`集合通信函数将通信域中所有进程的数据汇总。 + +#### 梯形法则 + + + +梯形法则是指为了计算图(a)中从`a`到`b`阴影部分的面积,将该区域划分为`n`个子区域,每个子区域用梯形面积计算公式计算,最终将`n`个小梯形汇总求和作为所求面积大小的近似结果。 + +#### MPI_Bcast + +`MPI_Bcast` - Broadcasts a message from the process with rank root to all other processes of the group. + +```c +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. + +```c +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` + +--- + +开始你的任务吧,祝你成功!