[mpich2-commits] r7958 - in mpich2/trunk/src/mpi/romio/adio: ad_bgl common

robl at mcs.anl.gov robl at mcs.anl.gov
Mon Feb 14 14:17:34 CST 2011


Author: robl
Date: 2011-02-14 14:17:34 -0600 (Mon, 14 Feb 2011)
New Revision: 7958

Modified:
   mpich2/trunk/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c
   mpich2/trunk/src/mpi/romio/adio/common/ad_write_coll.c
Log:
Wei-keng Liao (wkliao at ece.northwestern.edu) fixed a place Jeff Daley and
Valgrind found where having no work would result in an extra read in romio's
hole detection. 


Modified: mpich2/trunk/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c
===================================================================
--- mpich2/trunk/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c	2011-02-14 19:48:04 UTC (rev 7957)
+++ mpich2/trunk/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c	2011-02-14 20:17:34 UTC (rev 7958)
@@ -799,12 +799,15 @@
 
     sum = 0;
     for (i=0; i<nprocs; i++) sum += count[i];
-    srt_off = (ADIO_Offset *) ADIOI_Malloc((sum+1)*sizeof(ADIO_Offset));
-    srt_len = (int *) ADIOI_Malloc((sum+1)*sizeof(int));
-    /* +1 to avoid a 0-size malloc */
+    /* valgrind-detcted optimization: if there is no work on this process we do
+     * not need to search for holes */
+    if (sum) {
+	srt_off = (ADIO_Offset *) ADIOI_Malloc((sum)*sizeof(ADIO_Offset));
+	srt_len = (int *) ADIOI_Malloc((sum)*sizeof(int));
 
-    ADIOI_Heap_merge(others_req, count, srt_off, srt_len, start_pos,
-                     nprocs, nprocs_recv, sum);
+        ADIOI_Heap_merge(others_req, count, srt_off, srt_len, start_pos,
+                         nprocs, nprocs_recv, sum);
+    }
 
 /* for partial recvs, restore original lengths */
     for (i=0; i<nprocs; i++) 
@@ -821,23 +824,25 @@
      * #835). Missing these holes would result in us writing more data than
      * recieved by everyone else. */
     *hole = 0;
-    if (off != srt_off[0]) /* hole at the front */
-        *hole = 1;
-    else { /* coalesce the sorted offset-length pairs */
-        for (i=1; i<sum; i++) {
-            if (srt_off[i] <= srt_off[0] + srt_len[0]) {
-		int new_len = srt_off[i] + srt_len[i] - srt_off[0];
-		if (new_len > srt_len[0]) srt_len[0] = new_len;
+    if (sum) {
+        if (off != srt_off[0]) /* hole at the front */
+            *hole = 1;
+        else { /* coalesce the sorted offset-length pairs */
+            for (i=1; i<sum; i++) {
+                if (srt_off[i] <= srt_off[0] + srt_len[0]) {
+		    int new_len = srt_off[i] + srt_len[i] - srt_off[0];
+		    if (new_len > srt_len[0]) srt_len[0] = new_len;
+	        }
+                else
+                    break;
 	    }
-            else
-                break;
-        }
-        if (i < sum || size != srt_len[0]) /* hole in middle or end */
-            *hole = 1;
-	}
+            if (i < sum || size != srt_len[0]) /* hole in middle or end */
+                *hole = 1;
+	    }
 
     ADIOI_Free(srt_off);
     ADIOI_Free(srt_len);
+    }
 
     if (nprocs_recv) {
 	if (*hole) {

Modified: mpich2/trunk/src/mpi/romio/adio/common/ad_write_coll.c
===================================================================
--- mpich2/trunk/src/mpi/romio/adio/common/ad_write_coll.c	2011-02-14 19:48:04 UTC (rev 7957)
+++ mpich2/trunk/src/mpi/romio/adio/common/ad_write_coll.c	2011-02-14 20:17:34 UTC (rev 7958)
@@ -624,12 +624,15 @@
 
     sum = 0;
     for (i=0; i<nprocs; i++) sum += count[i];
-    srt_off = (ADIO_Offset *) ADIOI_Malloc((sum+1)*sizeof(ADIO_Offset));
-    srt_len = (int *) ADIOI_Malloc((sum+1)*sizeof(int));
-    /* +1 to avoid a 0-size malloc */
+    /* valgrind-detcted optimization: if there is no work on this process we do
+     * not need to search for holes */
+    if (sum) {
+        srt_off = (ADIO_Offset *) ADIOI_Malloc(sum*sizeof(ADIO_Offset));
+        srt_len = (int *) ADIOI_Malloc(sum*sizeof(int));
 
-    ADIOI_Heap_merge(others_req, count, srt_off, srt_len, start_pos,
-                     nprocs, nprocs_recv, sum);
+        ADIOI_Heap_merge(others_req, count, srt_off, srt_len, start_pos,
+                         nprocs, nprocs_recv, sum);
+    }
 
 /* for partial recvs, restore original lengths */
     for (i=0; i<nprocs; i++) 
@@ -647,24 +650,26 @@
      * recieved by everyone else. */
 
     *hole = 0;
-    if (off != srt_off[0]) /* hole at the front */
-        *hole = 1;
-    else { /* coalesce the sorted offset-length pairs */
-        for (i=1; i<sum; i++) {
-            if (srt_off[i] <= srt_off[0] + srt_len[0]) {
-		int new_len = srt_off[i] + srt_len[i] - srt_off[0];
-		if (new_len > srt_len[0]) srt_len[0] = new_len;
+    if (sum) {
+        if (off != srt_off[0]) /* hole at the front */
+            *hole = 1;
+        else { /* coalesce the sorted offset-length pairs */
+            for (i=1; i<sum; i++) {
+                if (srt_off[i] <= srt_off[0] + srt_len[0]) {
+		    int new_len = srt_off[i] + srt_len[i] - srt_off[0];
+		    if (new_len > srt_len[0]) srt_len[0] = new_len;
+		}
+		else
+			break;
 	    }
-            else
-                break;
-        }
-        if (i < sum || size != srt_len[0]) /* hole in middle or end */
-            *hole = 1;
+            if (i < sum || size != srt_len[0]) /* hole in middle or end */
+                *hole = 1;
+	}
+
+        ADIOI_Free(srt_off);
+        ADIOI_Free(srt_len);
     }
 
-    ADIOI_Free(srt_off);
-    ADIOI_Free(srt_len);
-
     if (nprocs_recv) {
 	if (*hole) {
 	    ADIO_ReadContig(fd, write_buf, size, MPI_BYTE, 



More information about the mpich2-commits mailing list