[mpich-discuss] MPI_File_open(...) - overwrite existing file

Rob Latham robl at mcs.anl.gov
Thu Feb 4 11:19:06 CST 2016



On 02/04/2016 11:01 AM, Thakur, Rajeev wrote:
> It will not be truncated. If you need the file to be truncated, you will have to delete the file before opening.
>

this is a consistent theme in the standard.  If you call 
MPI_FILE_SET_SIZE to shrink a file, it will also leave old data in an 
undefined state.

==rob

> Rajeev
>
>> On Feb 4, 2016, at 10:37 AM, Florian.Willich at dlr.de wrote:
>>
>> Dear MPI Group,
>>
>> I'm wondering if the files created with the modes
>>
>> MPI_MODE_CREATE | MPI_MODE_WRONLY
>>
>> will be truncated to 0 if the file already exists calling MPI_File_open(...).
>>
>> As far as I tested it and also which is written in the standard:
>>
>> MPI_MODE_CREATE — create the file if it does not exist
>> MPI_MODE_WRONLY — write only
>>
>> The existing file will be overwritten, but leaving the bytes that have not been explicitly overwritten. Thus, an existing file with the size of 8 Bytes and data to be written to of 4 Bytes will still be 8 Bytes after writing: With the 4 Bytes of the new data and 4 Bytes of the old data.
>>
>> As I read it, there is nothing defined what happens with the data of the file if it already exists [p 494, 1].
>>
>> The POSIX / GNU lib c standard states that the file will be truncated to 0 if opened with 'w' and the file does already exists calling fopen(...) [p. 249, 2]:
>>
>> ‘w’ - Open the file for writing only. If the file already exists, it is truncated to zero length. Otherwise a new file is created.
>>
>> I really would appreciate some input if I'm wrong or not and what to do if the file needs to be truncated before writing (other then deleting the file before).
>>
>> Kind regards
>>
>> Florian Willich
>>
>> [1]: Message Passing Interface Forum. 2015. MPI: A Message-Passing Interface Standard Version 3.1. http://mpi-forum.org/docs/mpi-3.1/mpi31-report.pdf. [Online. Accessed 2nd December 2015].
>>
>> [2]: Loosemore, Sandra, Stallman, Richard M., McGrath, Roland, Oram, Andrew, & Drepper, Ulrich. 2015. The GNU C Library Reference Manual. http://www.gnu.org/software/libc/manual/pdf/libc.pdf. [Online. Accessed 24th January 2016].
>>
>> Deutsches Zentrum für Luft- und Raumfahrt e. V. (DLR)
>> German Aerospace Center
>> Institute of Planetary Research | Planetary Physics | Rutherfordstraße 2 | 12489 Berlin
>>
>> Florian Willich| Candidate for Bachelor of Science
>> Software Developer (Parallel Applications)
>> florian.willlich at dlr.de
>> DLR.de
>> _______________________________________________
>> discuss mailing list     discuss at mpich.org
>> To manage subscription options or unsubscribe:
>> https://lists.mpich.org/mailman/listinfo/discuss
>
> _______________________________________________
> discuss mailing list     discuss at mpich.org
> To manage subscription options or unsubscribe:
> https://lists.mpich.org/mailman/listinfo/discuss
>
_______________________________________________
discuss mailing list     discuss at mpich.org
To manage subscription options or unsubscribe:
https://lists.mpich.org/mailman/listinfo/discuss


More information about the discuss mailing list