Formatted output with MPI_File_write_at?

216 Views Asked by At

I'm trying to write a parallel IO program with MPI, I'm required to write the data to the file with a format as: 02 03 04 in the file instead of 2 3 4.

fprintf(fpOut,"%.2d ",var);

Would be the serial counterpart of what I'm trying to do. I've looked around but couldn't find any answers so far. Any idea on how I might go about this?

1

There are 1 best solutions below

0
Gilles Gouaillardet On BEST ANSWER

MPI_IO writes binary data (vs text/formatted data).

So if you really want to write in parallel, you can use an intermediate buffer, and then write it, for example

char buf[4];
sprintf(buf, "%.2d ", var);
MPI_File_write_at(buf, 3, MPI_CHAR, ...);

That being said, you might want to reconsider your workflow:

  • one option is to start using binary data everywhere (and write in parallel)
  • an other option is to write intermediate data in binary and in parallel, and finally post process it (not in parallel) to "convert" it into plain text.