1

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?

Ilknur Mustafa
  • 301
  • 2
  • 11

1 Answers1

1

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.
Gilles Gouaillardet
  • 8,193
  • 11
  • 24
  • 30