[mpich2-dev] [PATCH 1/1] Issue 4120: Finish ad_bgl offset/aint changes (similar to common/)

Bob Cernohous bobc at us.ibm.com
Tue Mar 18 10:24:21 CDT 2008


Signed-off-by: Bob Cernohous <bobc at us.ibm.com>
---
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_rdcoll.c      |  101 ++++++++++--------
 .../mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_read.c |  101 +++++++++--------
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c      |   72 ++++++++-----
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_write.c       |  113 +++++++++++---------
 .../mpich2/src/mpi/romio/adio/common/ad_read_str.c |    6 +-
 .../src/mpi/romio/adio/common/ad_write_coll.c      |    6 +-
 6 files changed, 220 insertions(+), 179 deletions(-)

diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_rdcoll.c b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_rdcoll.c
index c4c5deb..1a6c0c8 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_rdcoll.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_rdcoll.c
@@ -236,7 +236,7 @@ void ADIOI_BGL_ReadStridedColl(ADIO_File fd, void *buf, int count,
 
 	if (buftype_is_contig && filetype_is_contig) {
 	    if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
-		off = fd->disp + (fd->etype_size) * offset;
+		off = fd->disp + (ADIO_Offset)(fd->etype_size) * offset;
 		ADIO_ReadContig(fd, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
                        off, status, error_code);
 	    }
@@ -413,12 +413,14 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
    array from a file, where each local array is 8Mbytes, requiring
    at least another 8Mbytes of temp space is unacceptable. */
 
-    int i, j, m, size, ntimes, max_ntimes, buftype_is_contig;
+    int i, j, m, ntimes, max_ntimes, buftype_is_contig;
     ADIO_Offset st_loc=-1, end_loc=-1, off, done, real_off, req_off;
     char *read_buf = NULL, *tmp_buf;
     int *curr_offlen_ptr, *count, *send_size, *recv_size;
-    int *partial_send, *recd_from_proc, *start_pos, for_next_iter;
-    int real_size, req_len, flag, for_curr_iter, rank;
+    int *partial_send, *recd_from_proc, *start_pos;
+    /* Not convinced end_loc-st_loc couldn't be > int, so make these offsets*/
+    ADIO_Offset real_size, size, for_curr_iter, for_next_iter;
+    int req_len, flag, rank;
     MPI_Status status;
     ADIOI_Flatlist_node *flat_buf=NULL;
     MPI_Aint buftype_extent;
@@ -557,7 +559,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 #ifdef PROFILE
         MPE_Log_event(13, 0, "start computation");
 #endif
-	size = (int) (ADIOI_MIN(coll_bufsize, end_loc-st_loc+1-done)); 
+	size = ADIOI_MIN((unsigned)coll_bufsize, end_loc-st_loc+1-done); 
 	real_off = off - for_curr_iter;
 	real_size = size + for_curr_iter;
 
@@ -590,22 +592,22 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 		    }
 		    if (req_off < real_off + real_size) {
 			count[i]++;
+      ADIOI_Assert((((ADIO_Offset)(unsigned long)read_buf)+req_off-real_off) == (ADIO_Offset)(unsigned long)(read_buf+req_off-real_off));
 			MPI_Address(read_buf+req_off-real_off, 
                                &(others_req[i].mem_ptrs[j]));
-			send_size[i] += (int)(ADIOI_MIN(real_off + (ADIO_Offset)real_size - 
-						  req_off, req_len));
+      ADIOI_Assert((real_off + real_size - req_off) == (int)(real_off + real_size - req_off));
+			send_size[i] += (int)(ADIOI_MIN(real_off + real_size - req_off, 
+                                      (ADIO_Offset)(unsigned)req_len)); 
 
-			if (real_off+real_size-req_off < req_len) {
-			    partial_send[i] = (int) (real_off+real_size-
-						     req_off);
+			if (real_off+real_size-req_off < (ADIO_Offset)(unsigned)req_len) {
+			    partial_send[i] = (int) (real_off + real_size - req_off);
 			    if ((j+1 < others_req[i].count) && 
                                  (others_req[i].offsets[j+1] < 
                                      real_off+real_size)) { 
 				/* this is the case illustrated in the
 				   figure above. */
-				for_next_iter = (int) (ADIOI_MAX(for_next_iter,
-					  real_off + real_size - 
-                                             others_req[i].offsets[j+1])); 
+				for_next_iter = ADIOI_MAX(for_next_iter,
+					  real_off + real_size - others_req[i].offsets[j+1]); 
 				/* max because it must cover requests 
 				   from different processes */
 			    }
@@ -626,7 +628,8 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
         MPE_Log_event(14, 0, "end computation");
 #endif
 	if (flag) {
-	    ADIO_ReadContig(fd, read_buf+for_curr_iter, size, MPI_BYTE,
+      ADIOI_Assert(size == (int)size);
+	    ADIO_ReadContig(fd, read_buf+for_curr_iter, (int)size, MPI_BYTE,
 			    ADIO_EXPLICIT_OFFSET, off, &status, error_code);
 #ifdef RDCOLL_DEBUG
 	    DBG_FPRINTF(stderr, "\tread_coll: 700, data read [%3d] = ", size );
@@ -670,6 +673,8 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 
 	if (for_next_iter) {
 	    tmp_buf = (char *) ADIOI_Malloc(for_next_iter);
+      ADIOI_Assert((((ADIO_Offset)(unsigned long)read_buf)+real_size-for_next_iter) == (ADIO_Offset)(unsigned long)(read_buf+real_size-for_next_iter));
+      ADIOI_Assert((for_next_iter+coll_bufsize) == (size_t)(for_next_iter+coll_bufsize));
 	    memcpy(tmp_buf, read_buf+real_size-for_next_iter, for_next_iter);
 	    ADIOI_Free(read_buf);
 	    read_buf = (char *) ADIOI_Malloc(for_next_iter+coll_bufsize);
@@ -849,6 +854,19 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
     }
 }
 
+static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
+				   *flat_buf, char **recv_buf, ADIO_Offset 
+				   *offset_list, ADIO_Offset *len_list, 
+				   unsigned *recv_size, 
+				   MPI_Request *requests, MPI_Status *statuses,
+				   int *recd_from_proc, int nprocs,
+				   int contig_access_count, 
+				   ADIO_Offset min_st_offset, 
+				   ADIO_Offset fd_size, ADIO_Offset *fd_start, 
+				   ADIO_Offset *fd_end,
+				   MPI_Aint buftype_extent)
+{
+/* this function is only called if buftype is not contig */
 
 #define ADIOI_BUF_INCR \
 { \
@@ -863,7 +881,7 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                 n_buftypes++; \
             } \
             user_buf_idx = flat_buf->indices[flat_buf_idx] + \
-                              n_buftypes*buftype_extent; \
+                              (ADIO_Offset)n_buftypes*(ADIO_Offset)buftype_extent; \
 	    flat_buf_sz = flat_buf->blocklens[flat_buf_idx]; \
 	} \
 	buf_incr -= size_in_buf; \
@@ -875,9 +893,11 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 { \
     while (size) { \
 	size_in_buf = ADIOI_MIN(size, flat_buf_sz); \
+  ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + user_buf_idx) == (ADIO_Offset)(unsigned long)(buf + user_buf_idx)); \
+  ADIOI_Assert(size_in_buf == (size_t)size_in_buf); \
 	memcpy(((char *) buf) + user_buf_idx, \
 	       &(recv_buf[p][recv_buf_idx[p]]), size_in_buf); \
-	recv_buf_idx[p] += size_in_buf; \
+	recv_buf_idx[p] += size_in_buf; /* already tested (size_t)size_in_buf*/ \
 	user_buf_idx += size_in_buf; \
 	flat_buf_sz -= size_in_buf; \
 	if (!flat_buf_sz) { \
@@ -887,7 +907,7 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                 n_buftypes++; \
             } \
             user_buf_idx = flat_buf->indices[flat_buf_idx] + \
-                              n_buftypes*buftype_extent; \
+                              (ADIO_Offset)n_buftypes*(ADIO_Offset)buftype_extent; \
 	    flat_buf_sz = flat_buf->blocklens[flat_buf_idx]; \
 	} \
 	size -= size_in_buf; \
@@ -897,25 +917,13 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 }
 
 
-static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-				   *flat_buf, char **recv_buf, ADIO_Offset 
-				   *offset_list, ADIO_Offset *len_list, 
-				   int *recv_size, 
-				   MPI_Request *requests, MPI_Status *statuses,
-				   int *recd_from_proc, int nprocs,
-				   int contig_access_count, 
-				   ADIO_Offset min_st_offset, 
-				   ADIO_Offset fd_size, ADIO_Offset *fd_start, 
-				   ADIO_Offset *fd_end,
-				   MPI_Aint buftype_extent)
-{
-/* this function is only called if buftype is not contig */
 
-    int i, p, flat_buf_idx, size, buf_incr;
-    int flat_buf_sz, size_in_buf, n_buftypes;
+    int i, p, flat_buf_idx;
+    ADIO_Offset flat_buf_sz, size_in_buf, buf_incr, size;
+    int n_buftypes;
     ADIO_Offset off, len, rem_len, user_buf_idx;
-
-    int *curr_from_proc, *done_from_proc, *recv_buf_idx;
+    /* Not sure unsigned is necessary, but it makes the math safer */
+    unsigned *curr_from_proc, *done_from_proc, *recv_buf_idx;
 
 /*  curr_from_proc[p] = amount of data recd from proc. p that has already
                         been accounted for so far
@@ -923,9 +931,9 @@ static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                         filled into user buffer in previous iterations
     user_buf_idx = current location in user buffer 
     recv_buf_idx[p] = current location in recv_buf of proc. p  */
-    curr_from_proc = (int *) ADIOI_Malloc(nprocs * sizeof(int));
-    done_from_proc = (int *) ADIOI_Malloc(nprocs * sizeof(int));
-    recv_buf_idx   = (int *) ADIOI_Malloc(nprocs * sizeof(int));
+    curr_from_proc = (unsigned *) ADIOI_Malloc(nprocs * sizeof(unsigned));
+    done_from_proc = (unsigned *) ADIOI_Malloc(nprocs * sizeof(unsigned));
+    recv_buf_idx   = (unsigned *) ADIOI_Malloc(nprocs * sizeof(unsigned));
 
     for (i=0; i < nprocs; i++) {
 	recv_buf_idx[i] = curr_from_proc[i] = 0;
@@ -963,29 +971,32 @@ static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 	    if (recv_buf_idx[p] < recv_size[p]) {
 		if (curr_from_proc[p]+len > done_from_proc[p]) {
 		    if (done_from_proc[p] > curr_from_proc[p]) {
-			size = (int)ADIOI_MIN(curr_from_proc[p] + len - 
+			size = ADIOI_MIN(curr_from_proc[p] + len - 
 			      done_from_proc[p], recv_size[p]-recv_buf_idx[p]);
 			buf_incr = done_from_proc[p] - curr_from_proc[p];
 			ADIOI_BUF_INCR
-			buf_incr = (int)(curr_from_proc[p]+len-done_from_proc[p]);
+			buf_incr = curr_from_proc[p]+len-done_from_proc[p];
+      ADIOI_Assert((done_from_proc[p] + size) == (unsigned)((ADIO_Offset)done_from_proc[p] + size));
 			curr_from_proc[p] = done_from_proc[p] + size;
 			ADIOI_BUF_COPY
 		    }
 		    else {
-			size = (int)ADIOI_MIN(len,recv_size[p]-recv_buf_idx[p]);
-			buf_incr = (int)len;
-			curr_from_proc[p] += size;
+			size = ADIOI_MIN(len,recv_size[p]-recv_buf_idx[p]);
+			buf_incr = len;
+      ADIOI_Assert((curr_from_proc[p] + size) == (unsigned)((ADIO_Offset)curr_from_proc[p] + size));
+			curr_from_proc[p] += (unsigned) size;
 			ADIOI_BUF_COPY
 		    }
 		}
 		else {
-		    curr_from_proc[p] += (int)len;
-		    buf_incr = (int)len;
+        ADIOI_Assert((curr_from_proc[p] + len) == (unsigned)((ADIO_Offset)curr_from_proc[p] + len));
+		    curr_from_proc[p] += (unsigned) len;
+		    buf_incr = len;
 		    ADIOI_BUF_INCR
 		}
 	    }
 	    else {
-		buf_incr = (int)len;
+		buf_incr = len;
 		ADIOI_BUF_INCR
 	    }
 	    off     += len;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_read.c b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_read.c
index 64f845a..25d8428 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_read.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_read.c
@@ -55,7 +55,7 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 	    ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
 	else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
         	if (bglmpio_timing2) io_time2 = MPI_Wtime();
-	err = read(fd->fd_sys, buf, len);
+	err = read(fd->fd_sys, buf, (unsigned int)len);
         	if (bglmpio_timing2) bglmpio_prof_cr[ BGLMPIO_CIO_T_POSI_RW ] += (MPI_Wtime() - io_time2);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_sys_posn = offset + err;
@@ -71,7 +71,7 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 	    ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
 	else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
         	if (bglmpio_timing2) io_time2 = MPI_Wtime();
-	err = read(fd->fd_sys, buf, len);
+	err = read(fd->fd_sys, buf, (unsigned int)len);
         	if (bglmpio_timing2) bglmpio_prof_cr[ BGLMPIO_CIO_T_POSI_RW ] += (MPI_Wtime() - io_time2);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_ind += err;
@@ -86,7 +86,7 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 	if (fd->atomicity)
 	    ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
 	else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
-	err = read(fd->fd_sys, buf, len);
+	err = read(fd->fd_sys, buf, (unsigned int)len);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_sys_posn = offset + err;
 	/* individual file pointer not updated */        
@@ -98,7 +98,7 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 	if (fd->atomicity)
 	    ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
 	else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
-	err = read(fd->fd_sys, buf, len);
+	err = read(fd->fd_sys, buf, (unsigned int)len);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_ind += err;
 	fd->fp_sys_posn = fd->fp_ind;
@@ -127,12 +127,18 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 }
 
 
+void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
+                       MPI_Datatype datatype, int file_ptr_type,
+                       ADIO_Offset offset, ADIO_Status *status, int
+                       *error_code)
+{
+/* offset is in units of etype relative to the filetype. */
 
 #define ADIOI_BUFFERED_READ \
 { \
     if (req_off >= readbuf_off + readbuf_len) { \
 	readbuf_off = req_off; \
-	readbuf_len = (int) (ADIOI_MIN(max_bufsize, end_offset-readbuf_off+1));\
+	readbuf_len = (unsigned) (ADIOI_MIN(max_bufsize, end_offset-readbuf_off+1));\
 	lseek(fd->fd_sys, readbuf_off, SEEK_SET);\
         if (!(fd->atomicity)) ADIOI_READ_LOCK(fd, readbuf_off, SEEK_SET, readbuf_len);\
         err = read(fd->fd_sys, readbuf, readbuf_len);\
@@ -140,6 +146,7 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
         if (err == -1) err_flag = 1; \
     } \
     while (req_len > readbuf_off + readbuf_len - req_off) { \
+  ADIOI_Assert((readbuf_off + readbuf_len - req_off) == (int) (readbuf_off + readbuf_len - req_off));\
 	partial_read = (int) (readbuf_off + readbuf_len - req_off); \
 	tmp_buf = (char *) ADIOI_Malloc(partial_read); \
 	memcpy(tmp_buf, readbuf+readbuf_len-partial_read, partial_read); \
@@ -148,7 +155,7 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 	memcpy(readbuf, tmp_buf, partial_read); \
 	ADIOI_Free(tmp_buf); \
 	readbuf_off += readbuf_len-partial_read; \
-	readbuf_len = (int) (partial_read + ADIOI_MIN(max_bufsize, \
+	readbuf_len = (unsigned) (partial_read + ADIOI_MIN(max_bufsize, \
 				       end_offset-readbuf_off+1)); \
 	lseek(fd->fd_sys, readbuf_off+partial_read, SEEK_SET);\
         if (!(fd->atomicity)) ADIOI_READ_LOCK(fd, readbuf_off+partial_read, SEEK_SET, readbuf_len-partial_read);\
@@ -156,32 +163,29 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
         if (!(fd->atomicity)) ADIOI_UNLOCK(fd, readbuf_off+partial_read, SEEK_SET, readbuf_len-partial_read);\
         if (err == -1) err_flag = 1; \
     } \
+    ADIOI_Assert(req_len == (size_t)req_len); \
     memcpy((char *)buf + userbuf_off, readbuf+req_off-readbuf_off, req_len); \
 }
 
 
-void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
-                       MPI_Datatype datatype, int file_ptr_type,
-                       ADIO_Offset offset, ADIO_Status *status, int
-                       *error_code)
-{
-/* offset is in units of etype relative to the filetype. */
 
     ADIOI_Flatlist_node *flat_buf, *flat_file;
-    int i, j, k, err=-1, brd_size, st_index=0;
-    ADIO_Offset frd_size=0, new_brd_size, new_frd_size, st_frd_size;
-    int bufsize, num, size, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
+    ADIO_Offset i_offset, new_brd_size, brd_size, size;
+    int j, k, err=-1, st_index=0;
+    ADIO_Offset frd_size=0, new_frd_size, st_frd_size;
+    unsigned bufsize, num; 
+    int n_etypes_in_filetype;
+    ADIO_Offset n_filetypes, etype_in_filetype, size_in_filetype;
     ADIO_Offset abs_off_in_filetype=0;
-    int filetype_size, etype_size, buftype_size, req_len, partial_read;
+    int filetype_size, etype_size, buftype_size, partial_read;
     MPI_Aint filetype_extent, buftype_extent; 
     int buf_count, buftype_is_contig, filetype_is_contig;
-    ADIO_Offset userbuf_off;
+    ADIO_Offset userbuf_off, req_len, sum;
     ADIO_Offset off, req_off, disp, end_offset=0, readbuf_off, start_off;
     char *readbuf, *tmp_buf, *value;
-    int flag, st_n_filetypes, readbuf_len;
-    int err_flag=0, info_flag, max_bufsize;
-
+    int flag, st_n_filetypes;
+    int err_flag=0, info_flag;
+    unsigned max_bufsize, readbuf_len;
     static char myname[] = "ADIOI_BGL_READSTRIDED";
 
     if (fd->hints->ds_read == ADIOI_HINT_DISABLE) {
@@ -235,13 +239,13 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 	while (flat_buf->type != datatype) flat_buf = flat_buf->next;
 
         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
-                 fd->disp + etype_size * offset;
+                 fd->disp + (ADIO_Offset)etype_size * offset;
 
 	start_off = off;
 	end_offset = off + bufsize - 1;
         readbuf_off = off;
         readbuf = (char *) ADIOI_Malloc(max_bufsize);
-        readbuf_len = (int) (ADIOI_MIN(max_bufsize, end_offset-readbuf_off+1));
+        readbuf_len = (unsigned) (ADIOI_MIN(max_bufsize, end_offset-readbuf_off+1));
 
 /* if atomicity is true, lock (exclusive) the region to be accessed */
         if (fd->atomicity)
@@ -255,7 +259,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 
         for (j=0; j<count; j++) 
             for (i=0; i<flat_buf->count; i++) {
-                userbuf_off = j*buftype_extent + flat_buf->indices[i];
+                userbuf_off = (ADIO_Offset)j*(ADIO_Offset)buftype_extent + flat_buf->indices[i];
 		req_off = off;
 		req_len = flat_buf->blocklens[i];
 		ADIOI_BUFFERED_READ
@@ -290,15 +294,16 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 	    n_filetypes = -1;
 	    flag = 0;
 	    while (!flag) {
+        int i;
                 n_filetypes++;
 		for (i=0; i<flat_file->count; i++) {
 		    if (disp + flat_file->indices[i] + 
-                        (ADIO_Offset) n_filetypes*filetype_extent + flat_file->blocklens[i] 
+                        n_filetypes*(ADIO_Offset)filetype_extent + flat_file->blocklens[i] 
                             >= offset) {
 			st_index = i;
-			frd_size = (int) (disp + flat_file->indices[i] + 
-			        (ADIO_Offset) n_filetypes*filetype_extent
-			         + flat_file->blocklens[i] - offset);
+			frd_size = disp + flat_file->indices[i] + 
+			        n_filetypes*(ADIO_Offset)filetype_extent
+			         + flat_file->blocklens[i] - offset;
 			flag = 1;
 			break;
 		    }
@@ -306,9 +311,10 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 	    }
 	}
 	else {
+    int i;
 	    n_etypes_in_filetype = filetype_size/etype_size;
-	    n_filetypes = (int) (offset / n_etypes_in_filetype);
-	    etype_in_filetype = (int) (offset % n_etypes_in_filetype);
+	    n_filetypes = offset / n_etypes_in_filetype;
+	    etype_in_filetype = offset % n_etypes_in_filetype;
 	    size_in_filetype = etype_in_filetype * etype_size;
  
 	    sum = 0;
@@ -324,7 +330,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 	    }
 
 	    /* abs. offset in bytes in the file */
-	    offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + abs_off_in_filetype;
+	    offset = disp + n_filetypes*(ADIO_Offset)filetype_extent + abs_off_in_filetype;
 	}
 
         start_off = offset;
@@ -334,12 +340,12 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 
 	st_frd_size = frd_size;
 	st_n_filetypes = n_filetypes;
-	i = 0;
+	i_offset = 0;
 	j = st_index;
 	off = offset;
 	frd_size = ADIOI_MIN(st_frd_size, bufsize);
-	while (i < bufsize) {
-	    i += frd_size;
+	while (i_offset < bufsize) {
+	    i_offset += frd_size;
 	    end_offset = off + frd_size - 1;
 
 	    if (j < (flat_file->count - 1)) j++;
@@ -348,7 +354,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 		n_filetypes++;
 	    }
 
-	    off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes*filetype_extent;
+	    off = disp + flat_file->indices[j] + n_filetypes*(ADIO_Offset)filetype_extent;
 	    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
 	}
 
@@ -359,7 +365,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
         /* initial read into readbuf */
 	readbuf_off = offset;
 	readbuf = (char *) ADIOI_Malloc(max_bufsize);
-	readbuf_len = (int) (ADIOI_MIN(max_bufsize, end_offset-readbuf_off+1));
+	readbuf_len = (unsigned) (ADIOI_MIN(max_bufsize, end_offset-readbuf_off+1));
 
 	lseek(fd->fd_sys, offset, SEEK_SET);
         if (!(fd->atomicity)) ADIOI_READ_LOCK(fd, offset, SEEK_SET, readbuf_len);
@@ -373,12 +379,12 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 /* contiguous in memory, noncontiguous in file. should be the most
    common case. */
 
-	    i = 0;
+	    i_offset = 0;
 	    j = st_index;
 	    off = offset;
 	    n_filetypes = st_n_filetypes;
 	    frd_size = ADIOI_MIN(st_frd_size, bufsize);
-	    while (i < bufsize) {
+	    while (i_offset < bufsize) {
                 if (frd_size) { 
                     /* TYPE_UB and TYPE_LB can result in 
                        frd_size = 0. save system call in such cases */ 
@@ -387,13 +393,13 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 
 		    req_off = off;
 		    req_len = frd_size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 		    ADIOI_BUFFERED_READ
 		}
-		i += frd_size;
+		i_offset += frd_size;
 
                 if (off + frd_size < disp + flat_file->indices[j] +
-                   flat_file->blocklens[j] + (ADIO_Offset) n_filetypes*filetype_extent)
+                   flat_file->blocklens[j] + n_filetypes*(ADIO_Offset)filetype_extent)
                        off += frd_size;
                 /* did not reach end of contiguous block in filetype.
                    no more I/O needed. off is incremented by frd_size. */
@@ -404,7 +410,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[j] + 
-                                        (ADIO_Offset) n_filetypes*filetype_extent;
+                                        n_filetypes*(ADIO_Offset)filetype_extent;
 		    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
 		}
 	    }
@@ -417,7 +423,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
 
 	    k = num = buf_count = 0;
-	    i = (int) (flat_buf->indices[0]);
+	    i_offset = flat_buf->indices[0];
 	    j = st_index;
 	    off = offset;
 	    n_filetypes = st_n_filetypes;
@@ -432,7 +438,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 
 		    req_off = off;
 		    req_len = size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 		    ADIOI_BUFFERED_READ
 		}
 
@@ -448,11 +454,11 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 		    }
 
 		    off = disp + flat_file->indices[j] + 
-                                              (ADIO_Offset) n_filetypes*filetype_extent;
+                                              n_filetypes*(ADIO_Offset)filetype_extent;
 
 		    new_frd_size = flat_file->blocklens[j];
 		    if (size != brd_size) {
-			i += size;
+			i_offset += size;
 			new_brd_size -= size;
 		    }
 		}
@@ -462,7 +468,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 
 		    k = (k + 1)%flat_buf->count;
 		    buf_count++;
-		    i = (int) (buftype_extent*(buf_count/flat_buf->count) +
+		    i_offset = ((ADIO_Offset)buftype_extent*(ADIO_Offset)(buf_count/flat_buf->count) +
 			flat_buf->indices[k]); 
 		    new_brd_size = flat_buf->blocklens[k];
 		    if (size != frd_size) {
@@ -470,6 +476,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 			new_frd_size -= size;
 		    }
 		}
+    ADIOI_Assert(((ADIO_Offset)num + size) == (unsigned)(num + size));
 		num += size;
 		frd_size = new_frd_size;
                 brd_size = new_brd_size;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c
index 1427ae8..cd71988 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c
@@ -381,8 +381,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 				 ADIOI_Access
 				 *others_req, ADIO_Offset *offset_list,
 				 ADIO_Offset *len_list, int contig_access_count,
-				 ADIO_Offset
-				 min_st_offset, ADIO_Offset fd_size,
+				 ADIO_Offset min_st_offset, ADIO_Offset fd_size,
 				 ADIO_Offset *fd_start, ADIO_Offset *fd_end,
 				 int *buf_idx, int *error_code)
 {
@@ -395,7 +394,9 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
    array to a file, where each local array is 8Mbytes, requiring
    at least another 8Mbytes of temp space is unacceptable. */
 
-    int hole, i, j, m, size=0, ntimes, max_ntimes, buftype_is_contig;
+    /* Not convinced end_loc-st_loc couldn't be > int, so make these offsets*/
+    ADIO_Offset size=0;
+    int hole, i, j, m, ntimes, max_ntimes, buftype_is_contig;
     ADIO_Offset st_loc=-1, end_loc=-1, off, done, req_off;
     char *write_buf=NULL;
     int *curr_offlen_ptr, *count, *send_size, req_len, *recv_size;
@@ -532,7 +533,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 #endif
 	for (i=0; i < nprocs; i++) count[i] = recv_size[i] = 0;
 
-	size = (int) (ADIOI_MIN(coll_bufsize, end_loc-st_loc+1-done)); 
+	size = ADIOI_MIN((unsigned)coll_bufsize, end_loc-st_loc+1-done); 
 
 	for (i=0; i < nprocs; i++) {
 	    if (others_req[i].count) {
@@ -556,12 +557,14 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 		    }
 		    if (req_off < off + size) {
 			count[i]++;
+      ADIOI_Assert((((ADIO_Offset)(unsigned long)write_buf)+req_off-off) == (ADIO_Offset)(unsigned long)(write_buf+req_off-off));
 			MPI_Address(write_buf+req_off-off, 
                                &(others_req[i].mem_ptrs[j]));
-			recv_size[i] += (int)(ADIOI_MIN(off + (ADIO_Offset)size - 
-						  req_off, req_len));
+      ADIOI_Assert((off + size - req_off) == (int)(off + size - req_off));
+			recv_size[i] += (int)(ADIOI_MIN(off + size - req_off, 
+                                      (unsigned)req_len));
 
-			if (off+size-req_off < req_len)
+			if (off+size-req_off < (unsigned)req_len)
 			{
 			    partial_recv[i] = (int) (off + size - req_off);
 
@@ -624,7 +627,8 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 	    if (count[i]) flag = 1;
 
 	if (flag) {
-	    ADIO_WriteContig(fd, write_buf, size, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
+      ADIOI_Assert(size == (int)size);
+	    ADIO_WriteContig(fd, write_buf, (int)size, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
                         off, &status, error_code);
 	    if (*error_code != MPI_SUCCESS) return;
 	}
@@ -924,7 +928,7 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
                 n_buftypes++; \
             } \
             user_buf_idx = flat_buf->indices[flat_buf_idx] + \
-                              n_buftypes*buftype_extent; \
+                              (ADIO_Offset)n_buftypes*(ADIO_Offset)buftype_extent; \
             flat_buf_sz = flat_buf->blocklens[flat_buf_idx]; \
         } \
         buf_incr -= size_in_buf; \
@@ -936,6 +940,8 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
 { \
     while (size) { \
         size_in_buf = ADIOI_MIN(size, flat_buf_sz); \
+  ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + user_buf_idx) == (ADIO_Offset)(unsigned long)(buf + user_buf_idx)); \
+  ADIOI_Assert(size_in_buf == (size_t)size_in_buf); \
         memcpy(&(send_buf[p][send_buf_idx[p]]), \
                ((char *) buf) + user_buf_idx, size_in_buf); \
         send_buf_idx[p] += size_in_buf; \
@@ -948,7 +954,7 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
                 n_buftypes++; \
             } \
             user_buf_idx = flat_buf->indices[flat_buf_idx] + \
-                              n_buftypes*buftype_extent; \
+                              (ADIO_Offset)n_buftypes*(ADIO_Offset)buftype_extent; \
             flat_buf_sz = flat_buf->blocklens[flat_buf_idx]; \
         } \
         size -= size_in_buf; \
@@ -957,8 +963,6 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
     ADIOI_BUF_INCR \
 }
 
