darshan-coll-write-strategy-test.patch 8.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
Index: lib/darshan-posix.c
===================================================================
--- lib/darshan-posix.c	(revision 444)
+++ lib/darshan-posix.c	(working copy)
@@ -1486,8 +1486,7 @@
     return;
 }
 
-#if 0
-void darshan_shutdown_bench(int argc, char** argv, int rank, int nprocs)
+void darshan_shutdown_bench(int argc, char** argv, int rank, int nprocs, int mode)
 {
     int* fd_array;
     int64_t* size_array;
@@ -1539,7 +1538,7 @@
 
     if(rank == 0)
         printf("# 1 unique file per proc\n");
-    darshan_shutdown(1);
+    darshan_shutdown(1, mode);
     darshan_global_job = NULL;
 
     /***********************************************************/
@@ -1562,7 +1561,7 @@
 
     if(rank == 0)
         printf("# 1 shared file across procs\n");
-    darshan_shutdown(1);
+    darshan_shutdown(1, mode);
     darshan_global_job = NULL;
 
     /***********************************************************/
@@ -1585,7 +1584,7 @@
 
     if(rank == 0)
         printf("# 1024 unique files per proc\n");
-    darshan_shutdown(1);
+    darshan_shutdown(1, mode);
     darshan_global_job = NULL;
 
     /***********************************************************/
@@ -1608,7 +1607,7 @@
 
     if(rank == 0)
         printf("# 1024 shared files across procs\n");
-    darshan_shutdown(1);
+    darshan_shutdown(1, mode);
     darshan_global_job = NULL;
 
     darshan_initialize(argc, argv, nprocs, rank);
@@ -1714,7 +1713,6 @@
     free(fd_array);
     free(size_array);
 }
-#endif
 
 static double posix_wtime(void)
 {
Index: lib/darshan-mpi-io.c
===================================================================
--- lib/darshan-mpi-io.c	(revision 444)
+++ lib/darshan-mpi-io.c	(working copy)
@@ -315,7 +315,7 @@
     int rank, int* inout_count, int* lengths, void** pointers, char*
     trailing_data);
 static int cp_log_write(struct darshan_job_runtime* final_job, int rank, 
-    char* logfile_name, int count, int* lengths, void** pointers, double start_log_time);
+    char* logfile_name, int count, int* lengths, void** pointers, double start_log_time, int mode);
 static int cp_log_reduction(struct darshan_job_runtime* final_job, int rank, 
     char* logfile_name, MPI_Offset* next_offset);
 static void darshan_file_reduce(void* infile_v, 
@@ -407,7 +407,7 @@
     return;
 }
 
-void darshan_shutdown(int timing_flag)
+void darshan_shutdown(int timing_flag, int mode)
 {
     int rank;
     char* logfile_name;
@@ -720,7 +720,7 @@
         if(timing_flag)
             write1 = DARSHAN_MPI_CALL(PMPI_Wtime)();
         local_ret = cp_log_write(final_job, rank, logfile_name, 
-            index_count, lengths, pointers, start_log_time);
+            index_count, lengths, pointers, start_log_time, mode);
         if(timing_flag)
             write2 = DARSHAN_MPI_CALL(PMPI_Wtime)();
         DARSHAN_MPI_CALL(PMPI_Allreduce)(&local_ret, &all_ret, 1,
@@ -787,9 +787,9 @@
     int ret;
 
     if(getenv("DARSHAN_INTERNAL_TIMING"))
-        darshan_shutdown(1);
+        darshan_shutdown(1, 0);
     else
-        darshan_shutdown(0);
+        darshan_shutdown(0, 0);
 
     ret = DARSHAN_MPI_CALL(PMPI_Finalize)();
     return(ret);
@@ -1848,7 +1848,7 @@
  * actually write log information to disk
  */
 static int cp_log_write(struct darshan_job_runtime* final_job, int rank, 
-    char* logfile_name, int count, int* lengths, void** pointers, double start_log_time)
+    char* logfile_name, int count, int* lengths, void** pointers, double start_log_time, int mode)
 {
     int ret;
     MPI_File fh;
@@ -1861,6 +1861,7 @@
     MPI_Aint displacements[CP_MAX_MEM_SEGMENTS];
     void* buf;
     int failed_write = 0;
+    MPI_Info info;
 
     /* skip building a datatype if we don't have anything to write */
     if(count > 0)
@@ -1883,24 +1884,21 @@
         DARSHAN_MPI_CALL(PMPI_Type_commit)(&mtype); 
     }
 
-    ret = DARSHAN_MPI_CALL(PMPI_File_open)(MPI_COMM_WORLD, logfile_name,
-        MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_EXCL, MPI_INFO_NULL, &fh);
-    if(ret != MPI_SUCCESS)
+    if(mode == 0)
     {
-        /* TODO: keep this print or not? */
+        /* in this mode, try pre-creating the file on rank 0 to avoid
+         * metadata contention in collective open
+         */
         if(rank == 0)
         {
-            int msg_len;
-            char msg[MPI_MAX_ERROR_STRING] = {0};
-            
-            MPI_Error_string(ret, msg, &msg_len);
-            fprintf(stderr, "darshan library warning: unable to open log file %s: %s\n", logfile_name, msg);
+            ret = DARSHAN_MPI_CALL(PMPI_File_open)(MPI_COMM_SELF, logfile_name,
+                MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_EXCL, 
+                MPI_INFO_NULL, &fh);
+            if(ret == MPI_SUCCESS)
+                DARSHAN_MPI_CALL(PMPI_File_close(&fh));
         }
-        if(count > 0)
-            DARSHAN_MPI_CALL(PMPI_Type_free)(&mtype);
-        return(-1);
     }
