Boost C++ 库

...世界上最受尊敬和专业设计的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ 编码标准

PrevUpHomeNext

从 C MPI 到 Boost.MPI 的映射

本节提供表格,将标准 C MPI 的函数和常量映射到其 Boost.MPI 等效项。对于已经熟悉 C 或 Fortran MPI 接口的用户,或者将现有并行程序移植到 Boost.MPI 的用户来说,这将非常有用。

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

表 23.1. 点对点通信


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

unused

MPI_PACKED

内部用于 序列化数据类型

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

unused

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

memberref boost::mpi::group::rank group::rank

MPI_Group_translate_ranks

memberref 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 类提供对进程间通信器的支持。

表 23.10. 进程间通信器操作


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 图,以便在现有的通用图算法中使用。

表 23.12. 进程拓扑


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