Whamcloud - gitweb
LU-11233 tests: fix gcc8 build warnings
[fs/lustre-release.git] / lustre / tests / mpi / write_disjoint.c
index 8ddc497..9ab6f44 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <errno.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <time.h>
 #include "mpi.h"
 
-#define CHUNK_MAX_SIZE 123456
+/* Chosen arbitrarily.  Actually running this large will take a long time.*/
+#define CHUNK_MAX_SIZE (1024*1024*16)
 
 void rprintf(int rank, int loop, const char *fmt, ...)
 {
@@ -88,19 +86,34 @@ int main (int argc, char *argv[]) {
         ssize_t ret;
         char *filename = "/mnt/lustre/write_disjoint";
         int numloops = 1000;
+       int max_size = CHUNK_MAX_SIZE;
+        int random = 0;
+       unsigned int seed = 0;
+       int seed_provided = 0;
 
         error = MPI_Init(&argc, &argv);
         if (error != MPI_SUCCESS)
                 rprintf(-1, -1, "MPI_Init failed: %d\n", error);
         /* Parse command line options */
-        while ((c = getopt(argc, argv, "f:n:")) != EOF) {
+       while ((c = getopt(argc, argv, "f:n:m:s:")) != EOF) {
+               errno = 0;
                 switch (c) {
                 case 'f':
                         filename = optarg;
                         break;
                 case 'n':
                         numloops = strtoul(optarg, NULL, 0);
+                       break;
+               case 'm':
+                       max_size = strtoul(optarg, NULL, 0);
+                       if (max_size > CHUNK_MAX_SIZE)
+                               rprintf(-1, -1, "Chunk size larger than %d.\n",
+                                       CHUNK_MAX_SIZE);
                         break;
+               case 's':
+                       seed = strtoul(optarg, NULL, 0);
+                       seed_provided = 1;
+                       break;
                 }
         }
 
@@ -109,10 +122,10 @@ int main (int argc, char *argv[]) {
 
         chunk_buf = malloc(noProcessors * sizeof(chunk_buf[0]));
         for (i=0; i < noProcessors; i++) {
-                chunk_buf[i] = malloc(CHUNK_MAX_SIZE);
-                memset(chunk_buf[i], 'A'+ i, CHUNK_MAX_SIZE);
+               chunk_buf[i] = malloc(max_size);
+               memset(chunk_buf[i], 'A' + i, max_size);
         }
-        read_buf = malloc(noProcessors * CHUNK_MAX_SIZE);
+       read_buf = malloc(noProcessors * max_size);
 
         if (rank == 0) {
                 fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
@@ -126,6 +139,14 @@ int main (int argc, char *argv[]) {
         if (fd < 0)
                 rprintf(rank, -1, "open() returned %s\n", strerror(errno));
 
+       if (rank == 0) {
+               if (!seed_provided)
+                       seed = (unsigned int) time(NULL);
+               printf("random seed: %d\n", seed);
+               srand(seed);
+       }
+
+
         for (n = 0; n < numloops; n++) {
                 /* reset the environment */
                 if (rank == 0) {
@@ -133,12 +154,24 @@ int main (int argc, char *argv[]) {
                         if (ret != 0)
                                 rprintf(rank, n, "truncate() returned %s\n",
                                         strerror(errno) );
+
+                        random = rand();
                 }
-                CHUNK_SIZE(n) = rand() % CHUNK_MAX_SIZE;
+                MPI_Bcast(&random, 1, MPI_INT, 0, MPI_COMM_WORLD);
+               CHUNK_SIZE(n) = random % max_size;
 
                 if (n % 1000 == 0 && rank == 0)
                         printf("loop %d: chunk_size %lu\n", n, CHUNK_SIZE(n));
 
+                if (stat(filename, &stat_buf) < 0)
+                        rprintf(rank, n, "error stating %s: %s\n",
+                                filename, strerror(errno));
+
+                if (stat_buf.st_size != 0)
+                        rprintf(rank, n, "filesize = %lu. "
+                                "Should be zero after truncate\n",
+                                stat_buf.st_size);
+
                 MPI_Barrier(MPI_COMM_WORLD);
 
                 /* Do the race */
@@ -194,7 +227,8 @@ int main (int argc, char *argv[]) {
 
                         for (i = 0; i < noProcessors; i++) {
                                 char command[4096];
-                                int j, rc;
+                                int j;
+                               
                                 if (!memcmp(read_buf + (i * CHUNK_SIZE(n)),
                                             chunk_buf[i], CHUNK_SIZE(n)))
                                         continue;
@@ -219,7 +253,7 @@ int main (int argc, char *argv[]) {
                                 }
 
                                 sprintf(command, "od -Ad -a %s", filename);
-                                rc = system(command);
+                                ret = system(command);
                                 rprintf(0, n, "data check error - exiting\n");
                         }
                 }