【发布时间】:2021-03-16 15:56:40
【问题描述】:
我已经编写了这部分代码,以便为每个等级创建一个文件并查看其内容。我的问题是如何扩展此代码以适用于任意大小。在这里,因为我使用 4 个内核运行;我已经知道我的大小,所以我用 4 个 if 条件编写了我的代码,我认为应该有更好的方法来处理更多的进程。
string local_string = to_string(rank) + base;
ofstream output{ local_string };
if (local_string == "0.txt") {
for (int i = 0; i < N;i++) {
output << data[i] << endl;
}
}
if (local_string == "1.txt") {
for (int i = 0; i < N;i++) {
output <<data[i] << endl;
}
}
if (local_string == "2.txt") {
for (int i = 0; i < N;i++) {
output << data[i] << endl;
}
}
if (local_string == "3.txt") {
for (int i = 0; i < N;i++) {
output << data[i] << endl;
}
}
【问题讨论】:
标签: c++ parallel-processing output mpi hpc