Skip to content

Commit

Permalink
examples: shorten file descriptor names
Browse files Browse the repository at this point in the history
  • Loading branch information
adammoody committed Mar 4, 2022
1 parent 5068958 commit 237ba23
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 50 deletions.
13 changes: 6 additions & 7 deletions examples/test_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,18 @@ double getbw(char* name, char* buf, int times)
strcpy(file, newname);
}

int my_fd = create_file(file);

/* write the checkpoint and close */
if (my_fd >= 0) {
int fd = create_file(file);
if (fd >= 0) {
count++;
valid = 1;

if (lseek(my_fd, my_file_offset, SEEK_SET) >= 0) {
if (lseek(fd, my_file_offset, SEEK_SET) >= 0) {
/* write the checkpoint data */
if (write_checkpoint(my_fd, timestep, buf, my_bufsize)) {
if (write_checkpoint(fd, timestep, buf, my_bufsize)) {
/* force the data to storage */
if (use_fsync) {
if (fsync(my_fd) < 0) {
if (fsync(fd) < 0) {
valid = 0;
printf("%d: Error fsync %s\n", rank, file);
}
Expand All @@ -357,7 +356,7 @@ double getbw(char* name, char* buf, int times)
}

/* make sure the close is without error */
if (close(my_fd) < 0) {
if (close(fd) < 0) {
valid = 0;
printf("%d: Error closing %s\n", rank, file);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/test_api_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ double getbw(char* name, char* buf, size_t size, int times)
}

/* open the file and write the checkpoint */
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
count++;
valid = 1;

/* write the checkpoint data */
rc = write_checkpoint(fd_me, timestep, buf, size);
rc = write_checkpoint(fd, timestep, buf, size);
if (rc < 0) {
valid = 0;
printf("%d: Error writing to %s\n", rank, file);
}

/* force the data to storage */
rc = fsync(fd_me);
rc = fsync(fd);
if (rc < 0) {
valid = 0;
printf("%d: Error fsync %s\n", rank, file);
}

/* make sure the close is without error */
rc = close(fd_me);
rc = close(fd);
if (rc < 0) {
valid = 0;
printf("%d: Error closing %s\n", rank, file);
Expand Down
20 changes: 10 additions & 10 deletions examples/test_api_multiple.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,19 @@ int main (int argc, char* argv[])
}

// open file and write checkpoint
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
valid = 1;

// write the checkpoint
rc = write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]);
rc = write_checkpoint(fd, timestep, bufs[i], filesizes[i]);
if (rc < 0) { valid = 0; }

rc = fsync(fd_me);
rc = fsync(fd);
if (rc < 0) { valid = 0; }

// make sure the close is without error
rc = close(fd_me);
rc = close(fd);
if (rc < 0) { valid = 0; }
}
if (!valid) { all_valid = 0; }
Expand Down Expand Up @@ -281,20 +281,20 @@ int main (int argc, char* argv[])
}

// open file and write checkpoint
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
count++;
valid = 1;

// write the checkpoint
rc = write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]);
rc = write_checkpoint(fd, timestep, bufs[i], filesizes[i]);
if (rc < 0) { valid = 0; }

rc = fsync(fd_me);
rc = fsync(fd);
if (rc < 0) { valid = 0; }

// make sure the close is without error
rc = close(fd_me);
rc = close(fd);
if (rc < 0) { valid = 0; }
}
if (!valid) { all_valid = 0; }
Expand Down
20 changes: 10 additions & 10 deletions examples/test_api_multiple_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ int main (int argc, char* argv[])
rank, scr_retval, __FILE__, __LINE__
);
}
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
valid = 1;

// write the checkpoint
rc = write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]);
rc = write_checkpoint(fd, timestep, bufs[i], filesizes[i]);
if (rc < 0) { valid = 0; }

rc = fsync(fd_me);
rc = fsync(fd);
if (rc < 0) { valid = 0; }

// make sure the close is without error
rc = close(fd_me);
rc = close(fd);
if (rc < 0) { valid = 0; }
}
if (!valid) { all_valid = 0; }
Expand Down Expand Up @@ -236,20 +236,20 @@ int main (int argc, char* argv[])
rank, scr_retval, __FILE__, __LINE__
);
}
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
count++;
valid = 1;

// write the checkpoint
rc = write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]);
rc = write_checkpoint(fd, timestep, bufs[i], filesizes[i]);
if (rc < 0) { valid = 0; }

rc = fsync(fd_me);
rc = fsync(fd);
if (rc < 0) { valid = 0; }

// make sure the close is without error
rc = close(fd_me);
rc = close(fd);
if (rc < 0) { valid = 0; }
}
if (!valid) { all_valid = 0; }
Expand Down
16 changes: 8 additions & 8 deletions examples/test_interpose.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ int main (int argc, char* argv[])
mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR);
}
MPI_Barrier(MPI_COMM_WORLD);
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
write(fd_me, buf, filesize);
close(fd_me);
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
write(fd, buf, filesize);
close(fd);
}
}
MPI_Barrier(MPI_COMM_WORLD);
Expand All @@ -88,11 +88,11 @@ int main (int argc, char* argv[])
mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR);
}
MPI_Barrier(MPI_COMM_WORLD);
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
count++;
write(fd_me, buf, filesize);
close(fd_me);
write(fd, buf, filesize);
close(fd);
}
}
gettimeofday (tv1, NULL);
Expand Down
20 changes: 10 additions & 10 deletions examples/test_interpose_multiple.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ int main (int argc, char* argv[])
for(t=0; t < 1; t++) {
for (i=0; i < num_files; i++) {
char* file = files[i];
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
// write the checkpoint
write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]);
write_checkpoint(fd, timestep, bufs[i], filesizes[i]);

fsync(fd_me);
fsync(fd);

close(fd_me);
close(fd);
}
}
if (rank == 0) { printf("Completed checkpoint %d.\n", timestep); fflush(stdout); }
Expand All @@ -182,16 +182,16 @@ int main (int argc, char* argv[])
for(t=0; t < times; t++) {
for (i=0; i < num_files; i++) {
char* file = files[i];
int fd_me = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_me >= 0) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
count++;

// write the checkpoint
write_checkpoint(fd_me, timestep, bufs[i], filesizes[i]);
write_checkpoint(fd, timestep, bufs[i], filesizes[i]);

fsync(fd_me);
fsync(fd);

close(fd_me);
close(fd);
}
}
if (rank == 0) { printf("Completed checkpoint %d.\n", timestep); fflush(stdout); }
Expand Down

0 comments on commit 237ba23

Please sign in to comment.