我可以声明一个位表吗?

发布于 2024-12-10 08:09:29 字数 217 浏览 0 评论 0原文

我正在构建一个 MPI 应用程序。为了减少正在传输的消息的大小,我正在考虑使用“位”表来表示 bool 表(因为 bool 值只能采用以下之一)两个值:truefalse)。这对我来说很重要,因为通信是我的应用程序中的主要性能瓶颈。

可以创建这样的表吗? MPI API 中是否存在此数据类型?

I am building an MPI application. In order to reduce the size of the messages being transferred, I am thinking of having tables of "bits" to represent bool tables (since the bool value can take only one of two values: true or false). It is important in my case since the communication is the main performance bottleneck in my application.

Is it possible to create this kind of table? Does this datatype exist in the MPI API?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

分開簡單 2024-12-17 08:09:29

在 C++ 中 std::bitsetboost::dynamic_bitset 对于管理多个位非常有用。如果位集的大小不固定,请选择后者。 AFAIK MPI 使用 MPI_SendMPI_Rec 进行进程间通信。如何序列化输出并通过这些接口发送它们是另一回事,因为 Boost.Serialization 不支持这两种类型。

In C++ std::bitset or boost::dynamic_bitset can be useful to manage a number of bits. Choose the later if the size of the bitset isn't fixed. AFAIK MPI uses MPI_Send and MPI_Rec for inter process communication. How you serialize your output and send them through those interfaces is another matter as neither of the two types is supported by Boost.Serialization.

别再吹冷风 2024-12-17 08:09:29

根据原始问题中的标签,我假设您混合使用 Fortran 和 C++。 Fortran 的 MPI 绑定具有 MPI_LOGICAL 数据类型,您可以在消息传递调用中轻松使用它。我不知道 MPI C 绑定有这种类型。正如 PlasmaHH 所建议的,在这种情况下发送整数可能对您有用。

https://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types

Based on the tag in the original question, I assume you are using a mix of Fortran and C++. MPI binding for Fortran has the datatype MPI_LOGICAL, which you can readily use in your message passing calls. I am not aware of such type for MPI C binding. As suggested by PlasmaHH, sending integers might work for you in that case.

https://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types

暮光沉寂 2024-12-17 08:09:29

简短的回答 - 不,最短的 MPI 数据类型是 MPI_BYTE,您不能创建只有一点的类型。 (Fortran 绑定具有 MPI_LOGICAL,它对应于本地逻辑类型,但几乎总是对应于 int 或可能是字节,而不是位)。

现在,这不一定是问题;而是问题。如果你有一个位数组,你可以四舍五入到下一个整数字节,然后发送它,并忽略最后几位。 (无论如何,这几乎是您在创建表时必须做的事情)。但我有一些问题。

您的消息有多大?你的网络是什么?您确定是带宽受到限制,而不是延迟受到限制吗?

如果您的消息很小(例如低于 MB),那么您可能会受到消息延迟的影响,而不是带宽,并且减小消息大小也无济于事。 (您可以使用乒乓球测试来估计这一点 - 例如在英特尔 MPI 基准测试< /a> - 查看有效带宽水平的大小)。如果这就是您所处的情况,那么这可能会让事情变得更糟,而不是更好,因为通信不会加速,但索引到位数组的额外成本可能会减慢速度。

另一方面,如果您要发送大消息(例如 MB 大小)和/或内存有限,这可能是一件好事。

Short answer - no, the shortest MPI datatype is MPI_BYTE, you can't create a type that's just a bit. (The fortran bindings have MPI_LOGICAL which corresponds to the local logical type, but that almost always corresponds to an int or maybe a byte, not a bit).

Now, that's not necessarily a problem; if you had a bit array you could just round up to the next whole number of bytes, and send that, and just ignore the last few bits. (which is pretty much what you'd have to do in your table creation anyway). But I have some questions.

How large are your messages? And what's your networking? Are you sure you're bandwidth limited, rather than latency limited?

If your messages are smallish (say under an MB), then you're likely dominated by latency of messages, not bandwidth, and reducing message size won't help. (You can estimate this using pingpong tests - say in the Intel MPI benchmarks - to see at what sizes your effective bandwidth levels off). If that's the regime you're in, then this will likely make things worse, not better, as communication won't speed up but additional cost of indexing into a bit array will likely slow things down.

On the other hand, if you're sending large messages (say MB sized) and/or you're memory limited, this could be a good thing.

残龙傲雪 2024-12-17 08:09:29

我会将您的位传输到整数数组中。

我将回答有关 FORTRAN 语言的问题。
您可以使用固有位操作来前后移动位。

另外需要澄清的是,您不应使用 FORTRAN 类型 LOGICAL,因为它与常规整数一样都是 4 字节变量。
使用这些函数:

BIT_SIZE(I)
IBCLR(I, POS) ! Set to 0 in variable I at position POS
IBSET(I, POS) ! Set to 1 in variable I at position POS
BTEST(I, POS) ! To test if bit at POS is 1

然后以您正在处理的任何类型进行正常传输。您可以在 MPI 通信中添加标签,让接收方知道它是一个应该按位处理的变量。
这应该会限制您的通信,但也需要打包数据和外打包。在任何情况下,您也可以将所有 BOOL 表转移到此方案。

但应该注意的是,您的 BOOL 表必须非常大才能看到任何效果,我们谈论的是多大?

I would transfer your bits into an array of integers.

I will answer in regard to the FORTRAN language.
You can use the intrinsic bit operations to move the bits back and forth.

Also to clearify, you should not use the FORTRAN type LOGICAL as it is an 4-byte variable just as regular integers.
Use these functions:

BIT_SIZE(I)
IBCLR(I, POS) ! Set to 0 in variable I at position POS
IBSET(I, POS) ! Set to 1 in variable I at position POS
BTEST(I, POS) ! To test if bit at POS is 1

Then do a normal transfer in whatever type you are dealing with. You can add tags in the MPI communication to let the receiver know that it is a variable that should be handled bitwise.
This should limit your communication, but requires packing of the data and outpackaging as well. In any case you could also just transfer all your BOOL tables to this scheme.

But it should be noticed that your BOOL tables have to be extensively big to see any effect, how large are we talking?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文