对于希望在运行 Catch2 分布式时删除所有重复的控制台输出的任何人,这里有一个解决方案。
在catch.hpp 中找到ConsoleReporter 的定义(在v2.10.0 中,它位于第15896 行)。它看起来像:
ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
: StreamingReporterBase(config),
m_tablePrinter(new TablePrinter(config.stream(),
[&config]() -> std::vector<ColumnInfo> {
if (config.fullConfig()->benchmarkNoAnalysis())
{
return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
{ " samples", 14, ColumnInfo::Right },
{ " iterations", 14, ColumnInfo::Right },
{ " mean", 14, ColumnInfo::Right }
};
}
else
{
return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left },
{ "samples mean std dev", 14, ColumnInfo::Right },
{ "iterations low mean low std dev", 14, ColumnInfo::Right },
{ "estimated high mean high std dev", 14, ColumnInfo::Right }
};
}
}())) {}
ConsoleReporter::~ConsoleReporter() = default;
虽然此处未显示,但基类 StreamingReporterBase 提供了一个 stream 属性,我们将通过 failbit 显示的技巧 here 禁用该属性。
在上面最后的{}(一个空的构造函数定义)内,插入:
// I solemnly swear that I am up to no good
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// silence non-root nodes
if (rank != 0)
stream.setstate(std::ios_base::failbit);
您可以在this repo 上查看示例。