我假设这里data_sink
是一个MPI::File
. 足够的代码能够重现您的输出会很有帮助。
首先要知道的是 MPI-IO 例程以二进制输出;在每个值之后输出空格和换行符不会改变这一点。但要知道的另一件事是gnuplot 可以很好地读取二进制文件。所以这里有一个小的 MPI-IO 代码,它输出一个正弦波,每个进程获得整个域的 20 个点:
#include <mpi.h>
#include <cmath>
int main(int argc, char **argv) {
int rank, size;
const int nperrank = 20;
double *data = new double[2*nperrank];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
int totnpts = nperrank * size;
double dx = (2.*3.14159/totnpts);
double left = rank * nperrank * dx;
for (int i=0; i<nperrank; i++) {
double x = left + dx*i;
double sinx = sin(x);
data[2*i] = x;
data[2*i+1] = sinx;
}
MPI_File file;
MPI_File_open(MPI_COMM_WORLD, "out.dat", MPI_MODE_WRONLY | MPI_MODE_CREATE,
MPI_INFO_NULL, &file);
MPI_Status status;
MPI_File_write_at_all(file, 2*rank*nperrank*sizeof(double),
data, 2*nperrank, MPI_DOUBLE, &status);
MPI_File_close(&file);
MPI_Finalize();
return 0;
}
这是运行它并绘制的输出:
$ mpicxx -o io io.cc
$ mpirun -np 4 ./io
$ gnuplot
G N U P L O T
Version 4.2 patchlevel 6
[...]
Terminal type set to 'x11'
gnuplot> plot 'out.dat' binary format="%lf%lf" using 1:2 with linespoints
gnuplot>