#include <unistd.h>
#include "mpi.h"
+#define DEFAULT_ITER 50000
#define CHUNK_SIZE_MAX 123456
#define CHUNK_CHAR 'C'
void usage(char *prog)
{
printf("usage: %s <filename> [nloops]\n", prog);
- printf("%s must be run on 2 nodes\n", prog);
+ printf("%s must be run with 2 processes\n", prog);
+ MPI_Finalize();
exit(1);
}
printf(fmt, ap);
+ MPI_Finalize();
exit(1);
}
if (argc == 3)
nloops = strtoul(argv[2], NULL, 0);
if (nloops == 0)
- nloops = 100000;
+ nloops = DEFAULT_ITER;
if (rank == 0) {
fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
/* Check case 2: first truncate then append */
if (memcmp(read_buf+chunk_size, trunc_buf,
trunc_offset-chunk_size)) {
- printf("loop %d: append-after-TRUNC"
- " bad [%d-%d]/[%#x-%#x] != 0\n",
+ printf("loop %d: append-after-TRUNC bad"
+ " [%d-%d]/[%#x-%#x] != 0\n",
n, chunk_size, trunc_offset - 1,
chunk_size, trunc_offset - 1);
error = 1;
} else if (memcmp(read_buf+trunc_offset,
append_buf, append_size)) {
- printf("loop %d: APPEND-after-trunc"
- " bad [%d-%d]/[%#x-%#x] != %c\n",
+ printf("loop %d: APPEND-after-trunc bad"
+ " [%d-%d]/[%#x-%#x] != %c\n",
n, trunc_offset, append_size - 1,
trunc_offset, append_size - 1,
APPEND_CHAR);
}
printf("rank %d, loop %d: finished\n", rank, n);
+ close(fd);
+
+ if (rank == 0) {
+ error = unlink(fname);
+ if (error < 0)
+ rprintf("unlink %s failed: %s\n",fname,strerror(errno));
+ }
MPI_Finalize();
return 0;