-
-
 static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            *flat_buf, char **send_buf, ADIO_Offset 
                            *offset_list, ADIO_Offset *len_list, int *send_size, 
@@ -973,8 +977,9 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 {
 /* this function is only called if buftype is not contig */
 
-    int i, p, flat_buf_idx, size;
-    int flat_buf_sz, buf_incr, size_in_buf, jj, n_buftypes;
+    int i, p, flat_buf_idx;
+    ADIO_Offset flat_buf_sz, size_in_buf, buf_incr, size;
+    int jj, n_buftypes;
     ADIO_Offset off, len, rem_len, user_buf_idx;
 
 /*  curr_to_proc[p] = amount of data sent to proc. p that has already
@@ -1021,17 +1026,20 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 	    if (send_buf_idx[p] < send_size[p]) {
 		if (curr_to_proc[p]+len > done_to_proc[p]) {
 		    if (done_to_proc[p] > curr_to_proc[p]) {
-			size = (int)ADIOI_MIN(curr_to_proc[p] + len - 
+			size = ADIOI_MIN(curr_to_proc[p] + len - 
                                 done_to_proc[p], send_size[p]-send_buf_idx[p]);
 			buf_incr = done_to_proc[p] - curr_to_proc[p];
 			ADIOI_BUF_INCR
-		        buf_incr = (int)(curr_to_proc[p] + len - done_to_proc[p]);
+      ADIOI_Assert((curr_to_proc[p] + len - done_to_proc[p]) == (unsigned)(curr_to_proc[p] + len - done_to_proc[p]));
+		        buf_incr = curr_to_proc[p] + len - done_to_proc[p];
+      ADIOI_Assert((done_to_proc[p] + size) == (unsigned)(done_to_proc[p] + size));
 			curr_to_proc[p] = done_to_proc[p] + size;
 		        ADIOI_BUF_COPY
 		    }
 		    else {
-			size = (int)ADIOI_MIN(len,send_size[p]-send_buf_idx[p]);
-			buf_incr = (int)len;
+			size = ADIOI_MIN(len,send_size[p]-send_buf_idx[p]);
+			buf_incr = len;
+      ADIOI_Assert((curr_to_proc[p] + size) == (unsigned)((ADIO_Offset)curr_to_proc[p] + size));
 			curr_to_proc[p] += size;
 			ADIOI_BUF_COPY
 		    }
@@ -1042,13 +1050,14 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 		    }
 		}
 		else {
-		    curr_to_proc[p] += (int)len;
-		    buf_incr = (int)len;
+        ADIOI_Assert((curr_to_proc[p] + len) == (unsigned)((ADIO_Offset)curr_to_proc[p] + len));
+		    curr_to_proc[p] += len;
+		    buf_incr = len;
 		    ADIOI_BUF_INCR
 		}
 	    }
 	    else {
-		buf_incr = (int)len;
+		buf_incr = len;
 		ADIOI_BUF_INCR
             }
 	    off     += len;
@@ -1367,8 +1376,9 @@ static void ADIOI_Fill_send_buffer_nosend(ADIO_File fd, void *buf, ADIOI_Flatlis
 {
 /* this function is only called if buftype is not contig */
 
-    int i, p, flat_buf_idx, size;
-    int flat_buf_sz, buf_incr, size_in_buf, jj, n_buftypes;
+    int i, p, flat_buf_idx;
+    ADIO_Offset flat_buf_sz, size_in_buf, buf_incr, size;
+    int jj, n_buftypes;
     ADIO_Offset off, len, rem_len, user_buf_idx;
 
 /*  curr_to_proc[p] = amount of data sent to proc. p that has already
@@ -1415,17 +1425,20 @@ static void ADIOI_Fill_send_buffer_nosend(ADIO_File fd, void *buf, ADIOI_Flatlis
 	    if (send_buf_idx[p] < send_size[p]) {
 		if (curr_to_proc[p]+len > done_to_proc[p]) {
 		    if (done_to_proc[p] > curr_to_proc[p]) {
-			size = (int)ADIOI_MIN(curr_to_proc[p] + len - 
+			size = ADIOI_MIN(curr_to_proc[p] + len - 
                                 done_to_proc[p], send_size[p]-send_buf_idx[p]);
 			buf_incr = done_to_proc[p] - curr_to_proc[p];
 			ADIOI_BUF_INCR
-		        buf_incr = (int)(curr_to_proc[p] + len - done_to_proc[p]);
+      ADIOI_Assert((curr_to_proc[p] + len - done_to_proc[p]) == (unsigned)(curr_to_proc[p] + len - done_to_proc[p]));
+		        buf_incr = curr_to_proc[p] + len - done_to_proc[p];
+      ADIOI_Assert((done_to_proc[p] + size) == (unsigned)(done_to_proc[p] + size));
 			curr_to_proc[p] = done_to_proc[p] + size;
 		        ADIOI_BUF_COPY
 		    }
 		    else {
-			size = (int)ADIOI_MIN(len,send_size[p]-send_buf_idx[p]);
-			buf_incr = (int)len;
+			size = ADIOI_MIN(len,send_size[p]-send_buf_idx[p]);
+			buf_incr = len;
+      ADIOI_Assert((curr_to_proc[p] + size) == (unsigned)((ADIO_Offset)curr_to_proc[p] + size));
 			curr_to_proc[p] += size;
 			ADIOI_BUF_COPY
 		    }
@@ -1439,13 +1452,14 @@ static void ADIOI_Fill_send_buffer_nosend(ADIO_File fd, void *buf, ADIOI_Flatlis
 		    */
 		}
 		else {
+        ADIOI_Assert((curr_to_proc[p] + len) == (unsigned)((ADIO_Offset)curr_to_proc[p] + len));
 		    curr_to_proc[p] += (int)len;
-		    buf_incr = (int)len;
+		    buf_incr = len;
 		    ADIOI_BUF_INCR
 		}
 	    }
 	    else {
-		buf_incr = (int)len;
+		buf_incr = len;
 		ADIOI_BUF_INCR
             }
 	    off     += len;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_write.c b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_write.c
