1

i'm working with MPI and i need to write on a single file. For a minimal example I'm considering the one proposed here: writing a matrix into a single txt file with mpi which gives a result similar to what i'm looking for. However I would like to have an output like that:

P2  
10 10  
0.000    0.000    0.000    0.000    0.000    0.000    0.000    0.000    0.000    0.000  
0.000    0.000    0.000    0.000    0.000    0.000    0.000    0.000    0.000    0.000  
1.000    1.000    1.000    1.000    1.000    1.000    1.000    1.000    1.000    1.000  
1.000    1.000    1.000    1.000    1.000    1.000    1.000    1.000    1.000    1.000  
2.000    2.000    2.000    2.000    2.000    2.000    2.000    2.000    2.000    2.000  
2.000    2.000    2.000    2.000    2.000    2.000    2.000    2.000    2.000    2.000  
3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000  
3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000  
3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000  
3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000    3.000   

where P2 is an arbitrary string and 10 10 refers to the number of rows and columns. I suppose that this charachters should be written by only one process, but i cannot handle the problem.

Community
  • 1
  • 1
  • 1
    What is the problem? If the data size is small enough as to fit in the memory of a single MPI process, just use `MPI_GATHER[V]` to collect the data into a single process and then write the file from that process only. MPI has parallel IO built in but it doesn't play nice with text files. – Hristo Iliev Aug 20 '12 at 09:31
  • 1
    The answer given in the question you link to should work for you; the only real difference is that you'd have only one task (presumably rank 0) write the header and then use a non-zero offset in the call to `MPI_File_set_view()` to skip over that header. – Jonathan Dursi Aug 20 '12 at 12:48
  • 1
    @JonathanDursi, as much as I enjoy your solution (just +1'd it), using MPI-IO in such a way is a total overkill :) – Hristo Iliev Aug 20 '12 at 14:40
  • Thanks, and I tend to agree; for small files it's almost certainly substantially slower due to the overhead than just gatherv'ing everything. Also, life would be easier if we could get people away from using text files for numerical data, but... – Jonathan Dursi Aug 20 '12 at 19:26
  • Have a look [here](http://stackoverflow.com/questions/12256650/how-do-i-get-all-global-data-from-one-mpi-thread-in-c) for a simpler code. I also think parallel io is too much for such a simple task. – angainor Sep 05 '12 at 05:40

0 Answers0