1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
18 void usage(char *prog)
20 printf("usage: %s {-o|-m|-l<tgt>} filenamefmt count\n", prog);
21 printf(" %s {-o|-m|-l<tgt>} filenamefmt -seconds\n", prog);
22 printf(" %s {-o|-m|-l<tgt>} filenamefmt start count\n", prog);
25 /* Print process rank, loop count, message, and exit (i.e. a fatal error) */
26 int rprintf(int rank, int loop, const char *fmt, ...)
30 printf("rank %d, loop %d: ", rank, loop);
40 int main(int argc, char ** argv)
42 int i, rc = 0, do_open = 0, do_link = 0, rank;
43 char format[4096], *fmt, *tgt;
45 long start, last, end;
46 long begin = 0, count;
48 rc = MPI_Init(&argc, &argv);
49 if (rc != MPI_SUCCESS)
50 rprintf(-1, -1, "MPI_Init failed: %d\n", rc);
52 if (argc < 4 || argc > 5) {
57 if (strcmp(argv[1], "-o") == 0) {
60 } else if (strncmp(argv[1], "-l", 2) == 0 && argv[1][2]) {
63 } else if (strcmp(argv[1], "-m") != 0) {
68 if (strlen(argv[2]) > 4080) {
69 printf("name too long\n");
73 rc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
74 if (rc != MPI_SUCCESS)
75 rprintf(-1, -1, "MPI_Comm_rank failed: %d\n", rc);
77 rc = MPI_Barrier(MPI_COMM_WORLD);
78 if (rc != MPI_SUCCESS)
79 rprintf(rank, -1, "prep MPI_Barrier failed: %d\n", rc);
81 start = last = time(0);
84 end = strtol(argv[3], NULL, 0);
86 begin = strtol(argv[3], NULL, 0);
87 end = strtol(argv[4], NULL, 0);
97 if (strchr(argv[2], '%'))
100 sprintf(format, "%s%%d", argv[2]);
103 printf("starting at %s", ctime(&start));
104 for (i = 0; i < count && time(0) < end; i++, begin++) {
105 sprintf(filename, fmt, begin);
107 int fd = open(filename, O_CREAT|O_RDWR, 0644);
109 printf("open(%s) error: %s\n", filename,
115 } else if (do_link) {
116 rc = link(tgt, filename);
118 printf("link(%s, %s) error: %s\n",
119 tgt, filename, strerror(errno));
124 rc = mknod(filename, S_IFREG| 0444, 0);
126 printf("mknod(%s) error: %s\n",
127 filename, strerror(errno));
132 if ((i % 10000) == 0) {
133 printf(" - created %d (time %ld total %ld last %ld)\n",
134 i, time(0), time(0) - start, time(0) - last);
138 printf("total: %d creates in %ld seconds: %f creates/second\n", i,
139 time(0) - start, ((float)i / (time(0) - start)));
141 printf("finish at %s", ctime(&start));