index 5f06a1c..1bae80c 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_write.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_write.c
@@ -42,7 +42,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 			  
     MPI_Type_size(datatype, &datatype_size);
     len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
-    ADIOI_Assert(len == (unsigned int) len); /* read takes an unsigned int parm */
+    ADIOI_Assert(len == (unsigned int) len); /* write takes an unsigned int parm */
 
 #if BGL_PROFILE
 
@@ -53,7 +53,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
         	if (bglmpio_timing2) bglmpio_prof_cw[ BGLMPIO_CIO_T_SEEK ] += (MPI_Wtime() - io_time2);
 	ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
         	if (bglmpio_timing2) io_time2 = MPI_Wtime();
-	err = write(fd->fd_sys, buf, len);
+	err = write(fd->fd_sys, buf, (unsigned int)len);
         	if (bglmpio_timing2) bglmpio_prof_cw[ BGLMPIO_CIO_T_POSI_RW ] += (MPI_Wtime() - io_time2);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_sys_posn = offset + err;
@@ -67,7 +67,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
         	if (bglmpio_timing2) bglmpio_prof_cw[ BGLMPIO_CIO_T_SEEK ] += (MPI_Wtime() - io_time2);
 	ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
         	if (bglmpio_timing2) io_time2 = MPI_Wtime();
