Boost C++ 库

one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

C MPI 到 Boost.MPI 的映射 - Boost C++ 函数库
PrevUpHomeNext

本节提供了映射表,将标准 C MPI 的函数和常量与其 Boost.MPI 等效项进行对应。这将对熟悉 MPI 的 C 或 Fortran 接口,或者需要将现有并行程序移植到 Boost.MPI 的用户最有帮助。

请注意,这不是一个完美的直接映射,Boost.MPI 有时会以对最终用户透明的方式使用 C API 中的函数。例如,MPI_Probe friends 可用于实现异步发送/接收。


Boost.MPI 会自动将 C 和 C++ 数据类型映射到其 MPI 等效项。下表说明了 C++ 类型和 MPI 数据类型常量之间的映射。

表 23.2. 数据类型

C 常量

Boost.MPI 等效项

MPI_CHAR

signed char

MPI_SHORT

signed short int

MPI_INT

signed int

MPI_LONG

signed long int

MPI_UNSIGNED_CHAR

unsigned char

MPI_UNSIGNED_SHORT

unsigned short int

MPI_UNSIGNED_INT

unsigned int

MPI_UNSIGNED_LONG

unsigned long int

MPI_FLOAT

float

MPI_DOUBLE

double

MPI_LONG_DOUBLE

long double

MPI_BYTE

未使用

MPI_PACKED

在 Boost.MPI 中内部使用,用于 序列化数据类型

MPI_LONG_LONG_INT

long long int, 如果编译器支持

MPI_UNSIGNED_LONG_LONG_INT

unsigned long long int, 如果编译器支持

MPI_FLOAT_INT

std::pair<float, int>

MPI_DOUBLE_INT

std::pair<double, int>

MPI_LONG_INT

std::pair<long, int>

MPI_2INT

std::pair<int, int>

MPI_SHORT_INT

std::pair<short, int>

MPI_LONG_DOUBLE_INT

std::pair<long double, int>


Boost.MPI 不提供对 MPI 派生数据类型功能的直接包装。相反,Boost.MPI 依赖于 Boost.Serialization 库来为用户定义类构建 MPI 数据类型。关于 用户定义数据类型 的章节描述了这种机制,它用于使用 is_mpi_datatype 标记为“MPI 数据类型”的类型。

接下来的派生数据类型表描述了哪些 C++ 类型对应于 C MPI 的数据类型构造函数的功能。Boost.MPI 在构建特定形式的数据类型时可能不会实际使用列出的 C MPI 函数。由于 Boost.MPI 构建的实际数据类型通常对用户是隐藏的,因此许多这些操作都是由 Boost.MPI 在内部调用的。

表 23.3. 派生数据类型

C 函数/常量

Boost.MPI 等效项

MPI_Address

在 Boost.MPI 中自动使用,用于 MPI 版本 1.x

MPI_Get_address

在 Boost.MPI 中自动使用,用于 MPI 版本 2.0 及更高版本

MPI_Type_commit

在 Boost.MPI 中自动使用

MPI_Type_contiguous

数组

MPI_Type_extent

在 Boost.MPI 中自动使用

MPI_Type_free

在 Boost.MPI 中自动使用

MPI_Type_hindexed

用作子对象的任何类型

MPI_Type_hvector

未使用

MPI_Type_indexed

用作子对象的任何类型

MPI_Type_lb

unsupported

MPI_Type_size

在 Boost.MPI 中自动使用

MPI_Type_struct

带有 MPI 1.x 的用户定义类和结构

MPI_Type_create_struct

带有 MPI 2.0 及更高版本的用户定义类和结构

MPI_Type_ub

unsupported

MPI_Type_vector

在 Boost.MPI 中自动使用


MPI 的打包功能将值存储到连续缓冲区中,该缓冲区可以通过 MPI 传输,然后通过 MPI 的解包功能解包为单独的值。与数据类型一样,Boost.MPI 提供了对 MPI 打包和解包功能的抽象接口。特别是,两个存档类 packed_oarchivepacked_iarchive 可用于使用 MPI 的功能打包或解包连续缓冲区。

表 23.4. 打包和解包

C 函数

Boost.MPI 等效项

MPI_Pack

packed_oarchive

MPI_Pack_size

在 Boost.MPI 中内部使用

MPI_Unpack

packed_iarchive


Boost.MPI 支持大多数 MPI 集合通信的“一对一”映射。对于 Boost.MPI 提供的每个集合通信,当可能(且高效)时,将调用底层的 C MPI 集合通信。

表 23.5. 集合通信

C 函数

Boost.MPI 等效项

MPI_Allgather

all_gather

MPI_Allgatherv

大多数用法由 all_gather 支持

MPI_Allreduce

all_reduce

MPI_Alltoall

all_to_all

MPI_Alltoallv

大多数用法由 all_to_all 支持

MPI_Barrier

communicator::barrier

MPI_Bcast

broadcast

MPI_Gather

gather

MPI_Gatherv

大多数用法由 gather 支持,其他用法由 gatherv 支持

MPI_Reduce

reduce

MPI_Reduce_scatter

unsupported

MPI_Scan

scan

MPI_Scatter

scatter

MPI_Scatterv

大多数用法由 scatter 支持,其他用法由 scatterv 支持

MPI_IN_PLACE

通过 all_reduce(通过省略输出值) 隐式支持


Boost.MPI 使用函数对象来指定在等效于 MPI_AllreduceMPI_ReduceMPI_Scan 的操作中如何进行归约。下表说明了 C MPI 和 Boost.MPI 之间的 预定义用户定义 归约操作如何映射。

表 23.6. 归约操作

C 常量

Boost.MPI 等效项

