Commits

Jed Brown committed e31d4fa

PetscSynchronizedFGets: fix deadlock at EOF

> Problem: When reading a file of unknown length using
> PetscSynchronizedFGets(), all but the first process in the communicator
> freeze after reaching the end of the file.
>
> Cause: When EOF is reached, PetscSynchronizedFGets() sets len = 0.
> However, this only happens in the first process, so the other processes
> are still expecting the originally requested number of bytes to be
> broadcast to them, and thus hang at MPI_Bcast().
>
> Solution: Do not set len = 0 at EOF.

This commit cherry-picks relevant portions of multiple commits from
the feature branch 'barry/wirth-fusion-materials'.

Reported-by: Ilmari Karonen <ilmari.karonen@helsinki.fi>

Comments (0)

Files changed (1)

src/sys/fileio/mprint.c

 -   len - the length of the output buffer
 
     Output Parameter:
-.   string - the line read from the file
+.   string - the line read from the file, at end of file string[0] == 0
 
     Level: intermediate
 
     char *ptr = fgets(string, len, fp);
 
     if (!ptr) {
-      if (feof(fp)) len = 0;
-      else SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_FILE_READ, "Error reading from file: %d", errno);
+      string[0] = 0;
+      if (!feof(fp)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_FILE_READ, "Error reading from file: %d", errno);
     }
   }
   ierr = MPI_Bcast(string,len,MPI_BYTE,0,comm);CHKERRQ(ierr);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.