-	err = write(fd->fd_sys, buf, len);
+	err = write(fd->fd_sys, buf, (unsigned int)len);
         	if (bglmpio_timing2) bglmpio_prof_cw[ BGLMPIO_CIO_T_POSI_RW ] += (MPI_Wtime() - io_time2);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_ind += err;
@@ -80,7 +80,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 	if (fd->fp_sys_posn != offset)
 	    lseek(fd->fd_sys, offset, SEEK_SET);
 	ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
-	err = write(fd->fd_sys, buf, len);
+	err = write(fd->fd_sys, buf, (unsigned int)len);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_sys_posn = offset + err;
 	/* individual file pointer not updated */        
@@ -90,7 +90,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 	if (fd->fp_sys_posn != fd->fp_ind)
 	    lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
 	ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
-	err = write(fd->fd_sys, buf, len);
+	err = write(fd->fd_sys, buf, (unsigned int)len);
 	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
 	fd->fp_ind += err;
 	fd->fp_sys_posn = fd->fp_ind;
@@ -120,6 +120,12 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 }
 
 
+void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
+                       MPI_Datatype datatype, int file_ptr_type,
+                       ADIO_Offset offset, ADIO_Status *status, int
+                       *error_code)
+{
+/* offset is in units of etype relative to the filetype. */
 
 
 #define ADIOI_BUFFERED_WRITE \
@@ -130,7 +136,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
         if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
         if (err == -1) err_flag = 1; \
 	writebuf_off = req_off; \
-        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
+        writebuf_len = (unsigned) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
 	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
 	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
 	err = read(fd->fd_sys, writebuf, writebuf_len); \
@@ -142,7 +148,8 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 	    return; \
         } \
     } \
