Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7920463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:13:51+00:00 2026-06-03T16:13:51+00:00

I recently came across a bit of not-well-tested legacy code for writing data that’s

  • 0

I recently came across a bit of not-well-tested legacy code for writing data that’s distributed across multiple processes (these are part of an MPI-based parallel computation) into the same file. Is this actually guaranteed to work?

It goes like this:

  • All processes open the same file for writing.

  • Each process calls fseek to seek to a different location within the file. This position may be past the end of the file.

  • Each process then writes a block of data into the file with fwrite. The seek locations
    and block sizes are such that these writes completely tile a
    section of the file — no gaps, no overlaps.

Is this guaranteed to work, or will it sometimes fail horribly? There is no locking to serialize the writes, and in fact they are likely to be starting from a synchronization point. On the other hand, we can guarantee that they are writing to different file positions, unlike other questions which have had issues with trying to write to the “end of the file” from multiple processes.

It occurs to me that the processes may be on different machines that mount the file via NFS, which I suspect probably answers my question — but, would it work if the file is local?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:13:54+00:00Added an answer on June 3, 2026 at 4:13 pm

    I believe this will typically work but there is no guarantee that I can find. The Posix specifications for fwrite(3) defer to ISO C and neither standard mentions concurrency.

    So I suspect it will typically work, but fseek(3) and fwrite(3) are buffered I/O functions, so success will depend on internal details of the library implementation. So, absolutely no guarantee but various reasons to expect that it will work.

    Now, should the program use lseek(2) and write(2) then I believe you could consider the results guaranteed, but now it’s restricted to Posix operating systems.

    One thing seems … odd … why would an MPI program decide to share its data via NFS and not the message API? It would seem slower, less portable, more prone to trouble, and generally just a waste of the MPI feature set. It certainly is no more distributed given the reliance on a single NFS server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently came across some Java code that simply put some strings into a
I recently came across an interesting line of code that waits until a particular
I recently came across this genius bit of code on HTTP POST from PHP,
I recently came across some code that looked like: if(sizeof(var,2) == 4) { ...
I came across some code recently that replaces the use of switches by hard-coding
I recently came across a piece of code, that I thought was very funny.
I recently came across the following piece of code. It doesn't look valid because
I recently came across a great data structures book, Data Structures Using C (c)
I recently came across a Windows library called AHK that gives me great control
I recently came across the following line of code: var type = (typeof x).toLowerCase();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.