我在并行阅读方面遇到了一些问题
我有一个文本文件,如下所示:
1 4 30 46
0 2 3 29
1 11 12 -1
1 4 5 -1
0 3 13 14
3 6 7 8
5 10 -1 -1
13 10 -1 -1
5 9 27 -1
我试图在每个进程中一次读取这些整数4,文件行数等于进程数,每行包含4个整数
int bufsize, count;
int *buf;
MPI::Status status;
MPI::File top = MPI::File::Open(MPI::COMM_WORLD, "top.txt", MPI::MODE_RDONLY, MPI::INFO_NULL);
MPI::Offset filesize = top.Get_size();
filesize = filesize / sizeof(int);
bufsize = filesize / wasteland_size + 1;
buf = new int[bufsize * sizeof(int)];
top.Set_view(my_rank * bufsize * sizeof(int), MPI_INT, MPI_INT, "native", MPI::INFO_NULL);
top.Read(buf, bufsize, MPI_INT, status);
count = status.Get_count(MPI_INT);
top.Close();
这是我正在使用的代码。
它编译没有错误或警告,但它输出一些行:
540287025 874524723 805969974 857748000
每个过程。
答案 0 :(得分:2)
问题是您的文件是文本文件,但不是这样解释的。您正在从二进制文件中读取整数。
当你转换这些数字中的任何一个时,你会看到它们是由用ASCII表示数字或空格的字节组成的。
我建议更改文件格式,以便我将每个数字表示为4个字节。这也允许您按照自己的方式拆分文件。