-    write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
+    write_sz = (unsigned) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
+    ADIOI_Assert((ADIO_Offset)write_sz == ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off));\
     memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\
     while (write_sz != req_len) { \
 	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
@@ -152,7 +159,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
         req_len -= write_sz; \
         userbuf_off += write_sz; \
         writebuf_off += writebuf_len; \
-        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
+        writebuf_len = (unsigned) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
 	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
 	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
 	err = read(fd->fd_sys, writebuf, writebuf_len); \
@@ -180,9 +187,10 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
         if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
         if (err == -1) err_flag = 1; \
 	writebuf_off = req_off; \
-        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
+        writebuf_len = (unsigned) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
     } \
-    write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
+    write_sz = (unsigned) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
+    ADIOI_Assert((ADIO_Offset)write_sz == ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off));\
     memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\
     while (write_sz != req_len) { \
 	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
@@ -193,7 +201,7 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
         req_len -= write_sz; \
         userbuf_off += write_sz; \
         writebuf_off += writebuf_len; \
-        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
+        writebuf_len = (unsigned) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
         write_sz = ADIOI_MIN(req_len, writebuf_len); \
         memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
     } \
@@ -201,27 +209,23 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 
 
 
-void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
-                       MPI_Datatype datatype, int file_ptr_type,
-                       ADIO_Offset offset, ADIO_Status *status, int
-                       *error_code)
-{
-/* offset is in units of etype relative to the filetype. */
 
     ADIOI_Flatlist_node *flat_buf, *flat_file;
-    int i, j, k, err=-1, st_index=0;
-    ADIO_Offset bwr_size, fwr_size=0, st_fwr_size, new_bwr_size, new_fwr_size;
-    int bufsize, num, size, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
+    ADIO_Offset i_offset, sum, size_in_filetype;
+    int j, k, err=-1, st_index=0;
+    int n_etypes_in_filetype;
+    ADIO_Offset num, size, n_filetypes, etype_in_filetype, st_n_filetypes;
     ADIO_Offset abs_off_in_filetype=0;
-    int filetype_size, etype_size, buftype_size, req_len;
+    int filetype_size, etype_size, buftype_size;
     MPI_Aint filetype_extent, buftype_extent; 
     int buf_count, buftype_is_contig, filetype_is_contig;
     ADIO_Offset userbuf_off;
     ADIO_Offset off, req_off, disp, end_offset=0, writebuf_off, start_off;
     char *writebuf, *value;
-    int flag, st_n_filetypes, writebuf_len, write_sz;
-    int err_flag=0, info_flag, max_bufsize;
+    int flag;
+    unsigned bufsize, writebuf_len, max_bufsize, write_sz;
+    int err_flag=0, info_flag;
+    ADIO_Offset new_bwr_size, new_fwr_size, st_fwr_size, fwr_size=0, bwr_size, req_len;
     static char myname[] = "ADIOI_BGL_WRITESTRIDED";
 
     if (fd->hints->ds_write == ADIOI_HINT_DISABLE) {
@@ -281,20 +285,23 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 	end_offset = off + bufsize - 1;
         writebuf_off = off;
         writebuf = (char *) ADIOI_Malloc(max_bufsize);
-        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));
+        writebuf_len = (unsigned) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));
 
 /* if atomicity is true, lock the region to be accessed */
         if (fd->atomicity) 
             ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
 
         for (j=0; j<count; j++) 
