[mpich-discuss] writing results of a parallel code in a single txt file

Pavan Balaji balaji at mcs.anl.gov
Sun Nov 13 10:26:18 CST 2011


If you do regular (posix) file I/O (like your example below does), only 
one process can write the file. Usually multiple processes writing the 
same file can cause corruption. You might be able to play some tricks to 
get multiple processes to write, but it's a pain and is not recommended. 
The recommend method is to use the MPI file I/O interface 
(MPI_File_open, MPI_File_read, MPI_File_write, etc).

  -- Pavan

On 11/12/2011 10:39 PM, ehsan saei wrote:
> yes I use MPI_Isend and MPI_Irecv for simple example I divide a 8*8 matrix between two processes half of the matrix is in process 0 and the other half is in the process 1 now I want to write this matrix on a txt file (all the elements of the matrix on a single file) when I do this I see that the half of the matrix would write on a txt file
> the writing code is:
> //myrank shows the process number and istart=0,iend=4 for process 0 and istart=4,iend=8 for process 1
> for(i=0;i<2;i++){
> if(myrank==i){
> ofstream makefile;
> makefile.open("A.txt");
> for(j=0;j<8;j++){
> for(i=istart;i<iend;i++){
> makefile<<A[i][j];
> }
> }
> makefile.close();
> }
> }
> On Nov 12, 2011, at 7:07 AM, Jeff Hammond wrote:
>
>> are you using MPI-IO?  if not, i don't see how this question belongs
>> on the MPICH discussion email list.
>>
>> with the information you have provided, i conclude that you have
>> written an incorrect parallel program and not that there is anything
>> wrong with MPI.
>>
>> jeff
>>
>> On Fri, Nov 11, 2011 at 6:59 PM, ehsan saei<shajarian_e at yahoo.com>  wrote:
>>> Hi all
>>>
>>> I want to write a parallel code that do some processes on a matrix after doing the job I want to write the updated matrix on a txt file I do this and my problem is that only the latest workers result that save its matrix on the txt file would save what must I do ?
>>> _______________________________________________
>>> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
>>> To manage subscription options or unsubscribe:
>>> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>>>
>>
>>
>>
>> --
>> Jeff Hammond
>> Argonne Leadership Computing Facility
>> University of Chicago Computation Institute
>> jhammond at alcf.anl.gov / (630) 252-5381
>> http://www.linkedin.com/in/jeffhammond
>> https://wiki.alcf.anl.gov/index.php/User:Jhammond
>> _______________________________________________
>> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
>> To manage subscription options or unsubscribe:
>> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss

-- 
Pavan Balaji
http://www.mcs.anl.gov/~balaji


More information about the mpich-discuss mailing list