Whamcloud - gitweb
b=22766 cascading_rw: take lmm_stripe_count returned by ioctl(LL_IOC_LOV_SETSTRIPE)
[fs/lustre-release.git] / lustre / tests / mpi / mdsrate.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * 2003, Copyright, Hewlett-Packard Development Compnay, LP.
5  *
6  * Developed under the sponsorship of the U.S. Government
7  *     under Subcontract No. B514193
8  */
9
10 /*
11  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
12  * Use is subject to license terms.
13  */
14
15 #include <stdio.h>
16 #include <getopt.h>
17 #include <libgen.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <time.h>
21 #include <limits.h>
22 #include <errno.h>
23 #include <string.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28 #include <signal.h>
29 #include <sys/ioctl.h>
30 #include <dirent.h>
31
32 #include "mpi.h"
33
34 /* lustre */
35 #include <liblustre.h>
36 #include <lustre/liblustreapi.h>        /* for O_LOV_DELAY_CREATE */
37
38 #define CHECK_COUNT 10000
39 #define DISPLAY_COUNT (CHECK_COUNT * 10)
40 #define DISPLAY_TIME 100
41
42 enum {
43         CREATE   = 'c',
44         LOOKUP   = 'l',
45         MKNOD    = 'm',
46         OPEN     = 'o',
47         STAT     = 's',
48         UNLINK   = 'u',
49         BEGIN    = 'b',
50         ITERS    = 'i',
51         TIME     = 't',
52         DIRFMT   = 'd',
53         NDIRS    = 'D',
54         FILEFMT  = 'f',
55         NFILES   = 'F',
56         NOEXCL   = 'X',
57         STRIPES  = 'S',
58         SEED     = 'r',
59         SEEDFILE = 'R',
60         RANDOM   = 'A',
61         READDIR  = 'B',
62         RECREATE = 'C',
63         IGNORE   = 'E',
64         VERBOSE  = 'V',
65         DEBUG    = 'v',
66         HELP     = 'h',
67 };
68
69 struct option longOpts[] = {
70         {"create",        0, NULL, CREATE     },
71         {"lookup",        0, NULL, LOOKUP     },
72         {"mknod",         0, NULL, MKNOD      },
73         {"open",          0, NULL, OPEN       },
74         {"stat",          0, NULL, STAT       },
75         {"unlink",        0, NULL, UNLINK     },
76         {"begin",         1, NULL, BEGIN      },
77         {"iters",         1, NULL, ITERS      },
78         {"time",          1, NULL, TIME       },   /* seconds */
79         {"dirfmt",        1, NULL, DIRFMT     },
80         {"ndirs",         1, NULL, NDIRS      },
81         {"filefmt",       1, NULL, FILEFMT    },
82         {"nfiles",        1, NULL, NFILES     },
83         {"noexcl",        0, NULL, NOEXCL     },
84         {"stripes",       1, NULL, STRIPES    },
85         {"seed",          1, NULL, SEED       },
86         {"seedfile",      1, NULL, SEEDFILE   },
87         {"random_order",  0, NULL, RANDOM     },
88         {"readdir_order", 0, NULL, READDIR    },
89         {"recreate",      0, NULL, RECREATE   },
90         {"ignore",        0, NULL, IGNORE     },
91         {"verbose",       0, NULL, VERBOSE    },
92         {"debug",         0, NULL, DEBUG      },
93         {"help",          0, NULL, HELP       },
94         { 0,              0, NULL, 0          }
95 };
96
97 int foo1, foo2;
98
99 char   shortOpts[128];
100 int    myrank = -1;
101 int    nthreads = -1;
102 char * prog;
103 char   hostname[512] = "unknown";
104 char   mode;
105 char * cmd;
106 int    openflags = O_RDWR|O_CREAT|O_EXCL;
107 int    ndirs = 1;
108 char * dirfmt;
109 char   dir[PATH_MAX];
110 char   mkdir_cmd[PATH_MAX+14];
111 int    dirthreads;
112 int    dirnum;
113 DIR *  directory;
114 struct dirent *dir_entry;
115 int    nfiles;
116 char   filefmt[PATH_MAX];
117 char   filename[PATH_MAX];
118 int    stripes = -1;
119 int    begin;
120 int    beginsave;
121 int    end;
122 int    iters;
123 int    seconds;
124 int    alarm_caught;
125 struct sigaction act;
126 int    order = RANDOM;
127 int    seed;
128 int    recreate;
129 int    ignore;
130 int    verbose;
131 int    debug;
132 struct stat statbuf;
133
134 #define dmesg if (debug) printf
135
136 #define DISPLAY_PROGRESS() {                                                \
137         if (verbose && (nops % CHECK_COUNT == 0)) {                         \
138                 curTime = MPI_Wtime();                                      \
139                 interval = curTime - lastTime;                              \
140                 if (interval > DISPLAY_TIME || nops % DISPLAY_COUNT == 0) { \
141                         rate = (double)(nops - lastOps)/interval;           \
142                         printf("Rank %d: %.2f %ss/sec %.2f secs "           \
143                                "(total: %d %ss %.2f secs)\n",               \
144                                myrank, rate, cmd, interval,                 \
145                                nops, cmd, curTime - startTime);             \
146                         lastOps = nops;                                     \
147                         lastTime = curTime;                                 \
148                 }                                                           \
149         }                                                                   \
150 }
151
152 char *usage_msg = "usage: %s\n"
153                   "    { --create [ --noexcl ] | --lookup | --mknod |\n"
154                   "      --open | --stat | --unlink  [ --recreate ] [ --ignore ] }\n"
155                   "    [ --help ] [ --verbose ] [ --debug ]\n"
156                   "    { [ --begin <num> ] --nfiles <num> }\n"
157                   "    [ --iters <num> ] [ --time <secs> ]\n"
158                   "    [ --dirfmt <str> ] [ --ndirs  <num> ]\n"
159                   "    [ --filefmt <str> ] [ --stripes <num> ]\n"
160                   "    [ --random_order [--seed <num> | --seedfile <file>] ]\n"
161                   "    [ --readdir_order ]\n";
162
163 static void
164 usage(FILE *stream, char *fmt, ...)
165 {
166         if (myrank == 0) {
167                 if (fmt != NULL) {
168                         va_list       ap;
169
170                         fprintf(stream, "%s: ", prog);
171                         va_start(ap, fmt);
172                         vfprintf(stderr, fmt, ap);
173                         va_end(ap);
174                 }
175                 fprintf(stream, usage_msg, prog);
176         }
177
178         MPI_Finalize();
179         exit(stream == stderr);
180 }
181
182 /* Print process myrank and message, and exit (i.e. a fatal error) */
183 static int
184 fatal(int rank, const char *fmt, ...)
185 {
186         if (rank == myrank) {
187                 va_list       ap;
188
189                 fprintf(stderr, "rank %d: ", rank);
190                 va_start(ap, fmt);
191                 vfprintf(stderr, fmt, ap);
192                 va_end(ap);
193         }
194
195         MPI_Abort(MPI_COMM_WORLD, 1);
196         exit(1);
197 }
198
199 static void
200 sigalrm_handler(int signum)
201 {
202         alarm_caught++;
203 }
204
205 /* HAVE_LLAPI_FILE_LOOKUP is defined by liblustreapi.h if this function is
206  * defined therein.  Otherwise we can do the equivalent operation via ioctl
207  * if we have access to a complete lustre build tree to get the various
208  * definitions - then compile with USE_MDC_LOOKUP defined. */
209 #if defined(HAVE_LLAPI_FILE_LOOKUP)
210 #define HAVE_MDC_LOOKUP
211 #elif defined(USE_MDC_LOOKUP)
212 #include <config.h>
213 #include <liblustre.h>
214 #include <linux/lustre_lib.h>
215
216 int llapi_file_lookup(int dirfd, const char *name)
217 {
218         struct obd_ioctl_data data = { 0 };
219         char rawbuf[8192];
220         char *buf = rawbuf;
221         int rc;
222
223         if (dirfd < 0 || name == NULL)
224                 return -EINVAL;
225
226         data.ioc_version = OBD_IOCTL_VERSION;
227         data.ioc_len = sizeof(data);
228         data.ioc_inlbuf1 = name;
229         data.ioc_inllen1 = strlen(name) + 1;
230
231         rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
232         if (rc) {
233                 fatal(myrank, "ioctl_pack failed: rc = %d\n", rc);
234                 return rc;
235         }
236
237         return ioctl(fd, IOC_MDC_LOOKUP, buf);
238 }
239 #define HAVE_MDC_LOOKUP
240 #endif
241
242 static void
243 process_args(int argc, char *argv[])
244 {
245         char   *cp, *endptr;
246         int    i, index, offset, tmpend, rc;
247         char   tmp[16];
248         FILE * seed_file;
249         struct option *opt;
250
251         setbuf(stdout, 0);
252         setbuf(stderr, 0);
253         prog = basename(argv[0]);
254         strcpy(filefmt, "f%d");
255         gethostname(hostname, sizeof(hostname));
256
257         /* auto create shortOpts rather than maintaining a static string. */
258         for (opt = longOpts, cp = shortOpts; opt->name != NULL; opt++, cp++) {
259                 *cp = opt->val;
260                 if (opt->has_arg)
261                         *++cp = ':';
262         }
263
264         while ((rc = getopt_long(argc,argv, shortOpts, longOpts,&index)) != -1) {
265                 switch (rc) {
266                 case OPEN:
267                         openflags &= ~(O_CREAT|O_EXCL);
268                 case CREATE:
269 #ifdef HAVE_MDC_LOOKUP
270                 case LOOKUP:
271 #endif
272                 case MKNOD:
273                 case STAT:
274                 case UNLINK:
275                         if (cmd != NULL) {
276                                 fatal(0, "Invalid - more than one operation "
277                                            "specified: --%s\n",
278                                         longOpts[index].name);
279                         }
280                         mode = rc;
281                         cmd = (char *)longOpts[index].name;
282                         break;
283                 case NOEXCL:
284                         if (mode != CREATE && mode != MKNOD) {
285                                 usage(stderr, "--noexcl only applies to "
286                                               "--create or --mknod.\n");
287                         }
288                         openflags &= ~O_EXCL;
289                         break;
290                 case RECREATE:
291                         if (mode != UNLINK) {
292                                 usage(stderr, "--recreate only makes sense"
293                                               "with --unlink.\n");
294                         }
295                         recreate++;
296                         break;
297                 case BEGIN:
298                         begin = strtol(optarg, &endptr, 0);
299                         if ((*endptr != 0) || (begin < 0)) {
300                                 fatal(0, "Invalid --start value.\n");
301                         }
302                         break;
303                 case ITERS:
304                         iters = strtol(optarg, &endptr, 0);
305                         if ((*endptr != 0) || (iters <= 0)) {
306                                 fatal(0, "Invalid --iters value.\n");
307                         }
308                         if (mode != LOOKUP && mode != OPEN) {
309                                 usage(stderr, "--iters only makes sense with "
310                                               "--lookup or --open.\n");
311                         }
312                         break;
313                 case TIME:
314                         seconds = strtol(optarg, &endptr, 0);
315                         if ((*endptr != 0) || (seconds <= 0)) {
316                                 fatal(0, "Invalid --time value.\n");
317                         }
318                         break;
319                 case DIRFMT:
320                         if (strlen(optarg) > (PATH_MAX - 16)) {
321                                 fatal(0, "--dirfmt too long\n");
322                         }
323                         dirfmt = optarg;
324                         break;
325                 case NDIRS:
326                         ndirs = strtol(optarg, &endptr, 0);
327                         if ((*endptr != 0) || (ndirs <= 0)) {
328                                 fatal(0, "Invalid --ndirs value.\n");
329                         }
330                         if ((ndirs > nthreads) &&
331                             ((mode == CREATE) || (mode == MKNOD))) {
332                                 fatal(0, "--ndirs=%d must be less than or "
333                                       "equal to the number of threads (%d).\n",
334                                       ndirs, nthreads);
335                         }
336                         break;
337                 case FILEFMT:
338                         if (strlen(optarg) > 4080) {
339                                 fatal(0, "--filefmt too long\n");
340                         }
341
342                         /* Use %%d where you want the file # in the name. */
343                         sprintf(filefmt, optarg, myrank);
344                         break;
345                 case NFILES:
346                         nfiles = strtol(optarg, &endptr, 0);
347                         if ((*endptr != 0) || (nfiles <= 0)) {
348                                 fatal(0, "Invalid --nfiles value.\n");
349                         }
350                         break;
351                 case STRIPES:
352                         stripes = strtol(optarg, &endptr, 0);
353                         if ((*endptr != 0) || (stripes < 0)) {
354                                 fatal(0, "Invalid --stripes value.\n");
355                         }
356
357                         if (stripes == 0) {
358                                 openflags |= O_LOV_DELAY_CREATE;
359                         } else {
360                                 fatal(0, "non-zero --stripes value "
361                                          "not yet supported.\n");
362                         }
363
364                         break;
365                 case SEED:
366                         seed = strtoul(optarg, &endptr, 0);
367                         if (*endptr) {
368                                 fatal(0, "bad --seed option %s\n", optarg);
369                         }
370                         break;
371                 case SEEDFILE:
372                         seed_file = fopen(optarg, "r");
373                         if (!seed_file) {
374                               fatal(myrank, "fopen(%s) error: %s\n",
375                                       optarg, strerror(errno));
376                         }
377
378                         for (i = -1; fgets(tmp, 16, seed_file) != NULL;) {
379                                 if (++i == myrank)
380                                         break;
381                         }
382
383                         if (i == myrank) {
384                                 rc = sscanf(tmp, "%d", &seed);
385                                 if ((rc != 1) || (seed < 0)) {
386                                         fatal(myrank, "Invalid seed value '%s' "
387                                               "at line %d in %s.\n",
388                                               tmp, i, optarg);
389                                 }
390                         } else {
391                                 fatal(myrank, "File '%s' too short. Does not "
392                                       "contain a seed for thread %d.\n",
393                                       optarg, myrank);
394                         }
395
396                         fclose(seed_file);
397                         break;
398                 case RANDOM:
399                 case READDIR:
400                         if (mode != LOOKUP && mode != OPEN)  {
401                                 fatal(0, "--%s can only be specified with "
402                                          "--lookup, or --open.\n",
403                                       (char *)longOpts[index].name);
404                         }
405                         order = rc;
406                         break;
407                 case IGNORE:
408                         ++ignore;
409                         break;
410                 case DEBUG:
411                         ++debug;
412                 case VERBOSE:
413                         ++verbose;
414                         break;
415                 case HELP:
416                         usage(stdout, NULL);
417                 default:
418                         usage(stderr, "unrecognized option: '%c'.\n", optopt);
419                 }
420         }
421
422         if (optind < argc) {
423                 usage(stderr, "too many arguments %d >= %d.\n", optind, argc);
424         }
425
426         if (mode == CREATE || mode == MKNOD || mode == UNLINK || mode == STAT) {
427                 if (seconds != 0) {
428                         if (nfiles == 0)
429                                 nfiles = INT_MAX;
430                 } else if (nfiles == 0) {
431                         usage(stderr, "--nfiles or --time must be specified "
432                                       "with %s.\n", cmd);
433                 }
434         } else if (mode == LOOKUP || mode == OPEN) {
435                 if (seconds != 0) {
436                         if (iters == 0)
437                                 iters = INT_MAX;
438                 } else if (iters == 0) {
439                         usage(stderr, "--iters or --time must be specifed "
440                                       "with %s.\n", cmd);
441                 }
442
443                 if (nfiles == 0) {
444                         usage(stderr, "--nfiles must be specifed with --%s.\n",
445                               cmd);
446                 }
447
448                 if (seed == 0) {
449                         int fd = open("/dev/urandom", O_RDONLY);
450
451                         if (fd >= 0) {
452                                 if (read(fd, &seed, sizeof(seed)) <
453                                     sizeof(seed))
454                                         seed = time(0);
455                                 close(fd);
456                         } else {
457                                 seed = time(0);
458                         }
459                 }
460
461                 srand(seed);
462
463                 dmesg("%s: rank %d seed %d (%s).\n", prog, myrank, seed,
464                       (order == RANDOM) ? "random_order" : "readdir_order");
465         } else {
466                 usage(stderr, "one --create, --mknod, --open, --stat,"
467 #ifdef HAVE_MDC_LOOKUP
468                       " --lookup,"
469 #endif
470                       " or --unlink must be specifed.");
471         }
472
473         /* support for multiple threads in a dir, set begin/end appropriately.*/
474         dirnum = myrank % ndirs;
475         dirthreads = nthreads / ndirs;
476         if (nthreads > (ndirs * dirthreads + dirnum))
477                 ++dirthreads;
478
479         offset = myrank / ndirs;
480
481         tmpend = begin + nfiles - 1;
482         if (tmpend <= 0)
483                 tmpend = INT_MAX;
484
485         end = begin + (nfiles / dirthreads) * dirthreads + offset;
486         if ((end > tmpend) || (end <= 0))
487                 end -= dirthreads;
488
489         begin += offset;
490         if (begin < 0)
491                 begin = INT_MAX;
492
493         beginsave = begin;
494
495         dmesg("%d: iters %d nfiles %d time %d begin %d end %d dirthreads %d."
496               "\n", myrank, iters, nfiles, seconds, begin, end, dirthreads);
497
498         if (dirfmt == NULL) {
499                 strcpy(dir, ".");
500         } else {
501                 sprintf(dir, dirfmt, dirnum);
502
503                 sprintf(mkdir_cmd, "/bin/mkdir -p %s", dir);
504                 #ifdef _LIGHTWEIGHT_KERNEL
505                         printf("NOTICE: not running system(%s)\n", mkdir_cmd);
506                 #else
507                         rc = system(mkdir_cmd);
508                         if (rc) {
509                                 fatal(myrank, "'%s' failed.\n", mkdir_cmd);
510                         }
511                 #endif
512
513                 rc = chdir(dir);
514                 if (rc) {
515                         fatal(myrank, "unable to chdir to '%s'.\n", dir);
516                 }
517         }
518 }
519
520 static inline char *next_file()
521 {
522         if (order == RANDOM) {
523                 sprintf(filename, filefmt, random() % nfiles);
524                 return(filename);
525         }
526
527         /* readdir order */
528
529         dir_entry = readdir(directory);
530         if (dir_entry == NULL) {
531                 rewinddir(directory);
532                 while ((dir_entry = readdir(directory)) != NULL) {
533                         if (dir_entry->d_name[0] != '.')
534                                 return(dir_entry->d_name);
535                 }
536
537                 fatal(myrank, "unable to read directory %s (%s).\n",
538                       dir, strerror(errno));
539         }
540
541         return(dir_entry->d_name);
542 }
543
544 int
545 main(int argc, char *argv[])
546 {
547         int    i, j, fd, rc, nops, lastOps;
548         int ag_ops = 0;
549         double ag_interval = 0;
550         double ag_rate = 0;
551         double rate, avg_rate, effective_rate;
552         double startTime, curTime, lastTime, interval;
553         time_t timestamp;
554         char * file;
555
556         rc = MPI_Init(&argc, &argv);
557         if (rc != MPI_SUCCESS)
558                 fatal(myrank, "MPI_Init failed: %d\n", rc);
559
560         rc = MPI_Comm_size(MPI_COMM_WORLD, &nthreads);
561         if (rc != MPI_SUCCESS)
562                 fatal(myrank, "MPI_Comm_size failed: %d\n", rc);
563
564         rc = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
565         if (rc != MPI_SUCCESS)
566                 fatal(myrank, "MPI_Comm_rank failed: %d\n", rc);
567
568         process_args(argc, argv);
569
570         timestamp = time(0);
571         if ((myrank == 0) || debug) {
572                 printf("%d: %s starting at %s",
573                        myrank, hostname, ctime(&timestamp));
574         }
575
576         /* if we're not measuring creation rates then precreate
577          * the files we're operating on. */
578         if ((mode != CREATE) && (mode != MKNOD) && !ignore) {
579                 /* create the files in reverse order. When we encounter
580                  * a file that already exists, assume the remainder of 
581                  * the files exist to save time. The timed performance
582                  * test scripts make use of this behavior. */
583                 for (i = end, j = 0; i >= begin; i -= dirthreads) {
584                         sprintf(filename, filefmt, i);
585                         fd = open(filename, openflags, 0644);
586                         if (fd < 0) {
587                                 if (errno == EEXIST)
588                                         break;
589                                 rc = errno;
590                                 fatal(myrank, "precreate open(%s) error: %s\n",
591                                       filename, strerror(rc));
592                         }
593                         j++;
594                         close(fd);
595                 }
596                 dmesg("%d: %s pre-created %d files.\n",myrank,hostname,j);
597
598                 rc = MPI_Barrier(MPI_COMM_WORLD);
599                 if (rc != MPI_SUCCESS)
600                         fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
601         }
602
603         if (order == READDIR) {
604                 directory = opendir(dir);
605                 if (directory == NULL) {
606                         rc = errno;
607                         fatal(myrank, "opendir(%s) error: %s\n",
608                               dir, strerror(rc));
609                 }
610
611                 timestamp = time(0);
612                 j = random() % nfiles;
613                 dmesg("%d: %s initializing dir offset %u: %s",
614                       myrank, hostname, j, ctime(&timestamp));
615
616                 for (i = 0; i <= j; i++) {
617                         if ((dir_entry = readdir(directory)) == NULL) {
618                                 fatal(myrank, "could not read entry number %d "
619                                       "in directory %s.\n", i, dir);
620                         }
621                 }
622
623                 timestamp = time(0);
624                 dmesg("%d: index %d, filename %s, offset %ld: "
625                       "%s initialization complete: %s",
626                       myrank, i, dir_entry->d_name, telldir(directory),
627                       hostname, ctime(&timestamp));
628         }
629
630         if (seconds) {
631                 act.sa_handler = sigalrm_handler;
632                 (void)sigemptyset(&act.sa_mask);
633                 act.sa_flags = 0;
634                 sigaction(SIGALRM, &act, NULL);
635                 alarm(seconds);
636         }
637
638         rc = MPI_Barrier(MPI_COMM_WORLD);
639         if (rc != MPI_SUCCESS)
640                 fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
641
642         startTime = lastTime = MPI_Wtime();
643         nops = lastOps = 0;
644
645         switch (mode) {
646         case CREATE:
647                 for (; begin <= end && !alarm_caught; begin += dirthreads) {
648                         sprintf(filename, filefmt, begin);
649                         if ((fd = open(filename, openflags, 0644)) < 0) {
650                                 if (((rc = errno) == EINTR) && alarm_caught)
651                                         break;
652                                 fatal(myrank, "open(%s) error: %s\n",
653                                       filename, strerror(rc));
654                         }
655
656                         close(fd);
657                         nops++;
658                         DISPLAY_PROGRESS();
659                 }
660
661                 dmesg("%d: created %d files, last file '%s'.\n",
662                       myrank, nops, filename);
663                 break;
664 #ifdef HAVE_MDC_LOOKUP
665         case LOOKUP:
666                 fd = open(dir, O_RDONLY);
667                 if (fd < 0) {
668                         fatal(myrank, "open(dir == '%s') error: %s\n",
669                               dir, strerror(errno));
670                 }
671
672                 for (; nops < iters && !alarm_caught;) {
673                         char *filename = next_file();
674                         rc = llapi_file_lookup(fd, filename);
675                         if (rc < 0) {
676                                 if (((rc = errno) == EINTR) && alarm_caught)
677                                         break;
678                                 fatal(myrank, "llapi_file_lookup(%s) "
679                                       "error: %s\n", filename, strerror(rc));
680                         }
681
682                         nops++;
683                         DISPLAY_PROGRESS();
684                 }
685                 break;
686 #endif
687         case MKNOD:
688                 for (; begin <= end && !alarm_caught; begin += dirthreads) {
689                         sprintf(filename, filefmt, begin);
690                         rc = mknod(filename, S_IFREG| 0644, 0);
691                         if (rc) {
692                                 if (((rc = errno) == EINTR) && alarm_caught)
693                                         break;
694                                 fatal(myrank, "mknod(%s) error: %s\n",
695                                       filename, strerror(rc));
696                         }
697
698                         nops++;
699                         DISPLAY_PROGRESS();
700                 }
701                 break;
702         case OPEN:
703                 for (; nops < iters && !alarm_caught;) {
704                         file = next_file();
705                         if ((fd = open(file, openflags, 0644)) < 0) {
706                                 if (((rc = errno) == EINTR) && alarm_caught)
707                                         break;
708                                 fatal(myrank, "open(%s) error: %s\n",
709                                       file, strerror(rc));
710                         }
711
712                         close(fd);
713
714                         nops++;
715                         DISPLAY_PROGRESS();
716                 }
717                 break;
718         case STAT:
719                 for (; begin <= end && !alarm_caught; begin += dirthreads) {
720                         sprintf(filename, filefmt, begin);
721                         rc = stat(filename, &statbuf);
722                         if (rc) {
723                                 if (((rc = errno) == EINTR) && alarm_caught)
724                                         break;
725                                 if (((rc = errno) == ENOENT) && ignore)
726                                         continue;
727                                 fatal(myrank, "stat(%s) error: %s\n",
728                                       filename, strerror(rc));
729                         }
730
731                         nops++;
732                         DISPLAY_PROGRESS();
733                 }
734                 break;
735         case UNLINK:
736                 for (; begin <= end && !alarm_caught; begin += dirthreads) {
737                         sprintf(filename, filefmt, begin);
738                         rc = unlink(filename);
739                         if (rc) {
740                                 if (((rc = errno) == EINTR) && alarm_caught)
741                                         break;
742                                 if (((rc = errno) == ENOENT) && ignore)
743                                         continue;
744                                 fatal(myrank, "unlink(%s) error: %s\n",
745                                       filename, strerror(rc));
746                         }
747
748                         nops++;
749                         DISPLAY_PROGRESS();
750                 }
751                 break;
752         }
753
754         rc = MPI_Barrier(MPI_COMM_WORLD);
755         if (rc != MPI_SUCCESS)
756                fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
757         curTime = MPI_Wtime();
758         interval = curTime - startTime;
759         rate = (double) (nops) / interval;
760
761         rc = MPI_Reduce(&nops, &ag_ops, 1, MPI_INT, MPI_SUM, 0,
762                         MPI_COMM_WORLD);
763         if (rc != MPI_SUCCESS) {
764                 fatal(myrank, "Failure in MPI_Reduce of total ops.\n");
765         }
766
767         rc = MPI_Reduce(&interval, &ag_interval, 1, MPI_DOUBLE, MPI_SUM, 0,
768                         MPI_COMM_WORLD);
769         if (rc != MPI_SUCCESS) {
770                 fatal(myrank, "Failure in MPI_Reduce of total interval.\n");
771         }
772
773         rc = MPI_Reduce(&rate, &ag_rate, 1, MPI_DOUBLE, MPI_SUM, 0,
774                         MPI_COMM_WORLD);
775         if (rc != MPI_SUCCESS) {
776                 fatal(myrank, "Failure in MPI_Reduce of aggregated rate.\n");
777         }
778
779         if (myrank == 0) {
780
781                 curTime = MPI_Wtime();
782                 interval = curTime - startTime;
783                 effective_rate = (double) ag_ops / interval;
784                 avg_rate = (double) ag_ops / ag_interval;
785
786                 printf("Rate: %.2f eff %.2f aggr %.2f avg client %ss/sec "
787                        "(total: %d threads %d %ss %d dirs %d threads/dir %.2f secs)\n",
788                        effective_rate, ag_rate, avg_rate, cmd, nthreads, ag_ops,
789                        cmd, ndirs, dirthreads, interval);
790         }
791
792         if (recreate) {
793                 for (begin = beginsave; begin <= end; begin += dirthreads) {
794                         sprintf(filename, filefmt, begin);
795                         if ((fd = open(filename, openflags, 0644)) < 0) {
796                                 rc = errno;
797                                 if (rc == EEXIST)
798                                         break;
799                                 fatal(myrank, "recreate open(%s) error: %s\n",
800                                       filename, strerror(rc));
801                         }
802
803                         close(fd);
804                 }
805         }
806
807         timestamp = time(0);
808         if ((myrank == 0) || debug) {
809                 printf("%d: %s finished at %s",
810                        myrank, hostname, ctime(&timestamp));
811         }
812
813         MPI_Finalize();
814         return(0);
815 }