+        {
+          int i;
             for (i=0; i<flat_buf->count; i++) {
-                userbuf_off = j*buftype_extent + flat_buf->indices[i];
+                userbuf_off = (ADIO_Offset)j*(ADIO_Offset)buftype_extent + flat_buf->indices[i];
 		req_off = off;
 		req_len = flat_buf->blocklens[i];
 		ADIOI_BUFFERED_WRITE_WITHOUT_READ
                 off += flat_buf->blocklens[i];
             }
+        }
 
         /* write the buffer out finally */
 	lseek(fd->fd_sys, writebuf_off, SEEK_SET); 
@@ -330,15 +337,16 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 	    n_filetypes = -1;
 	    flag = 0;
 	    while (!flag) {
+        int i;
                 n_filetypes++;
 		for (i=0; i<flat_file->count; i++) {
 		    if (disp + flat_file->indices[i] + 
-                        (ADIO_Offset) n_filetypes*filetype_extent + flat_file->blocklens[i] 
+                        n_filetypes*(ADIO_Offset)filetype_extent + flat_file->blocklens[i] 
                             >= offset) {
 			st_index = i;
-			fwr_size = (int) (disp + flat_file->indices[i] + 
-			        (ADIO_Offset) n_filetypes*filetype_extent
-			         + flat_file->blocklens[i] - offset);
+			fwr_size = disp + flat_file->indices[i] + 
+			        n_filetypes*(ADIO_Offset)filetype_extent
+			         + flat_file->blocklens[i] - offset;
 			flag = 1;
 			break;
 		    }
@@ -346,9 +354,10 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 	    }
 	}
 	else {
+    int i;
 	    n_etypes_in_filetype = filetype_size/etype_size;
-	    n_filetypes = (int) (offset / n_etypes_in_filetype);
-	    etype_in_filetype = (int) (offset % n_etypes_in_filetype);
+	    n_filetypes = offset / n_etypes_in_filetype;
+	    etype_in_filetype = offset % n_etypes_in_filetype;
 	    size_in_filetype = etype_in_filetype * etype_size;
  
 	    sum = 0;
@@ -364,7 +373,7 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 	    }
 
 	    /* abs. offset in bytes in the file */