MPI_BAND

bitwise_and

MPI_BOR

bitwise_or

MPI_BXOR

bitwise_xor

MPI_LAND

std::logical_and

MPI_LOR

std::logical_or

MPI_LXOR

logical_xor

MPI_MAX

maximum

MPI_MAXLOC

unsupported

MPI_MIN

minimum

MPI_MINLOC

unsupported

MPI_Op_create

在 Boost.MPI 中内部使用

MPI_Op_free

在 Boost.MPI 中内部使用

MPI_PROD

std::multiplies

MPI_SUM

std::plus


MPI 定义了几种特殊的通信子,包括 MPI_COMM_WORLD(包含本地进程可以通信的所有进程)、MPI_COMM_SELF(只包含本地进程)和 MPI_COMM_EMPTY(不包含任何进程)。这些特殊的通信子都是 Boost.MPI 中的 communicator 类的实例。

表 23.7. 预定义通信子

C 常量

Boost.MPI 等效项

MPI_COMM_WORLD

默认构造的 communicator

MPI_COMM_SELF

包含当前进程的 communicator

MPI_COMM_EMPTY

计算为 false 的 communicator


Boost.MPI 通过其 group 类支持进程组。

表 23.8. 组操作和常量

C 函数/常量

Boost.MPI 等效项

MPI_GROUP_EMPTY

默认构造的 group

MPI_Group_size

group::size

MPI_Group_rank

成员引用 boost::mpi::group::rank group::rank

MPI_Group_translate_ranks

成员引用 boost::mpi::group::translate_ranks group::translate_ranks

MPI_Group_compare

运算符 ==!=

MPI_IDENT

运算符 ==!=

MPI_SIMILAR

运算符 ==!=

MPI_UNEQUAL

运算符 ==!=

MPI_Comm_group

communicator::group

MPI_Group_union

组的运算符 |

MPI_Group_intersection

组的运算符 &

MPI_Group_difference

组的运算符 -

MPI_Group_incl

group::include

MPI_Group_excl

group::exclude

MPI_Group_range_incl

unsupported

MPI_Group_range_excl

unsupported

MPI_Group_free

在 Boost.MPI 中自动使用


Boost.MPI 通过 communicator 类提供通信子的操作。

表 23.9. 通信子操作

C 函数

Boost.MPI 等效项

MPI_Comm_size

communicator::size

MPI_Comm_rank

communicator::rank

MPI_Comm_compare

运算符 ==!=

MPI_Comm_dup

使用 comm_duplicatecommunicator 类构造函数

MPI_Comm_create

communicator 构造函数

MPI_Comm_split

communicator::split

MPI_Comm_free

在 Boost.MPI 中自动使用


Boost.MPI 目前通过 intercommunicator 类提供对互通信子的支持。


Boost.MPI 目前不提供对属性缓存的支持。

表 23.11. 属性和缓存

C 函数/常量

Boost.MPI 等效项

MPI_NULL_COPY_FN

unsupported

MPI_NULL_DELETE_FN

unsupported

MPI_KEYVAL_INVALID

unsupported

MPI_Keyval_create

unsupported

MPI_Copy_function

unsupported

MPI_Delete_function

unsupported

MPI_Keyval_free

unsupported

MPI_Attr_put

unsupported

MPI_Attr_get

unsupported

MPI_Attr_delete

unsupported


Boost.MPI 将提供对创建具有不同拓扑的通信子以及之后查询这些拓扑的全面支持。通过与 Boost Graph Library (BGL) 的接口来支持图拓扑,其中可以创建一个与任何 BGL 图结构匹配的通信子,并且通信子的图拓扑可以被视为 BGL 图,用于现有的通用图算法。


Boost.MPI 通过 environment 类支持环境查询。

表 23.13. 环境查询

C 函数/常量

Boost.MPI 等效项

MPI_TAG_UB

不必要;使用 environment::max_tag

MPI_HOST

不必要;使用 environment::host_rank

MPI_IO

不必要;使用 environment::io_rank

MPI_Get_processor_name

environment::processor_name


Boost.MPI 将 MPI 错误转换为异常,通过 exception 类报告。

表 23.14. 错误处理

C 函数/常量

Boost.MPI 等效项

MPI_ERRORS_ARE_FATAL

未使用;错误被转换为 Boost.MPI 异常

MPI_ERRORS_RETURN

未使用;错误被转换为 Boost.MPI 异常

MPI_errhandler_create

未使用;错误被转换为 Boost.MPI 异常

MPI_errhandler_set

未使用;错误被转换为 Boost.MPI 异常

MPI_errhandler_get

未使用;错误被转换为 Boost.MPI 异常

MPI_errhandler_free

未使用;错误被转换为 Boost.MPI 异常

MPI_Error_string

在 Boost.MPI 中内部使用

MPI_Error_class

exception::error_class


MPI 的计时设施通过 Boost.MPI 的 timer 类公开,它提供了一个与 Boost Timer 库 兼容的接口。

表 23.15. 计时设施

C 函数/常量

Boost.MPI 等效项

MPI_WTIME_IS_GLOBAL

不必要;使用 timer::time_is_global

MPI_Wtime

使用 timer::elapsed 来确定从某个特定起始点经过的时间

MPI_Wtick

timer::elapsed_min


MPI 的启动和关闭由 Boost.MPI environment 类的构造和析构来管理。

表 23.16. 启动/关闭设施


Boost.MPI 不提供对 MPI 1.1 中任何性能分析设施的支持。

表 23.17. 性能分析接口

C 函数

Boost.MPI 等效项

PMPI_* 例程

unsupported

MPI_Pcontrol

unsupported



PrevUpHomeNext