- } while (done != chunk_size);
-
- MPI_Barrier(MPI_COMM_WORLD);
-
- /* Check the result */
- if (rank == 0) {
- lseek(fd, 0, SEEK_SET);
-
- /* quick check */
- stat(filename, &stat_buf);
- file_size = stat_buf.st_size;
- if (file_size != chunk_size * noProcessors)
- rprintf(rank, n, "invalid file size %d"
- " instead of %d\n", file_size,
- chunk_size * noProcessors);
+ } while (done != CHUNK_SIZE(n));
+
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ /* Check the result */
+ if (stat(filename, &stat_buf) < 0)
+ rprintf(rank, n, "error stating %s: %s\n",
+ filename, strerror(errno));
+
+ if (stat_buf.st_size != CHUNK_SIZE(n) * noProcessors) {
+ if (n > 0)
+ printf("loop %d: chunk_size %lu, "
+ "file size was %lu\n",
+ n - 1, CHUNK_SIZE(n - 1),
+ CHUNK_SIZE(n - 1) *noProcessors);
+ rprintf(rank, n, "invalid file size %lu"
+ " instead of %lu = %lu * %u\n",
+ (unsigned long)stat_buf.st_size,
+ CHUNK_SIZE(n) * noProcessors,
+ CHUNK_SIZE(n), noProcessors);
+ }
+
+ if (rank == 0) {
+ if (lseek(fd, 0, SEEK_SET) < 0)
+ rprintf(rank, n, "error seeking to 0: %s\n",
+ strerror(errno));