-	    offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + abs_off_in_filetype;
+	    offset = disp + n_filetypes*(ADIO_Offset)filetype_extent + abs_off_in_filetype;
 	}
 
         start_off = offset;
@@ -374,12 +383,12 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 
 	st_fwr_size = fwr_size;
 	st_n_filetypes = n_filetypes;
-	i = 0;
+	i_offset = 0;
 	j = st_index;
 	off = offset;
 	fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
-	while (i < bufsize) {
-	    i += fwr_size;
+	while (i_offset < bufsize) {
+	    i_offset += fwr_size;
 	    end_offset = off + fwr_size - 1;
 
 	    if (j < (flat_file->count - 1)) j++;
@@ -388,7 +397,7 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 		n_filetypes++;
 	    }
 
-	    off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes*filetype_extent;
+	    off = disp + flat_file->indices[j] + n_filetypes*(ADIO_Offset)filetype_extent;
 	    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
 	}
 
@@ -399,7 +408,7 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
         /* initial read for the read-modify-write */
         writebuf_off = offset;
         writebuf = (char *) ADIOI_Malloc(max_bufsize);
-        writebuf_len = (int)(ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));
+        writebuf_len = (unsigned)(ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));
 	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
 	lseek(fd->fd_sys, writebuf_off, SEEK_SET); 
 	err = read(fd->fd_sys, writebuf, writebuf_len); 