-  
+ 
     /* figure out where everyone is writing */
     if(count > 0)
         DARSHAN_MPI_CALL(PMPI_Type_size)(mtype, &my_total);
@@ -1912,6 +1910,60 @@
     /* scan is inclusive; subtract local size back out */
     offset -= my_total_long;
 
+    if(mode > 0)
+    {
+        /* in this mode, no precreate, but we set romio hints to tell it
+         * that we are only going to do collective operations (so that files
+         * are only opened on the aggregators).  We also use the value of
+         * mode to set the number of aggregators.
+         */
+        char cb_nodes_string[10];
+        sprintf(cb_nodes_string, "%d", mode);
+
+        MPI_Info_create(&info);
+        /* make sure that collective buffering is on */
+        MPI_Info_set(info, "romio_cb_write", "enable"); 
+        /* tell ROMIO that we will only do collective operations to this file,
+         * so that it can avoid opening the file on every proc. 
+         */
+        MPI_Info_set(info, "romio_no_indep_rw", "true"); 
+        /* use exactly one process as an aggregator */
+        MPI_Info_set(info, "cb_nodes", cb_nodes_string);
+
+        ret = DARSHAN_MPI_CALL(PMPI_File_open)(MPI_COMM_WORLD, logfile_name,
+            MPI_MODE_CREATE | MPI_MODE_EXCL |MPI_MODE_WRONLY, info, &fh);
+
+        MPI_Info_free(&info);
+    }
+    else if(mode == 0)
+    {
+        /* must have been precreated */
+        ret = DARSHAN_MPI_CALL(PMPI_File_open)(MPI_COMM_WORLD, logfile_name,
+            MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);
+    }
+    else
+    {
+        /* negative mode; do what we've always done */
+        ret = DARSHAN_MPI_CALL(PMPI_File_open)(MPI_COMM_WORLD, logfile_name,
+            MPI_MODE_CREATE | MPI_MODE_EXCL| MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);
+    }
+
+    if(ret != MPI_SUCCESS)
+    {
+        /* TODO: keep this print or not? */
+        if(rank == 0)
+        {
+            int msg_len;
+            char msg[MPI_MAX_ERROR_STRING] = {0};
+            
+            MPI_Error_string(ret, msg, &msg_len);
+            fprintf(stderr, "darshan library warning: unable to open log file %s: %s\n", logfile_name, msg);
+        }
+        if(count > 0)
+            DARSHAN_MPI_CALL(PMPI_Type_free)(&mtype);
+        return(-1);
+    }
+ 
     if(count > 0)
     {
         /* collectively write out file records from all processes */
Index: darshan.h
===================================================================
--- darshan.h	(revision 444)
+++ darshan.h	(working copy)
@@ -207,8 +207,8 @@
 void darshan_finalize(struct darshan_job_runtime* job);
 void darshan_condense(void);
 void darshan_search_bench(int argc, char** argv, int iters);
-void darshan_shutdown(int timing_flag);
-void darshan_shutdown_bench(int argc, char** argv, int rank, int nprocs);
+void darshan_shutdown(int timing_flag, int mode);
+void darshan_shutdown_bench(int argc, char** argv, int rank, int nprocs, int mode);
 void darshan_walk_file_accesses(struct darshan_job_runtime* final_job);
 double darshan_wtime(void);
 
Index: test/cp-shutdown-bench.c
===================================================================
--- test/cp-shutdown-bench.c	(revision 444)
+++ test/cp-shutdown-bench.c	(working copy)
@@ -23,7 +23,7 @@
     int i;
     int ret;
     int fd;
-    int iters;
+    int mode;
 
     MPI_Init(&argc, &argv);
     MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
@@ -37,7 +37,7 @@
         return(-1);
     }
 
-    ret = sscanf(argv[1], "%d", &iters);
+    ret = sscanf(argv[1], "%d", &mode);
     if(ret != 1)
     {
         fprintf(stderr, "Usage: %s <number of iterations>\n", argv[0]);
@@ -47,10 +47,16 @@
 
     if(mynod == 0)
     {
-        printf("ignoring iters argument for now.\n");
+	if(mode < 0)
+        	printf("# using old method (no precreate or hints)\n");
+	if(mode == 0)
+        	printf("# using precreate)\n");
+	if(mode > 0)
+		printf("# using hints, with cb_nodes %d\n", mode);
+
     }
 
-    darshan_shutdown_bench(argc, argv, mynod, nprocs);
+    darshan_shutdown_bench(argc, argv, mynod, nprocs, mode);
 
     MPI_Finalize();
     return(0);