@@ -417,27 +426,27 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 /* contiguous in memory, noncontiguous in file. should be the most
    common case. */
 
-	    i = 0;
+	    i_offset = 0;
 	    j = st_index;
 	    off = offset;
 	    n_filetypes = st_n_filetypes;
 	    fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
-	    while (i < bufsize) {
+	    while (i_offset < bufsize) {
                 if (fwr_size) { 
                     /* TYPE_UB and TYPE_LB can result in 
                        fwr_size = 0. save system call in such cases */ 
 		    /* lseek(fd->fd_sys, off, SEEK_SET);
-		    err = write(fd->fd_sys, ((char *) buf) + i, fwr_size);*/
+		    err = write(fd->fd_sys, ((char *) buf) + i_offset, fwr_size);*/
 
 		    req_off = off;
 		    req_len = fwr_size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 		    ADIOI_BUFFERED_WRITE
 		}
-		i += fwr_size;
+		i_offset += fwr_size;
 
                 if (off + fwr_size < disp + flat_file->indices[j] +
-                   flat_file->blocklens[j] + (ADIO_Offset) n_filetypes*filetype_extent)
+                   flat_file->blocklens[j] + n_filetypes*(ADIO_Offset)filetype_extent)
                        off += fwr_size;
                 /* did not reach end of contiguous block in filetype.
                    no more I/O needed. off is incremented by fwr_size. */
@@ -448,7 +457,7 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[j] + 
-                                        (ADIO_Offset) n_filetypes*filetype_extent;
+                                        n_filetypes*(ADIO_Offset)filetype_extent;
 		    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
 		}
 	    }
@@ -461,7 +470,7 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 	    while (flat_buf->type != datatype) flat_buf = flat_buf->next;
 
 	    k = num = buf_count = 0;
-	    i = (int) (flat_buf->indices[0]);
+	    i_offset = flat_buf->indices[0];
 	    j = st_index;
 	    off = offset;
 	    n_filetypes = st_n_filetypes;
@@ -472,11 +481,11 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 		size = ADIOI_MIN(fwr_size, bwr_size);
 		if (size) {
 		    /* lseek(fd->fd_sys, off, SEEK_SET);
-		    err = write(fd->fd_sys, ((char *) buf) + i, size); */
+		    err = write(fd->fd_sys, ((char *) buf) + i_offset, size); */
 
 		    req_off = off;
 		    req_len = size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 		    ADIOI_BUFFERED_WRITE
 		}
 
@@ -492,11 +501,11 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 		    }
 
 		    off = disp + flat_file->indices[j] + 
-                                  (ADIO_Offset) n_filetypes*filetype_extent;
+                                  n_filetypes*(ADIO_Offset)filetype_extent;
 
 		    new_fwr_size = flat_file->blocklens[j];
 		    if (size != bwr_size) {
-			i += size;
+			i_offset += size;
 			new_bwr_size -= size;
 		    }
 		}
@@ -506,8 +515,8 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 
 		    k = (k + 1)%flat_buf->count;
 		    buf_count++;
-		    i = (int) (buftype_extent*(buf_count/flat_buf->count) +
-			flat_buf->indices[k]); 
+		    i_offset = (ADIO_Offset)buftype_extent*(ADIO_Offset)(buf_count/flat_buf->count) +
+			flat_buf->indices[k]; 
 		    new_bwr_size = flat_buf->blocklens[k];
 		    if (size != fwr_size) {
 			off += size;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str.c
index 87f110d..fb1136f 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str.c
@@ -51,8 +51,8 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
     ADIO_Offset i_offset, new_brd_size, brd_size, size;
     int j, k, st_index=0;
     unsigned num, bufsize; 
-    int n_etypes_in_filetype, size_in_filetype;
-    ADIO_Offset n_filetypes, etype_in_filetype, st_n_filetypes;
+    int n_etypes_in_filetype;
+    ADIO_Offset n_filetypes, etype_in_filetype, st_n_filetypes, size_in_filetype;
     ADIO_Offset abs_off_in_filetype=0, new_frd_size, frd_size=0, st_frd_size;
     int filetype_size, etype_size, buftype_size, partial_read;
     MPI_Aint filetype_extent, buftype_extent; 
@@ -184,7 +184,7 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
     int i;
 	    n_etypes_in_filetype = filetype_size/etype_size;
 	    n_filetypes = offset / n_etypes_in_filetype;
-	    etype_in_filetype = (int) (offset % n_etypes_in_filetype);
+	    etype_in_filetype = offset % n_etypes_in_filetype;
 	    size_in_filetype = etype_in_filetype * etype_size;
  
 	    sum = 0;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_coll.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_coll.c
index c9e6165..7c70eee 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_coll.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_coll.c
@@ -452,9 +452,9 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
                                &(others_req[i].mem_ptrs[j]));
       ADIOI_Assert((off + size - req_off) == (int)(off + size - req_off));
 			recv_size[i] += (int)(ADIOI_MIN(off + size - req_off, 
-                                      (ADIO_Offset)(unsigned)req_len));
+                                      (unsigned)req_len));
 
-			if (off+size-req_off < (ADIO_Offset)(unsigned)req_len)
+			if (off+size-req_off < (unsigned)req_len)
 			{
 			    partial_recv[i] = (int) (off + size - req_off);
 
@@ -914,7 +914,7 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 		}
 		else {
         ADIOI_Assert((curr_to_proc[p] + len) == (unsigned)((ADIO_Offset)curr_to_proc[p] + len));
-		    curr_to_proc[p] += (int)len;
+		    curr_to_proc[p] += len;
 		    buf_incr = len;
 		    ADIOI_BUF_INCR
 		}
-- 
1.5.3.7




More information about the mpich2-dev mailing list