[mpich2-dev] [PATCH 2/2] Issue 4120: Offset/MPI_Aint changes

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


Switched many integers to offsets and added many asserts.  Was looking
in particular for offsets cast to int, math involving (int*int) which
could overflow > 2G and for min(int,offset) which could incorrectly
select negative/overflow int's as the min.  (Sometime switch int's to
unsigned to avoid negative min's.)

Added asserts instead of switching to offsets if it seemed like there was
little or no chance of overflow.  But mostly just changed a lot of things
to offsets.

Signed-off-by: Bob Cernohous <bobc at us.ibm.com>
---
 lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl.h  |    2 +
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.c       |   26 ++-
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.h       |    2 +-
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_rdcoll.c      |   27 ++--
 .../mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_read.c |   14 +-
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_wrcoll.c      |   27 ++--
 .../src/mpi/romio/adio/ad_bgl/ad_bgl_write.c       |   14 +-
 .../src/mpi/romio/adio/common/ad_aggregate.c       |   26 ++-
 .../mpich2/src/mpi/romio/adio/common/ad_darray.c   |   26 ++--
 .../mpich2/src/mpi/romio/adio/common/ad_iread.c    |    3 +-
 .../src/mpi/romio/adio/common/ad_iread_fake.c      |    7 +-
 .../mpich2/src/mpi/romio/adio/common/ad_iwrite.c   |    3 +-
 .../src/mpi/romio/adio/common/ad_iwrite_fake.c     |   12 +-
 .../mpich2/src/mpi/romio/adio/common/ad_prealloc.c |   15 ++-
 lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read.c |    8 +-
 .../src/mpi/romio/adio/common/ad_read_coll.c       |  189 +++++++++++---------
 .../mpich2/src/mpi/romio/adio/common/ad_read_str.c |  106 ++++++-----
 .../src/mpi/romio/adio/common/ad_read_str_naive.c  |   67 ++++---
 .../mpich2/src/mpi/romio/adio/common/ad_resize.c   |    3 +-
 lib/mpi/mpich2/src/mpi/romio/adio/common/ad_seek.c |   18 +-
 .../mpich2/src/mpi/romio/adio/common/ad_subarray.c |   18 +-
 .../mpich2/src/mpi/romio/adio/common/ad_write.c    |    8 +-
 .../src/mpi/romio/adio/common/ad_write_coll.c      |   94 ++++++-----
 .../src/mpi/romio/adio/common/ad_write_nolock.c    |   50 +++--
 .../src/mpi/romio/adio/common/ad_write_str.c       |  117 +++++++------
 .../src/mpi/romio/adio/common/ad_write_str_naive.c |   72 +++++----
 .../mpich2/src/mpi/romio/adio/common/byte_offset.c |   16 +-
 .../mpich2/src/mpi/romio/adio/common/eof_offset.c  |   19 +-
 lib/mpi/mpich2/src/mpi/romio/adio/common/flatten.c |  134 +++++++++-----
 .../mpich2/src/mpi/romio/adio/common/get_fp_posn.c |   20 ++-
 lib/mpi/mpich2/src/mpi/romio/adio/common/lock.c    |    4 +-
 lib/mpi/mpich2/src/mpi/romio/adio/include/adioi.h  |   17 ++-
 32 files changed, 680 insertions(+), 484 deletions(-)

diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl.h b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl.h
index f1ee16c..f5cae5f 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl.h
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl.h
@@ -33,8 +33,10 @@
 #include <aio.h>
 #endif
 
+#if 0 
 int ADIOI_BGL_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
 		  int wr, void *handle);
+#endif
 
 void ADIOI_BGL_Open(ADIO_File fd, int *error_code);
 
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.c b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.c
index 7ca72be..36338ab 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.c
@@ -637,7 +637,7 @@ int ADIOI_BGL_Calc_aggregator(ADIO_File fd,
  * of this process are located in the file domains of various processes
  * (including this one)
  */
-void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list, 
+void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, ADIO_Offset *len_list, 
 			   int contig_access_count, ADIO_Offset 
 			   min_st_offset, ADIO_Offset *fd_start,
 			   ADIO_Offset *fd_end, ADIO_Offset fd_size,
@@ -646,6 +646,8 @@ void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list
 			   int **count_my_req_per_proc_ptr,
 			   ADIOI_Access **my_req_ptr,
 			   int **buf_idx_ptr)
+/* Possibly reconsider if buf_idx's are ok as int's, or should they be aints/offsets? 
+   They are used as memory buffer indices so it seems like the 2G limit is in effect */
 {
     int *count_my_req_per_proc, count_my_req_procs, *buf_idx;
     int i, l, proc;
@@ -737,10 +739,14 @@ void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list
 				     fd_start, fd_end);
 
 	/* for each separate contiguous access from this process */
-	if (buf_idx[proc] == -1) buf_idx[proc] = (int) curr_idx;
+	if (buf_idx[proc] == -1)
+  {
+    ADIOI_Assert(curr_idx == (int) curr_idx);
+    buf_idx[proc] = (int) curr_idx;
+  }
 
 	l = my_req[proc].count;
-	curr_idx += (int) fd_len; /* NOTE: Why is curr_idx an int?  Fix? */
+	curr_idx += fd_len;
 
 	rem_len = len_list[i] - fd_len;
 
@@ -750,6 +756,7 @@ void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list
 	 * and the associated count. 
 	 */
 	my_req[proc].offsets[l] = off;
+  ADIOI_Assert(fd_len == (int) fd_len);
 	my_req[proc].lens[l] = (int) fd_len;
 	my_req[proc].count++;
 
@@ -759,13 +766,18 @@ void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list
 	    proc = ADIOI_BGL_Calc_aggregator(fd, off, min_st_offset, &fd_len, 
 					 fd_size, fd_start, fd_end);
 
-	    if (buf_idx[proc] == -1) buf_idx[proc] = (int) curr_idx;
+	    if (buf_idx[proc] == -1) 
+      {
+        ADIOI_Assert(curr_idx == (int) curr_idx);
+        buf_idx[proc] = (int) curr_idx;
+      }
 
 	    l = my_req[proc].count;
 	    curr_idx += fd_len;
 	    rem_len -= fd_len;
 
 	    my_req[proc].offsets[l] = off;
+      ADIOI_Assert(fd_len == (int) fd_len);
 	    my_req[proc].lens[l] = (int) fd_len;
 	    my_req[proc].count++;
 	}
@@ -777,17 +789,13 @@ void ADIOI_BGL_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list
 	    DBG_FPRINTF(stderr, "data needed from %d (count = %d):\n", i, 
 		    my_req[i].count);
 	    for (l=0; l < my_req[i].count; l++) {
-		DBG_FPRINTF(stderr, "   off[%d] = %Ld, len[%d] = %d\n", l,
+		DBG_FPRINTF(stderr, "   off[%d] = %lld, len[%d] = %d\n", l,
 			my_req[i].offsets[l], l, my_req[i].lens[l]);
 	    }
 	}
-    }
-#if 0
-    for (i=0; i<nprocs; i++) {
 	DBG_FPRINTF(stderr, "buf_idx[%d] = 0x%x\n", i, buf_idx[i]);
     }
 #endif
-#endif
 
     *count_my_req_procs_ptr = count_my_req_procs;
     *buf_idx_ptr = buf_idx;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.h b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.h
index 573517a..3008663 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.h
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/ad_bgl/ad_bgl_aggrs.h
@@ -66,7 +66,7 @@
 
     /* overriding ADIOI_Calc_my_req for the default implementation is specific for 
        static file domain partitioning */
-    void ADIOI_BGL_Calc_my_req ( ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
+    void ADIOI_BGL_Calc_my_req ( ADIO_File fd, ADIO_Offset *offset_list, ADIO_Offset *len_list,
 				 int contig_access_count, ADIO_Offset
 				 min_st_offset, ADIO_Offset *fd_start,
 				 ADIO_Offset *fd_end, ADIO_Offset fd_size,
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 ec7cc8f..c4c5deb 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
@@ -37,13 +37,13 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 				datatype, int nprocs,
 				int myrank, ADIOI_Access
 				*others_req, ADIO_Offset *offset_list,
-				int *len_list, int contig_access_count, 
+				ADIO_Offset *len_list, int contig_access_count, 
 				ADIO_Offset
 				min_st_offset, ADIO_Offset fd_size,
 				ADIO_Offset *fd_start, ADIO_Offset *fd_end,
 				int *buf_idx, int *error_code);
 static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-				  *flat_buf, ADIO_Offset *offset_list, int
+				  *flat_buf, ADIO_Offset *offset_list, ADIO_Offset
 				  *len_list, int *send_size, int *recv_size,
 				  int *count, int *start_pos, 
 				  int *partial_send, 
@@ -57,7 +57,7 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 				  int iter, 
 				  MPI_Aint buftype_extent, int *buf_idx);
 static void ADIOI_R_Exchange_data_alltoallv(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-                                  *flat_buf, ADIO_Offset *offset_list, int
+                                  *flat_buf, ADIO_Offset *offset_list, ADIO_Offset
                                   *len_list, int *send_size, int *recv_size,
                                   int *count, int *start_pos,
                                   int *partial_send,
@@ -72,7 +72,7 @@ static void ADIOI_R_Exchange_data_alltoallv(ADIO_File fd, void *buf, ADIOI_Flatl
                                   MPI_Aint buftype_extent, int *buf_idx);
 static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 				   *flat_buf, char **recv_buf, ADIO_Offset 
-				   *offset_list, int *len_list, 
+				   *offset_list, ADIO_Offset *len_list, 
 				   int *recv_size, 
 				   MPI_Request *requests, MPI_Status *statuses,
 				   int *recd_from_proc, int nprocs,
@@ -84,7 +84,7 @@ static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 
 extern void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 			    datatype, int file_ptr_type, ADIO_Offset
-			    offset, ADIO_Offset **offset_list_ptr, int
+			    offset, ADIO_Offset **offset_list_ptr, ADIO_Offset
 			    **len_list_ptr, ADIO_Offset *start_offset_ptr,
 			    ADIO_Offset *end_offset_ptr, int
 			   *contig_access_count_ptr);
@@ -116,7 +116,8 @@ void ADIOI_BGL_ReadStridedColl(ADIO_File fd, void *buf, int count,
 	*fd_end = NULL, *end_offsets = NULL;
     ADIO_Offset *bgl_offsets0 = NULL, *bgl_offsets = NULL;
     int  ii;
-    int *len_list = NULL, *buf_idx = NULL;
+    ADIO_Offset *len_list = NULL;
+    int *buf_idx = NULL;
 /*
     double io_time = 0., all_time, max_all_time; 
     double tstep1, max_tstep1;
@@ -169,7 +170,7 @@ void ADIOI_BGL_ReadStridedColl(ADIO_File fd, void *buf, int count,
 
 #ifdef RDCOLL_DEBUG
     for (i=0; i<contig_access_count; i++) {
-	      DBG_FPRINTF(stderr, "rank %d  off %lld  len %d\n", myrank, offset_list[i], 
+	      DBG_FPRINTF(stderr, "rank %d  off %lld  len %lld\n", myrank, offset_list[i], 
 	      len_list[i]);
     }
 #endif
@@ -397,7 +398,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 			 datatype, int nprocs,
 			 int myrank, ADIOI_Access
 			 *others_req, ADIO_Offset *offset_list,
-			 int *len_list, int contig_access_count, ADIO_Offset
+			 ADIO_Offset *len_list, int contig_access_count, ADIO_Offset
                          min_st_offset, ADIO_Offset fd_size,
 			 ADIO_Offset *fd_start, ADIO_Offset *fd_end,
                          int *buf_idx, int *error_code)
@@ -722,7 +723,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 }
 
 static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-			 *flat_buf, ADIO_Offset *offset_list, int
+			 *flat_buf, ADIO_Offset *offset_list, ADIO_Offset
                          *len_list, int *send_size, int *recv_size,
 			 int *count, int *start_pos, int *partial_send, 
 			 int *recd_from_proc, int nprocs, 
@@ -760,7 +761,7 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
     if (buftype_is_contig) {
 	j = 0;
 	for (i=0; i < nprocs; i++) 
-	    if (recv_size[i]) {
+	    if (recv_size[i]) { 
 		MPI_Irecv(((char *) buf) + buf_idx[i], recv_size[i], 
 		  MPI_BYTE, i, myrank+i+100*iter, fd->comm, requests+j);
 		j++;
@@ -898,7 +899,7 @@ 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, int *len_list, 
+				   *offset_list, ADIO_Offset *len_list, 
 				   int *recv_size, 
 				   MPI_Request *requests, MPI_Status *statuses,
 				   int *recd_from_proc, int nprocs,
@@ -942,7 +943,7 @@ static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 
     for (i=0; i<contig_access_count; i++) { 
 	off     = offset_list[i];
-	rem_len = (ADIO_Offset) len_list[i];
+	rem_len = len_list[i];
 
 	/* this request may span the file domains of more than one process */
 	while (rem_len > 0) {
@@ -1001,7 +1002,7 @@ static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 
 static void ADIOI_R_Exchange_data_alltoallv(
                 ADIO_File fd, void *buf, ADIOI_Flatlist_node
-                *flat_buf, ADIO_Offset *offset_list, int
+                *flat_buf, ADIO_Offset *offset_list, ADIO_Offset
                 *len_list, int *send_size, int *recv_size, 
                 int *count, int *start_pos, int *partial_send,
                 int *recd_from_proc, int nprocs,
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 41947c9..64f845a 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
@@ -26,7 +26,8 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
                      MPI_Datatype datatype, int file_ptr_type,
 		     ADIO_Offset offset, ADIO_Status *status, int *error_code)
 {
-    int err=-1, datatype_size, len;
+    int err=-1, datatype_size;
+    ADIO_Offset len;
     static char myname[] = "ADIOI_BGL_READCONTIG";
 
 #if BGL_PROFILE
@@ -40,7 +41,8 @@ void ADIOI_BGL_ReadContig(ADIO_File fd, void *buf, int count,
 #endif
 
     MPI_Type_size(datatype, &datatype_size);
-    len = datatype_size * count;
+    len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
+    ADIOI_Assert(len == (unsigned int) len); /* read takes an unsigned int parm */
 
 #if BGL_PROFILE
 
@@ -166,7 +168,8 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
 /* 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, frd_size=0, st_index=0;
+    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 abs_off_in_filetype=0;
@@ -176,8 +179,8 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
     ADIO_Offset userbuf_off;
     ADIO_Offset off, req_off, disp, end_offset=0, readbuf_off, start_off;
     char *readbuf, *tmp_buf, *value;
-    int flag, st_frd_size, st_n_filetypes, readbuf_len;
-    int new_brd_size, new_frd_size, err_flag=0, info_flag, max_bufsize;
+    int flag, st_n_filetypes, readbuf_len;
+    int err_flag=0, info_flag, max_bufsize;
 
     static char myname[] = "ADIOI_BGL_READSTRIDED";
 
@@ -212,6 +215,7 @@ void ADIOI_BGL_ReadStrided(ADIO_File fd, void *buf, int count,
     MPI_Type_extent(datatype, &buftype_extent);
     etype_size = fd->etype_size;
 
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
 /* get max_bufsize from the info object. */
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 22af36d..1427ae8 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
@@ -31,13 +31,13 @@
 static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
                          datatype, int nprocs, int myrank, ADIOI_Access
                          *others_req, ADIO_Offset *offset_list,
-                         int *len_list, int contig_access_count, ADIO_Offset
+                         ADIO_Offset *len_list, int contig_access_count, ADIO_Offset
                          min_st_offset, ADIO_Offset fd_size,
                          ADIO_Offset *fd_start, ADIO_Offset *fd_end,
                          int *buf_idx, int *error_code);
 static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
                          ADIOI_Flatlist_node *flat_buf, ADIO_Offset 
-                         *offset_list, int *len_list, int *send_size, 
+                         *offset_list, ADIO_Offset *len_list, int *send_size, 
                          int *recv_size, ADIO_Offset off, int size,
                          int *count, int *start_pos, int *partial_recv, 
                          int *sent_to_proc, int nprocs, 
@@ -54,7 +54,7 @@ static void ADIOI_W_Exchange_data_alltoallv(
 		char *write_buf,					/* 1 */
 		ADIOI_Flatlist_node *flat_buf, 
 		ADIO_Offset *offset_list, 
-		int *len_list, int *send_size, int *recv_size, 
+		ADIO_Offset *len_list, int *send_size, int *recv_size, 
 		ADIO_Offset off, int size,				/* 2 */
 		int *count, int *start_pos, int *partial_recv,
 		int *sent_to_proc, int nprocs, int myrank, 
@@ -70,7 +70,7 @@ static void ADIOI_W_Exchange_data_alltoallv(
 		int *error_code);
 static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            *flat_buf, char **send_buf, ADIO_Offset 
-                           *offset_list, int *len_list, int *send_size, 
+                           *offset_list, ADIO_Offset *len_list, int *send_size, 
                            MPI_Request *requests, int *sent_to_proc, 
                            int nprocs, int myrank, 
                            int contig_access_count, ADIO_Offset
@@ -81,7 +81,7 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            MPI_Aint buftype_extent);
 static void ADIOI_Fill_send_buffer_nosend(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            *flat_buf, char **send_buf, ADIO_Offset 
-                           *offset_list, int *len_list, int *send_size, 
+                           *offset_list, ADIO_Offset *len_list, int *send_size, 
                            MPI_Request *requests, int *sent_to_proc, 
                            int nprocs, int myrank, 
                            int contig_access_count, ADIO_Offset
@@ -123,7 +123,8 @@ void ADIOI_BGL_WriteStridedColl(ADIO_File fd, void *buf, int count,
     ADIO_Offset *bgl_offsets0 = NULL, *bgl_offsets = NULL;
     int  ii;
 
-    int *buf_idx = NULL, *len_list = NULL;
+    int *buf_idx = NULL;
+    ADIO_Offset *len_list = NULL;
 /*
     double io_time = 0, all_time, max_all_time;
     double tstep1, max_tstep1;
@@ -379,7 +380,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 				 datatype, int nprocs, int myrank,
 				 ADIOI_Access
 				 *others_req, ADIO_Offset *offset_list,
-				 int *len_list, int contig_access_count,
+				 ADIO_Offset *len_list, int contig_access_count,
 				 ADIO_Offset
 				 min_st_offset, ADIO_Offset fd_size,
 				 ADIO_Offset *fd_start, ADIO_Offset *fd_end,
@@ -683,7 +684,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
  */
 static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
 				  ADIOI_Flatlist_node *flat_buf, ADIO_Offset 
-				  *offset_list, int *len_list, int *send_size, 
+				  *offset_list, ADIO_Offset *len_list, int *send_size, 
 				  int *recv_size, ADIO_Offset off, int size,
 				  int *count, int *start_pos,
 				  int *partial_recv,
@@ -960,7 +961,7 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
 
 static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            *flat_buf, char **send_buf, ADIO_Offset 
-                           *offset_list, int *len_list, int *send_size, 
+                           *offset_list, ADIO_Offset *len_list, int *send_size, 
                            MPI_Request *requests, int *sent_to_proc, 
                            int nprocs, int myrank, 
                            int contig_access_count, 
@@ -1000,7 +1001,7 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 
     for (i=0; i<contig_access_count; i++) { 
 	off     = offset_list[i];
-	rem_len = (ADIO_Offset) len_list[i];
+	rem_len = len_list[i];
 
 	/*this request may span the file domains of more than one process*/
   while (rem_len != 0) {
@@ -1186,7 +1187,7 @@ static void ADIOI_W_Exchange_data_alltoallv(
 		char *write_buf,					/* 1 */
 		ADIOI_Flatlist_node *flat_buf, 
 		ADIO_Offset *offset_list, 
-		int *len_list, int *send_size, int *recv_size, 
+		ADIO_Offset *len_list, int *send_size, int *recv_size, 
 		ADIO_Offset off, int size,				/* 2 */
 		int *count, int *start_pos, int *partial_recv,
 		int *sent_to_proc, int nprocs, int myrank, 
@@ -1354,7 +1355,7 @@ static void ADIOI_W_Exchange_data_alltoallv(
 
 static void ADIOI_Fill_send_buffer_nosend(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            *flat_buf, char **send_buf, ADIO_Offset 
-                           *offset_list, int *len_list, int *send_size, 
+                           *offset_list, ADIO_Offset *len_list, int *send_size, 
                            MPI_Request *requests, int *sent_to_proc, 
                            int nprocs, int myrank, 
                            int contig_access_count, 
@@ -1394,7 +1395,7 @@ static void ADIOI_Fill_send_buffer_nosend(ADIO_File fd, void *buf, ADIOI_Flatlis
 
     for (i=0; i<contig_access_count; i++) { 
 	off     = offset_list[i];
-	rem_len = (ADIO_Offset) len_list[i];
+	rem_len = len_list[i];
 
 	/*this request may span the file domains of more than one process*/
   while (rem_len != 0) {
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 6fbdb20..5f06a1c 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
@@ -26,7 +26,8 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
                      MPI_Datatype datatype, int file_ptr_type,
 		     ADIO_Offset offset, ADIO_Status *status, int *error_code)
 {
-    int err=-1, datatype_size, len;
+    int err=-1, datatype_size;
+    ADIO_Offset len;
     static char myname[] = "ADIOI_BGL_WRITECONTIG";
 
 #if BGL_PROFILE
@@ -40,7 +41,8 @@ void ADIOI_BGL_WriteContig(ADIO_File fd, void *buf, int count,
 #endif
 			  
     MPI_Type_size(datatype, &datatype_size);
-    len = datatype_size * count;
+    len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
+    ADIOI_Assert(len == (unsigned int) len); /* read takes an unsigned int parm */
 
 #if BGL_PROFILE
 
@@ -207,7 +209,8 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
 /* offset is in units of etype relative to the filetype. */
 
     ADIOI_Flatlist_node *flat_buf, *flat_file;
-    int i, j, k, err=-1, bwr_size, fwr_size=0, st_index=0;
+    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 abs_off_in_filetype=0;
@@ -217,8 +220,8 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
     ADIO_Offset userbuf_off;
     ADIO_Offset off, req_off, disp, end_offset=0, writebuf_off, start_off;
     char *writebuf, *value;
-    int flag, st_fwr_size, st_n_filetypes, writebuf_len, write_sz;
-    int new_bwr_size, new_fwr_size, err_flag=0, info_flag, max_bufsize;
+    int flag, st_n_filetypes, writebuf_len, write_sz;
+    int err_flag=0, info_flag, max_bufsize;
     static char myname[] = "ADIOI_BGL_WRITESTRIDED";
 
     if (fd->hints->ds_write == ADIOI_HINT_DISABLE) {
@@ -252,6 +255,7 @@ void ADIOI_BGL_WriteStrided(ADIO_File fd, void *buf, int count,
     MPI_Type_extent(datatype, &buftype_extent);
     etype_size = fd->etype_size;
 
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
 /* get max_bufsize from the info object. */
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_aggregate.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_aggregate.c
index 7252f50..8e19bad 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_aggregate.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_aggregate.c
@@ -194,7 +194,7 @@ void ADIOI_Calc_file_domains(ADIO_Offset *st_offsets, ADIO_Offset
  * of this process are located in the file domains of various processes
  * (including this one)
  */
-void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list, 
+void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, ADIO_Offset *len_list, 
 		       int contig_access_count, ADIO_Offset 
 		       min_st_offset, ADIO_Offset *fd_start,
 		       ADIO_Offset *fd_end, ADIO_Offset fd_size,
@@ -203,6 +203,8 @@ void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
 		       int **count_my_req_per_proc_ptr,
 		       ADIOI_Access **my_req_ptr,
 		       int **buf_idx_ptr)
+/* Possibly reconsider if buf_idx's are ok as int's, or should they be aints/offsets? 
+   They are used as memory buffer indices so it seems like the 2G limit is in effect */
 {
     int *count_my_req_per_proc, count_my_req_procs, *buf_idx;
     int i, l, proc;
@@ -293,10 +295,14 @@ void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
 				     fd_start, fd_end);
 
 	/* for each separate contiguous access from this process */
-	if (buf_idx[proc] == -1) buf_idx[proc] = (int) curr_idx;
+	if (buf_idx[proc] == -1) 
+  {
+    ADIOI_Assert(curr_idx == (int) curr_idx);
+    buf_idx[proc] = (int) curr_idx;
+  }
 
 	l = my_req[proc].count;
-	curr_idx += (int) fd_len; /* NOTE: Why is curr_idx an int?  Fix? */
+	curr_idx += fd_len; 
 
 	rem_len = len_list[i] - fd_len;
 
@@ -306,6 +312,7 @@ void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
 	 * and the associated count. 
 	 */
 	my_req[proc].offsets[l] = off;
+  ADIOI_Assert(fd_len == (int) fd_len);
 	my_req[proc].lens[l] = (int) fd_len;
 	my_req[proc].count++;
 
@@ -315,13 +322,18 @@ void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
 	    proc = ADIOI_Calc_aggregator(fd, off, min_st_offset, &fd_len, 
 					 fd_size, fd_start, fd_end);
 
-	    if (buf_idx[proc] == -1) buf_idx[proc] = (int) curr_idx;
+	    if (buf_idx[proc] == -1) 
+      {
+        ADIOI_Assert(curr_idx == (int) curr_idx);
+        buf_idx[proc] = (int) curr_idx;
+      }
 
 	    l = my_req[proc].count;
 	    curr_idx += fd_len;
 	    rem_len -= fd_len;
 
 	    my_req[proc].offsets[l] = off;
+      ADIOI_Assert(fd_len == (int) fd_len);
 	    my_req[proc].lens[l] = (int) fd_len;
 	    my_req[proc].count++;
 	}
@@ -336,14 +348,10 @@ void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
 		FPRINTF(stdout, "   off[%d] = %lld, len[%d] = %d\n", l,
 			my_req[i].offsets[l], l, my_req[i].lens[l]);
 	    }
-	}
-    }
-#if 0
-    for (i=0; i<nprocs; i++) {
 	FPRINTF(stdout, "buf_idx[%d] = 0x%x\n", i, buf_idx[i]);
+	}
     }
 #endif
-#endif
 
     *count_my_req_procs_ptr = count_my_req_procs;
     *buf_idx_ptr = buf_idx;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_darray.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_darray.c
index b9b3c46..faa2cf6 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_darray.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_darray.c
@@ -81,7 +81,7 @@ int ADIO_Type_create_darray(int size, int rank, int ndims,
 	tmp_size = 1;
 	for (i=1; i<ndims; i++) {
 	    tmp_size *= array_of_gsizes[i-1];
-	    disps[1] += tmp_size*st_offsets[i];
+	    disps[1] += (MPI_Aint)tmp_size*st_offsets[i];
 	}
         /* rest done below for both Fortran and C order */
     }
@@ -119,14 +119,14 @@ int ADIO_Type_create_darray(int size, int rank, int ndims,
 	tmp_size = 1;
 	for (i=ndims-2; i>=0; i--) {
 	    tmp_size *= array_of_gsizes[i+1];
-	    disps[1] += tmp_size*st_offsets[i];
+	    disps[1] += (MPI_Aint)tmp_size*st_offsets[i];
 	}
     }
 
     disps[1] *= orig_extent;
 
     disps[2] = orig_extent;
-    for (i=0; i<ndims; i++) disps[2] *= array_of_gsizes[i];
+    for (i=0; i<ndims; i++) disps[2] *= (MPI_Aint)array_of_gsizes[i];
 	
     disps[0] = 0;
     blklens[0] = blklens[1] = blklens[2] = 1;
@@ -183,7 +183,7 @@ static int MPIOI_Type_block(int *array_of_gsizes, int dim, int ndims, int nprocs
 	if (dim == 0) 
 	    MPI_Type_contiguous(mysize, type_old, type_new);
 	else {
-	    for (i=0; i<dim; i++) stride *= array_of_gsizes[i];
+	    for (i=0; i<dim; i++) stride *= (MPI_Aint)array_of_gsizes[i];
 	    MPI_Type_hvector(mysize, 1, stride, type_old, type_new);
 	}
     }
@@ -191,13 +191,13 @@ static int MPIOI_Type_block(int *array_of_gsizes, int dim, int ndims, int nprocs
 	if (dim == ndims-1) 
 	    MPI_Type_contiguous(mysize, type_old, type_new);
 	else {
-	    for (i=ndims-1; i>dim; i--) stride *= array_of_gsizes[i];
+	    for (i=ndims-1; i>dim; i--) stride *= (MPI_Aint)array_of_gsizes[i];
 	    MPI_Type_hvector(mysize, 1, stride, type_old, type_new);
 	}
 
     }
 
-    *st_offset = blksize * rank;
+    *st_offset = (MPI_Aint)blksize * (MPI_Aint)rank;
      /* in terms of no. of elements of type oldtype in this dimension */
     if (mysize == 0) *st_offset = 0;
 
@@ -241,10 +241,10 @@ static int MPIOI_Type_cyclic(int *array_of_gsizes, int dim, int ndims, int nproc
     count = local_size/blksize;
     rem = local_size % blksize;
     
-    stride = nprocs*blksize*orig_extent;
+    stride = (MPI_Aint)nprocs*(MPI_Aint)blksize*orig_extent;
     if (order == MPI_ORDER_FORTRAN)
-	for (i=0; i<dim; i++) stride *= array_of_gsizes[i];
-    else for (i=ndims-1; i>dim; i--) stride *= array_of_gsizes[i];
+	for (i=0; i<dim; i++) stride *= (MPI_Aint)array_of_gsizes[i];
+    else for (i=ndims-1; i>dim; i--) stride *= (MPI_Aint)array_of_gsizes[i];
 
     MPI_Type_hvector(count, blksize, stride, type_old, type_new);
 
@@ -255,7 +255,7 @@ static int MPIOI_Type_cyclic(int *array_of_gsizes, int dim, int ndims, int nproc
 	types[0] = *type_new;
 	types[1] = type_old;
 	disps[0] = 0;
-	disps[1] = count*stride;
+	disps[1] = (MPI_Aint)count*stride;
 	blklens[0] = 1;
 	blklens[1] = rem;
 
@@ -272,9 +272,9 @@ static int MPIOI_Type_cyclic(int *array_of_gsizes, int dim, int ndims, int nproc
         types[0] = MPI_LB;
         disps[0] = 0;
         types[1] = *type_new;
-        disps[1] = rank * blksize * orig_extent;
+        disps[1] = (MPI_Aint)rank * (MPI_Aint)blksize * orig_extent;
         types[2] = MPI_UB;
-        disps[2] = orig_extent * array_of_gsizes[dim];
+        disps[2] = orig_extent * (MPI_Aint)array_of_gsizes[dim];
         blklens[0] = blklens[1] = blklens[2] = 1;
         MPI_Type_struct(3, blklens, disps, types, &type_tmp);
         MPI_Type_free(type_new);
@@ -284,7 +284,7 @@ static int MPIOI_Type_cyclic(int *array_of_gsizes, int dim, int ndims, int nproc
                             the struct above */
     }
     else {
-        *st_offset = rank * blksize; 
+        *st_offset = (MPI_Aint)rank * (MPI_Aint)blksize; 
         /* st_offset is in terms of no. of elements of type oldtype in
          * this dimension */ 
     }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread.c
index 34fce2c..2a38295 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread.c
@@ -45,6 +45,7 @@ void ADIOI_GEN_IreadContig(ADIO_File fd, void *buf, int count,
     static char myname[] = "ADIOI_GEN_IREADCONTIG";
 
     MPI_Type_size(datatype, &typesize);
+    ADIOI_Assert((count * typesize) == ((ADIO_Offset)(unsigned)count * (ADIO_Offset)typesize));
     len = count * typesize;
 
     if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
@@ -84,7 +85,7 @@ void ADIOI_GEN_IreadStrided(ADIO_File fd, void *buf, int count,
 
     if (*error_code == MPI_SUCCESS) {
 	MPI_Type_size(datatype, &typesize);
-	nbytes = count*typesize;
+	nbytes = (MPI_Offset)count*(MPI_Offset)typesize;
     }
     MPIO_Completed_request_create(&fd, nbytes, error_code, request);
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread_fake.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread_fake.c
index 1a35164..c6a2562 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread_fake.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iread_fake.c
@@ -21,12 +21,13 @@ void ADIOI_FAKE_IreadContig(ADIO_File fd, void *buf, int count,
     MPI_Offset len;
 
     MPI_Type_size(datatype, &typesize);
-    len = count * typesize;
+    len = (MPI_Offset)count * (MPI_Offset)typesize;
 
     /* Call the blocking function.  It will create an error code
      * if necessary.
      */
-    ADIO_ReadContig(fd, buf, len, MPI_BYTE, file_ptr_type, offset, 
+    ADIOI_Assert(len == (int) len); /* the count is an int parm */
+    ADIO_ReadContig(fd, buf, (int)len, MPI_BYTE, file_ptr_type, offset, 
 		    &status, error_code);  
     if (*error_code != MPI_SUCCESS) {
 	    len=0;
@@ -54,7 +55,7 @@ void ADIOI_FAKE_IreadStrided(ADIO_File fd, void *buf, int count,
 		     offset, &status, error_code);  
     if (*error_code == MPI_SUCCESS) {
 	MPI_Type_size(datatype, &typesize);
-	nbytes = count*typesize;
+	nbytes = (MPI_Offset)count*(MPI_Offset)typesize;
     }
     MPIO_Completed_request_create(&fd, nbytes, error_code, request);
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite.c
index 15d6a66..76ee366 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite.c
@@ -54,6 +54,7 @@ void ADIOI_GEN_IwriteContig(ADIO_File fd, void *buf, int count,
 
     MPI_Type_size(datatype, &typesize);
     len = count * typesize;
+    ADIOI_Assert(len == (int)((ADIO_Offset)count * (ADIO_Offset)typesize)); /* the count is an int parm */
 
     if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
     aio_errno = ADIOI_GEN_aio(fd, buf, len, offset, 1, request);
@@ -177,7 +178,7 @@ void ADIOI_GEN_IwriteStrided(ADIO_File fd, void *buf, int count,
 
     if (*error_code == MPI_SUCCESS) {
 	MPI_Type_size(datatype, &typesize);
-	nbytes = count * typesize;
+	nbytes = (MPI_Offset)count * (MPI_Offset)typesize;
     }
     MPIO_Completed_request_create(&fd, nbytes, error_code, request);
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite_fake.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite_fake.c
index 5fce4e3..1df7d9d 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite_fake.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_iwrite_fake.c
@@ -18,20 +18,22 @@ void ADIOI_FAKE_IwriteContig(ADIO_File fd, void *buf, int count,
 			    int *error_code)  
 {
     ADIO_Status status;
-    int len, typesize;
+    MPI_Offset len;
+    int typesize;
     MPI_Offset nbytes=0;
 
     MPI_Type_size(datatype, &typesize);
-    len = count * typesize;
+    len = (MPI_Offset)count * (MPI_Offset)typesize;
 
     /* Call the blocking function.  It will create an error code
      * if necessary.
      */
-    ADIO_WriteContig(fd, buf, len, MPI_BYTE, file_ptr_type, offset,
+    ADIOI_Assert(len == (int) len); /* the count is an int parm */
+    ADIO_WriteContig(fd, buf, (int)len, MPI_BYTE, file_ptr_type, offset,
 		     &status, error_code);  
     if (*error_code == MPI_SUCCESS) {
 	MPI_Type_size(datatype, &typesize);
-	nbytes = count*typesize;
+	nbytes = (MPI_Offset)count*(MPI_Offset)typesize;
     }
     MPIO_Completed_request_create(&fd, nbytes, error_code, request);
 
@@ -57,7 +59,7 @@ void ADIOI_FAKE_IwriteStrided(ADIO_File fd, void *buf, int count,
 		      offset, &status, error_code);  
     if (*error_code == MPI_SUCCESS) {
 	MPI_Type_size(datatype, &typesize);
-	nbytes = count * typesize;
+	nbytes = (MPI_Offset)count * (MPI_Offset)typesize;
     }
     MPIO_Completed_request_create(&fd, nbytes, error_code, request);
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_prealloc.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_prealloc.c
index 4b44ccb..cd18dbb 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_prealloc.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_prealloc.c
@@ -47,7 +47,10 @@ void ADIOI_GEN_Prealloc(ADIO_File fd, ADIO_Offset diskspace, int *error_code)
 
 	for (i=0; i<ntimes; i++) {
 	    len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
-	    ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
+	    ADIO_ReadContig(fd, buf, 
+                      len, /* len is ADIO_Offset but is <= ADIOI_PREALLOC_BUFSZ (16M), 
+                              so it fits in an int parameter */
+                      MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
 			    &status, error_code);
 	    if (*error_code != MPI_SUCCESS) {
 		*error_code = MPIO_Err_create_code(MPI_SUCCESS,
@@ -58,7 +61,10 @@ void ADIOI_GEN_Prealloc(ADIO_File fd, ADIO_Offset diskspace, int *error_code)
 						   0);
                 return;  
 	    }
-	    ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
+	    ADIO_WriteContig(fd, buf, 
+                       len, /* len is ADIO_Offset but is <= ADIOI_PREALLOC_BUFSZ (16M), 
+                               so it fits in an int parameter */
+                       MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
                              done, &status, error_code);
 	    if (*error_code != MPI_SUCCESS) return;
 	    done += len;
@@ -70,7 +76,10 @@ void ADIOI_GEN_Prealloc(ADIO_File fd, ADIO_Offset diskspace, int *error_code)
 	    ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
 	    for (i=0; i<ntimes; i++) {
 		len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
-		ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
+		ADIO_WriteContig(fd, buf, 
+                     len, /* len is ADIO_Offset but is <= ADIOI_PREALLOC_BUFSZ (16M), 
+                             so it fits in an int parameter */
+                     MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
 				 done, &status, error_code);
 		if (*error_code != MPI_SUCCESS) return;
 		done += len;  
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read.c
index 0cef18a..b14207b 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read.c
@@ -16,11 +16,13 @@ void ADIOI_GEN_ReadContig(ADIO_File fd, void *buf, int count,
 			  ADIO_Offset offset, ADIO_Status *status,
 			  int *error_code)
 {
-    int err = -1, datatype_size, len;
+    int err = -1, datatype_size;
+    ADIO_Offset len;
     static char myname[] = "ADIOI_GEN_READCONTIG";
 
     MPI_Type_size(datatype, &datatype_size);
-    len = datatype_size * count;
+    len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
+    ADIOI_Assert(len == (unsigned int) len); /* read takes an unsigned int parm */
 
     if (file_ptr_type == ADIO_INDIVIDUAL) {
 	offset = fd->fp_ind;
@@ -50,7 +52,7 @@ void ADIOI_GEN_ReadContig(ADIO_File fd, void *buf, int count,
 #ifdef ADIOI_MPE_LOGGING
     MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
 #endif
-    err = read(fd->fd_sys, buf, len);
+    err = read(fd->fd_sys, buf, (unsigned int)len);
 #ifdef ADIOI_MPE_LOGGING
     MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
 #endif
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_coll.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_coll.c
index 42ebc58..18e0b4c 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_coll.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_coll.c
@@ -17,13 +17,13 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 				datatype, int nprocs,
 				int myrank, ADIOI_Access
 				*others_req, ADIO_Offset *offset_list,
-				int *len_list, int contig_access_count, 
+				ADIO_Offset *len_list, int contig_access_count, 
 				ADIO_Offset
 				min_st_offset, ADIO_Offset fd_size,
 				ADIO_Offset *fd_start, ADIO_Offset *fd_end,
 				int *buf_idx, int *error_code);
 static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-				  *flat_buf, ADIO_Offset *offset_list, int
+				  *flat_buf, ADIO_Offset *offset_list, ADIO_Offset
 				  *len_list, int *send_size, int *recv_size,
 				  int *count, int *start_pos, 
 				  int *partial_send, 
@@ -38,8 +38,8 @@ static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 				  MPI_Aint buftype_extent, int *buf_idx);
 static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 				   *flat_buf, char **recv_buf, ADIO_Offset 
-				   *offset_list, int *len_list, 
-				   int *recv_size, 
+				   *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, 
@@ -74,7 +74,8 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File fd, void *buf, int count,
     ADIO_Offset start_offset, end_offset, orig_fp, fd_size, min_st_offset, off;
     ADIO_Offset *offset_list = NULL, *st_offsets = NULL, *fd_start = NULL,
 	*fd_end = NULL, *end_offsets = NULL;
-    int *len_list = NULL, *buf_idx = NULL;
+    ADIO_Offset *len_list = NULL;
+    int *buf_idx = NULL;
 
 #ifdef HAVE_STATUS_SET_BYTES
     int bufsize, size;
@@ -101,7 +102,7 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File fd, void *buf, int count,
     
 #ifdef RDCOLL_DEBUG
     for (i=0; i<contig_access_count; i++) {
-	      DBG_FPRINTF(stderr, "rank %d  off %lld  len %d\n", myrank, offset_list[i], 
+	      DBG_FPRINTF(stderr, "rank %d  off %lld  len %lld\n", myrank, offset_list[i], 
 	      len_list[i]);
 	      }
 #endif
@@ -263,17 +264,23 @@ void ADIOI_GEN_ReadStridedColl(ADIO_File fd, void *buf, int count,
 
 void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 			    datatype, int file_ptr_type, ADIO_Offset
-			    offset, ADIO_Offset **offset_list_ptr, int
+			    offset, ADIO_Offset **offset_list_ptr, ADIO_Offset
 			    **len_list_ptr, ADIO_Offset *start_offset_ptr,
 			    ADIO_Offset *end_offset_ptr, int
 			   *contig_access_count_ptr)
 {
-    int filetype_size, buftype_size, etype_size;
-    int i, j, k, frd_size=0, old_frd_size=0, st_index=0;
-    int n_filetypes, etype_in_filetype;
+    int filetype_size, etype_size;
+    unsigned buftype_size;
+    int j, k;
+    ADIO_Offset i_offset;
+    ADIO_Offset frd_size=0, old_frd_size=0;
+    int st_index=0;
+    ADIO_Offset n_filetypes, etype_in_filetype;
     ADIO_Offset abs_off_in_filetype=0;
-    int bufsize, sum, n_etypes_in_filetype, size_in_filetype;
-    int contig_access_count, *len_list, flag, filetype_is_contig;
+    ADIO_Offset bufsize;
+    ADIO_Offset sum, n_etypes_in_filetype, size_in_filetype;
+    int contig_access_count, flag, filetype_is_contig;
+    ADIO_Offset *len_list;
     MPI_Aint filetype_extent, filetype_lb;
     ADIOI_Flatlist_node *flat_file;
     ADIO_Offset *offset_list, off, end_offset=0, disp;
@@ -286,19 +293,19 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
     MPI_Type_size(fd->filetype, &filetype_size);
     MPI_Type_extent(fd->filetype, &filetype_extent);
     MPI_Type_lb(fd->filetype, &filetype_lb);
-    MPI_Type_size(datatype, &buftype_size);
+    MPI_Type_size(datatype, (int*)&buftype_size);
     etype_size = fd->etype_size;
 
     if ( ! filetype_size ) {
 	*contig_access_count_ptr = 0;
 	*offset_list_ptr = (ADIO_Offset *) ADIOI_Malloc(2*sizeof(ADIO_Offset));
-	*len_list_ptr = (int *) ADIOI_Malloc(2*sizeof(int));
+	*len_list_ptr = (ADIO_Offset *) ADIOI_Malloc(2*sizeof(ADIO_Offset));
         /* 2 is for consistency. everywhere I malloc one more than needed */
 
 	offset_list = *offset_list_ptr;
 	len_list = *len_list_ptr;
         offset_list[0] = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
-                 fd->disp + etype_size * offset;
+                 fd->disp + (ADIO_Offset)etype_size * offset;
 	len_list[0] = 0;
 	*start_offset_ptr = offset_list[0];
 	*end_offset_ptr = offset_list[0] + len_list[0] - 1;
@@ -309,14 +316,14 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
     if (filetype_is_contig) {
 	*contig_access_count_ptr = 1;        
 	*offset_list_ptr = (ADIO_Offset *) ADIOI_Malloc(2*sizeof(ADIO_Offset));
-	*len_list_ptr = (int *) ADIOI_Malloc(2*sizeof(int));
+	*len_list_ptr = (ADIO_Offset *) ADIOI_Malloc(2*sizeof(ADIO_Offset));
         /* 2 is for consistency. everywhere I malloc one more than needed */
 
 	offset_list = *offset_list_ptr;
 	len_list = *len_list_ptr;
         offset_list[0] = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
-                 fd->disp + etype_size * offset;
-	len_list[0] = bufcount * buftype_size;
+                 fd->disp + (ADIO_Offset)etype_size * offset;
+	len_list[0] = (ADIO_Offset)bufcount * (ADIO_Offset)buftype_size;
 	*start_offset_ptr = offset_list[0];
 	*end_offset_ptr = offset_list[0] + len_list[0] - 1;
 
@@ -337,7 +344,7 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 	int ii;
 	DBG_FPRINTF(stderr, "flattened %3d : ", flat_file->count );
 	for (ii=0; ii<flat_file->count; ii++) {
-	    DBG_FPRINTF(stderr, "%16qd:%-12qd", flat_file->indices[ii], flat_file->blocklens[ii] );
+	    DBG_FPRINTF(stderr, "%16qd:%-16qd", flat_file->indices[ii], flat_file->blocklens[ii] );
 	}
   	DBG_FPRINTF(stderr, "\n" );
 #endif
@@ -346,16 +353,17 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 	    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 + 
+			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;
 		    }
@@ -363,9 +371,10 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 	    }
 	}
 	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;
@@ -381,29 +390,29 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 	    }
 
 	    /* abs. offset in bytes in the file */
-	    offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + 
+	    offset = disp + n_filetypes* (ADIO_Offset)filetype_extent + 
 		abs_off_in_filetype;
 	}
 
          /* calculate how much space to allocate for offset_list, len_list */
 
 	old_frd_size = frd_size;
-	contig_access_count = i = 0;
+	contig_access_count = i_offset = 0;
 	j = st_index;
-	bufsize = buftype_size * bufcount;
+	bufsize = (ADIO_Offset)buftype_size * (ADIO_Offset)bufcount;
 	frd_size = ADIOI_MIN(frd_size, bufsize);
-	while (i < bufsize) {
+	while (i_offset < bufsize) {
 	    if (frd_size) contig_access_count++;
-	    i += frd_size;
+	    i_offset += frd_size;
 	    j = (j + 1) % flat_file->count;
-	    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+	    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 	}
 
         /* allocate space for offset_list and len_list */
 
 	*offset_list_ptr = (ADIO_Offset *)
 	         ADIOI_Malloc((contig_access_count+1)*sizeof(ADIO_Offset));  
-	*len_list_ptr = (int *) ADIOI_Malloc((contig_access_count+1)*sizeof(int));
+	*len_list_ptr = (ADIO_Offset *) ADIOI_Malloc((contig_access_count+1)*sizeof(ADIO_Offset));
         /* +1 to avoid a 0-size malloc */
 
 	offset_list = *offset_list_ptr;
@@ -413,13 +422,13 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 
 	*start_offset_ptr = offset; /* calculated above */
 
-	i = k = 0;
+	i_offset = k = 0;
 	j = st_index;
 	off = offset;
 	frd_size = ADIOI_MIN(old_frd_size, bufsize);
         ADIO_Offset min_off = 1048576; min_off *= (1048576*1024);
         ADIO_Offset max_off = 0;
-	while (i < bufsize) {
+	while (i_offset < bufsize) {
 	    if (frd_size) {
 		offset_list[k] = off;
 		len_list[k] = frd_size;
@@ -427,7 +436,7 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 		max_off = ( max_off < (offset_list[k] + len_list[k] - 1) ? (offset_list[k] + len_list[k] - 1) : max_off );
 		k++;
 	    }
-	    i += frd_size;
+	    i_offset += frd_size;
 	    end_offset = off + frd_size - 1;
 
      /* Note: end_offset points to the last byte-offset that will be accessed.
@@ -435,7 +444,7 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 
 	    if (off + frd_size < disp + flat_file->indices[j] +
 		flat_file->blocklens[j] + 
-		(ADIO_Offset) n_filetypes*filetype_extent)
+		 n_filetypes* (ADIO_Offset)filetype_extent)
 	    {
 		off += frd_size;
 		/* did not reach end of contiguous block in filetype.
@@ -452,8 +461,8 @@ void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 		    n_filetypes++;
 		}
 		off = disp + flat_file->indices[j] + 
-		    (ADIO_Offset) n_filetypes*filetype_extent;
-		frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+		     n_filetypes* (ADIO_Offset)filetype_extent;
+		frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 	    }
 	}
 
@@ -471,7 +480,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 			 datatype, int nprocs,
 			 int myrank, ADIOI_Access
 			 *others_req, ADIO_Offset *offset_list,
-			 int *len_list, int contig_access_count, ADIO_Offset
+			 ADIO_Offset *len_list, int contig_access_count, ADIO_Offset
                          min_st_offset, ADIO_Offset fd_size,
 			 ADIO_Offset *fd_start, ADIO_Offset *fd_end,
                          int *buf_idx, int *error_code)
@@ -486,12 +495,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;
-    ADIO_Offset st_loc=-1, end_loc=-1, off, done, real_off, req_off;
+    int i, j, m, ntimes, max_ntimes, buftype_is_contig;
+    ADIO_Offset st_loc=-1, end_loc=-1, off, done, real_off, req_off, tmp_scratch_offset;
     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;
@@ -621,7 +632,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
                        minus what was satisfied in previous iteration
              req_size = size corresponding to req_off */
 
-	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;
 
@@ -654,22 +665,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 */
 			    }
@@ -687,7 +698,8 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 	    if (count[i]) flag = 1;
 
 	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);
 	    if (*error_code != MPI_SUCCESS) return;
 	}
@@ -706,6 +718,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);
@@ -740,7 +754,7 @@ static void ADIOI_Read_and_exch(ADIO_File fd, void *buf, MPI_Datatype
 }
 
 static void ADIOI_R_Exchange_data(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-			 *flat_buf, ADIO_Offset *offset_list, int
+			 *flat_buf, ADIO_Offset *offset_list, ADIO_Offset
                          *len_list, int *send_size, int *recv_size,
 			 int *count, int *start_pos, int *partial_send, 
 			 int *recd_from_proc, int nprocs, 
@@ -866,6 +880,18 @@ 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)
+{
 
 #define ADIOI_BUF_INCR \
 { \
@@ -880,7 +906,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; \
@@ -892,9 +918,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) { \
@@ -904,7 +932,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; \
@@ -914,24 +942,14 @@ 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, int *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;
 
     ADIOI_UNREFERENCED_ARG(requests);
     ADIOI_UNREFERENCED_ARG(statuses);
@@ -942,9 +960,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;
@@ -962,7 +980,7 @@ static void ADIOI_Fill_user_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 
     for (i=0; i<contig_access_count; i++) { 
 	off     = offset_list[i];
-	rem_len = (ADIO_Offset) len_list[i];
+	rem_len = len_list[i];
 
 	/* this request may span the file domains of more than one process */
 	while (rem_len != 0) {
@@ -982,29 +1000,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/common/ad_read_str.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str.c
index a387ab9..87f110d 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
@@ -8,16 +8,23 @@
 #include "adio.h"
 #include "adio_extern.h"
 
+void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
+                       MPI_Datatype datatype, int file_ptr_type,
+                       ADIO_Offset offset, ADIO_Status *status, int
+                       *error_code)
+{
+
 #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));\
 	ADIO_ReadContig(fd, readbuf, readbuf_len, MPI_BYTE, \
               ADIO_EXPLICIT_OFFSET, readbuf_off, &status1, error_code); \
         if (*error_code != MPI_SUCCESS) return; \
     } \
     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); \
@@ -26,37 +33,36 @@
 	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)); \
 	ADIO_ReadContig(fd, readbuf+partial_read, readbuf_len-partial_read, \
              MPI_BYTE, ADIO_EXPLICIT_OFFSET, readbuf_off+partial_read, \
              &status1, error_code); \
         if (*error_code != MPI_SUCCESS) return; \
     } \
+    ADIOI_Assert(req_len == (size_t)req_len); \
     memcpy((char *)buf + userbuf_off, readbuf+req_off-readbuf_off, req_len); \
 }
 
 
-void ADIOI_GEN_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, brd_size, frd_size=0, st_index=0;
-    int bufsize, num, size, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
-    ADIO_Offset abs_off_in_filetype=0;
-    int filetype_size, etype_size, buftype_size, req_len, partial_read;
+    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;
+    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; 
     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_frd_size, st_n_filetypes, readbuf_len;
-    int new_brd_size, new_frd_size, info_flag, max_bufsize;
+    int flag;
+    int info_flag;
+    unsigned max_bufsize, readbuf_len;
     ADIO_Status status1;
 
     if (fd->hints->ds_read == ADIOI_HINT_DISABLE) {
@@ -90,6 +96,7 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
     MPI_Type_extent(datatype, &buftype_extent);
     etype_size = fd->etype_size;
 
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
 /* get max_bufsize from the info object. */
@@ -110,13 +117,13 @@ void ADIOI_GEN_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) && (fd->file_system != ADIO_PIOFS) && (fd->file_system != ADIO_PVFS))
@@ -127,13 +134,15 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
 	if (*error_code != MPI_SUCCESS) return;
 
         for (j=0; j<count; j++) 
-            for (i=0; i<flat_buf->count; i++) {
-                userbuf_off = j*buftype_extent + flat_buf->indices[i];
-		req_off = off;
-		req_len = flat_buf->blocklens[i];
-		ADIOI_BUFFERED_READ
-                off += flat_buf->blocklens[i];
-            }
+        { int i;
+              for (i=0; i<flat_buf->count; 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
+                  off += flat_buf->blocklens[i];
+              }
+        }
 
         if ((fd->atomicity) && (fd->file_system != ADIO_PIOFS) && (fd->file_system != ADIO_PVFS))
             ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
@@ -155,15 +164,16 @@ void ADIOI_GEN_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;
 		    }
@@ -171,8 +181,9 @@ void ADIOI_GEN_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);
+	    n_filetypes = offset / n_etypes_in_filetype;
 	    etype_in_filetype = (int) (offset % n_etypes_in_filetype);
 	    size_in_filetype = etype_in_filetype * etype_size;
  
@@ -189,7 +200,7 @@ void ADIOI_GEN_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;
@@ -199,12 +210,12 @@ void ADIOI_GEN_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++;
@@ -213,8 +224,8 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
 		n_filetypes++;
 	    }
 
-	    off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes*filetype_extent;
-	    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+	    off = disp + flat_file->indices[j] + n_filetypes*(ADIO_Offset)filetype_extent;
+	    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 	}
 
 /* if atomicity is true, lock (exclusive) the region to be accessed */
@@ -230,12 +241,12 @@ void ADIOI_GEN_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 */ 
@@ -244,13 +255,13 @@ void ADIOI_GEN_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. */
@@ -261,8 +272,8 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[j] + 
-                                        (ADIO_Offset) n_filetypes*filetype_extent;
-		    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+                                        n_filetypes*(ADIO_Offset)filetype_extent;
+		    frd_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 		}
 	    }
 	}
@@ -274,7 +285,7 @@ void ADIOI_GEN_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;
@@ -289,7 +300,7 @@ void ADIOI_GEN_ReadStrided(ADIO_File fd, void *buf, int count,
 
 		    req_off = off;
 		    req_len = size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 		    ADIOI_BUFFERED_READ
 		}
 
@@ -305,11 +316,11 @@ void ADIOI_GEN_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;
 		    }
 		}
@@ -319,7 +330,7 @@ void ADIOI_GEN_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) {
@@ -327,6 +338,7 @@ void ADIOI_GEN_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/common/ad_read_str_naive.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str_naive.c
index 26d00e3..3c9f69a 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str_naive.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_read_str_naive.c
@@ -16,11 +16,13 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
     /* offset is in units of etype relative to the filetype. */
 
     ADIOI_Flatlist_node *flat_buf, *flat_file;
-    int brd_size, frd_size=0, b_index;
-    int bufsize, size, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
+    ADIO_Offset size, brd_size, frd_size=0, req_len, sum;
+    int b_index;
+    int n_etypes_in_filetype;
+    ADIO_Offset n_filetypes, etype_in_filetype;
     ADIO_Offset abs_off_in_filetype=0;
-    int filetype_size, etype_size, buftype_size, req_len;
+    unsigned bufsize, filetype_size, buftype_size, size_in_filetype;
+    int etype_size;
     MPI_Aint filetype_extent, buftype_extent; 
     int buf_count, buftype_is_contig, filetype_is_contig;
     ADIO_Offset userbuf_off;
@@ -32,17 +34,18 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
     ADIOI_Datatype_iscontig(buftype, &buftype_is_contig);
     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
 
-    MPI_Type_size(fd->filetype, &filetype_size);
+    MPI_Type_size(fd->filetype, (int*)&filetype_size);
     if ( ! filetype_size ) {
 	*error_code = MPI_SUCCESS; 
 	return;
     }
 
     MPI_Type_extent(fd->filetype, &filetype_extent);
-    MPI_Type_size(buftype, &buftype_size);
+    MPI_Type_size(buftype,(int*) &buftype_size);
     MPI_Type_extent(buftype, &buftype_extent);
     etype_size = fd->etype_size;
 
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
     /* contiguous in buftype and filetype is handled elsewhere */
@@ -73,11 +76,13 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 	 */
         for (b_count=0; b_count < count; b_count++) {
             for (b_index=0; b_index < flat_buf->count; b_index++) {
-                userbuf_off = b_count*buftype_extent + 
+                userbuf_off = (ADIO_Offset)b_count*(ADIO_Offset)buftype_extent + 
 		              flat_buf->indices[b_index];
 		req_off = off;
 		req_len = flat_buf->blocklens[b_index];
 
+    ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + userbuf_off) == (ADIO_Offset)(unsigned long)(buf + userbuf_off));
+    ADIOI_Assert(req_len == (int) req_len);
 		ADIO_ReadContig(fd, 
 				(char *) buf + userbuf_off,
 				req_len, 
@@ -104,7 +109,9 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
     }
 
     else {  /* noncontiguous in file */
-    	int f_index, st_frd_size, st_index = 0, st_n_filetypes;
+    	int f_index, st_index = 0; 
+      ADIO_Offset st_n_filetypes;
+      ADIO_Offset st_frd_size;
 	int flag;
 
         /* First we're going to calculate a set of values for use in all
@@ -134,15 +141,15 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
                 n_filetypes++;
 		for (f_index=0; f_index < flat_file->count; f_index++) {
 		    if (disp + flat_file->indices[f_index] + 
-                       (ADIO_Offset) n_filetypes*filetype_extent + 
+                       n_filetypes*(ADIO_Offset)filetype_extent + 
 		       flat_file->blocklens[f_index] >= start_off) 
 		    {
 		    	/* this block contains our starting position */
 
 			st_index = f_index;
-			frd_size = (int) (disp + flat_file->indices[f_index] + 
-		 	           (ADIO_Offset) n_filetypes*filetype_extent + 
-				   flat_file->blocklens[f_index] - start_off);
+			frd_size = disp + flat_file->indices[f_index] + 
+		 	           n_filetypes*(ADIO_Offset)filetype_extent + 
+				   flat_file->blocklens[f_index] - start_off;
 			flag = 1;
 			break;
 		    }
@@ -151,9 +158,9 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 	}
 	else {
 	    n_etypes_in_filetype = filetype_size/etype_size;
-	    n_filetypes = (int) (offset / n_etypes_in_filetype);
+	    n_filetypes = offset / n_etypes_in_filetype;
 	    etype_in_filetype = (int) (offset % n_etypes_in_filetype);
-	    size_in_filetype = etype_in_filetype * etype_size;
+	    size_in_filetype = (unsigned)etype_in_filetype * (unsigned)etype_size;
  
 	    sum = 0;
 	    for (f_index=0; f_index < flat_file->count; f_index++) {
@@ -169,7 +176,7 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 	    }
 
 	    /* abs. offset in bytes in the file */
-	    start_off = disp + (ADIO_Offset) n_filetypes*filetype_extent + 
+	    start_off = disp + n_filetypes*(ADIO_Offset)filetype_extent + 
 	    	        abs_off_in_filetype;
 	}
 
@@ -198,9 +205,9 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 	    }
 
 	    off = disp + flat_file->indices[f_index] + 
-	          (ADIO_Offset) n_filetypes*filetype_extent;
+	          n_filetypes*(ADIO_Offset)filetype_extent;
 	    frd_size = ADIOI_MIN(flat_file->blocklens[f_index], 
-	                         bufsize-(int)userbuf_off);
+	                         bufsize-(unsigned)userbuf_off);
 	}
 
 	/* End of calculations.  At this point the following values have
@@ -238,6 +245,8 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 		    req_off = off;
 		    req_len = frd_size;
 
+        ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + userbuf_off) == (ADIO_Offset)(unsigned long)(buf + userbuf_off));
+        ADIOI_Assert(req_len == (int) req_len);
 		    ADIO_ReadContig(fd, 
 				    (char *) buf + userbuf_off,
 				    req_len, 
@@ -252,7 +261,7 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 
                 if (off + frd_size < disp + flat_file->indices[f_index] +
                    flat_file->blocklens[f_index] + 
-		   (ADIO_Offset) n_filetypes*filetype_extent)
+		   n_filetypes*(ADIO_Offset)filetype_extent)
 		{
 		    /* important that this value be correct, as it is
 		     * used to set the offset in the fd near the end of
@@ -270,14 +279,14 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[f_index] + 
-                          (ADIO_Offset) n_filetypes*filetype_extent;
+                          n_filetypes*(ADIO_Offset)filetype_extent;
 		    frd_size = ADIOI_MIN(flat_file->blocklens[f_index], 
-		                         bufsize-(int)userbuf_off);
+		                         bufsize-(unsigned)userbuf_off);
 		}
 	    }
 	}
 	else {
-	    int i, tmp_bufsize = 0;
+	    ADIO_Offset i_offset, tmp_bufsize = 0;
 	    /* noncontiguous in memory as well as in file */
 
 	    ADIOI_Flatten_datatype(buftype);
@@ -285,7 +294,7 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 	    while (flat_buf->type != buftype) flat_buf = flat_buf->next;
 
 	    b_index = buf_count = 0;
-	    i = (int) (flat_buf->indices[0]);
+	    i_offset = flat_buf->indices[0];
 	    f_index = st_index;
 	    off = start_off;
 	    n_filetypes = st_n_filetypes;
@@ -294,14 +303,16 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 
 	    /* while we haven't read size * count bytes, keep going */
 	    while (tmp_bufsize < bufsize) {
-    		int new_brd_size = brd_size, new_frd_size = frd_size;
+    		ADIO_Offset new_brd_size = brd_size, new_frd_size = frd_size;
 
 		size = ADIOI_MIN(frd_size, brd_size);
 		if (size) {
 		    req_off = off;
 		    req_len = size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 
+        ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + userbuf_off) == (ADIO_Offset)(unsigned long)(buf + userbuf_off));
+        ADIOI_Assert(req_len == (int) req_len);
 		    ADIO_ReadContig(fd, 
 				    (char *) buf + userbuf_off,
 				    req_len, 
@@ -322,11 +333,11 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 		    }
 
 		    off = disp + flat_file->indices[f_index] + 
-                          (ADIO_Offset) n_filetypes*filetype_extent;
+                          n_filetypes*(ADIO_Offset)filetype_extent;
 
 		    new_frd_size = flat_file->blocklens[f_index];
 		    if (size != brd_size) {
-			i += size;
+			i_offset += size;
 			new_brd_size -= size;
 		    }
 		}
@@ -336,8 +347,8 @@ void ADIOI_GEN_ReadStrided_naive(ADIO_File fd, void *buf, int count,
 
 		    b_index = (b_index + 1)%flat_buf->count;
 		    buf_count++;
-		    i = (int) (buftype_extent*(buf_count/flat_buf->count) +
-			flat_buf->indices[b_index]);
+		    i_offset = buftype_extent*(buf_count/flat_buf->count) +
+			flat_buf->indices[b_index];
 		    new_brd_size = flat_buf->blocklens[b_index];
 		    if (size != frd_size) {
 			off += size;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_resize.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_resize.c
index 18e1d1f..bf38296 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_resize.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_resize.c
@@ -20,7 +20,8 @@ void ADIOI_GEN_Resize(ADIO_File fd, ADIO_Offset size, int *error_code)
 
     /* first aggregator performs ftruncate() */
     if (rank == fd->hints->ranklist[0]) {
-	err = ftruncate(fd->fd_sys, size);
+    ADIOI_Assert(size == (off_t) size); 
+	err = ftruncate(fd->fd_sys, (off_t)size);
     }
 
     /* bcast return value */
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_seek.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_seek.c
index 18482f0..2fc19c5 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_seek.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_seek.c
@@ -22,10 +22,12 @@ ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
     ADIO_Offset off;
     ADIOI_Flatlist_node *flat_file;
 
-    int i, n_etypes_in_filetype, n_filetypes, etype_in_filetype;
+    int i;
+    ADIO_Offset n_etypes_in_filetype, n_filetypes, etype_in_filetype;
     ADIO_Offset abs_off_in_filetype=0;
-    int size_in_filetype, sum;
-    int filetype_size, etype_size, filetype_is_contig;
+    ADIO_Offset size_in_filetype, sum;
+    unsigned filetype_size;
+    int etype_size, filetype_is_contig;
     MPI_Aint filetype_extent;
 
     ADIOI_UNREFERENCED_ARG(whence);
@@ -33,13 +35,13 @@ ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
     etype_size = fd->etype_size;
 
-    if (filetype_is_contig) off = fd->disp + etype_size * offset;
+    if (filetype_is_contig) off = fd->disp + (ADIO_Offset)etype_size * offset;
     else {
         flat_file = ADIOI_Flatlist;
         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
 
 	MPI_Type_extent(fd->filetype, &filetype_extent);
-	MPI_Type_size(fd->filetype, &filetype_size);
+	MPI_Type_size(fd->filetype, (int*)&filetype_size);
 	if ( ! filetype_size ) {
 	    /* Since offset relative to the filetype size, we can't
 	       do compute the offset when that result is zero.
@@ -49,8 +51,8 @@ ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
 	}
 
 	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;
@@ -64,7 +66,7 @@ ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
 	}
 
 	/* abs. offset in bytes in the file */
-	off = fd->disp + (ADIO_Offset) n_filetypes * filetype_extent +
+	off = fd->disp + n_filetypes * filetype_extent +
                 abs_off_in_filetype;
     }
 
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_subarray.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_subarray.c
index 4f99ae2..f9a32e3 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_subarray.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_subarray.c
@@ -32,9 +32,9 @@ int ADIO_Type_create_subarray(int ndims,
 			    array_of_subsizes[0],
 			    array_of_sizes[0], oldtype, &tmp1);
 	    
-	    size = array_of_sizes[0]*extent;
+	    size = (MPI_Aint)array_of_sizes[0]*extent;
 	    for (i=2; i<ndims; i++) {
-		size *= array_of_sizes[i-1];
+		size *= (MPI_Aint)array_of_sizes[i-1];
 		MPI_Type_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
 		MPI_Type_free(&tmp1);
 		tmp1 = tmp2;
@@ -45,8 +45,8 @@ int ADIO_Type_create_subarray(int ndims,
 	disps[1] = array_of_starts[0];
 	size = 1;
 	for (i=1; i<ndims; i++) {
-	    size *= array_of_sizes[i-1];
-	    disps[1] += size*array_of_starts[i];
+	    size *= (MPI_Aint)array_of_sizes[i-1];
+	    disps[1] += size*(MPI_Aint)array_of_starts[i];
 	}  
         /* rest done below for both Fortran and C order */
     }
@@ -61,9 +61,9 @@ int ADIO_Type_create_subarray(int ndims,
 			    array_of_subsizes[ndims-1],
 			    array_of_sizes[ndims-1], oldtype, &tmp1);
 	    
-	    size = array_of_sizes[ndims-1]*extent;
+	    size = (MPI_Aint)array_of_sizes[ndims-1]*extent;
 	    for (i=ndims-3; i>=0; i--) {
-		size *= array_of_sizes[i+1];
+		size *= (MPI_Aint)array_of_sizes[i+1];
 		MPI_Type_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
 		MPI_Type_free(&tmp1);
 		tmp1 = tmp2;
@@ -74,15 +74,15 @@ int ADIO_Type_create_subarray(int ndims,
 	disps[1] = array_of_starts[ndims-1];
 	size = 1;
 	for (i=ndims-2; i>=0; i--) {
-	    size *= array_of_sizes[i+1];
-	    disps[1] += size*array_of_starts[i];
+	    size *= (MPI_Aint)array_of_sizes[i+1];
+	    disps[1] += size*(MPI_Aint)array_of_starts[i];
 	}
     }
     
     disps[1] *= extent;
     
     disps[2] = extent;
-    for (i=0; i<ndims; i++) disps[2] *= array_of_sizes[i];
+    for (i=0; i<ndims; i++) disps[2] *= (MPI_Aint)array_of_sizes[i];
     
     disps[0] = 0;
     blklens[0] = blklens[1] = blklens[2] = 1;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write.c
index ea2fc1f..80e5ca8 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write.c
@@ -16,11 +16,13 @@ void ADIOI_GEN_WriteContig(ADIO_File fd, void *buf, int count,
 			   ADIO_Offset offset, ADIO_Status *status,
 			   int *error_code)
 {
-    int err = -1, datatype_size, len;
+    int err = -1, datatype_size;
+    ADIO_Offset len;
     static char myname[] = "ADIOI_GEN_WRITECONTIG";
 
     MPI_Type_size(datatype, &datatype_size);
-    len = datatype_size * count;
+    len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
+    ADIOI_Assert(len == (unsigned int) len); /* read takes an unsigned int parm */
 
     if (file_ptr_type == ADIO_INDIVIDUAL) {
 	offset = fd->fp_ind;
@@ -50,7 +52,7 @@ void ADIOI_GEN_WriteContig(ADIO_File fd, void *buf, int count,
 #ifdef ADIOI_MPE_LOGGING
     MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
 #endif
-    err = write(fd->fd_sys, buf, len);
+    err = write(fd->fd_sys, buf, (unsigned int)len);
 #ifdef ADIOI_MPE_LOGGING
     MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
 #endif
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 f71ec67..a23731d 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
@@ -13,13 +13,13 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
                          datatype, int nprocs, int myrank,
 			 ADIOI_Access
                          *others_req, ADIO_Offset *offset_list,
-                         int *len_list, int contig_access_count, ADIO_Offset
+                         ADIO_Offset *len_list, int contig_access_count, ADIO_Offset
                          min_st_offset, ADIO_Offset fd_size,
                          ADIO_Offset *fd_start, ADIO_Offset *fd_end,
                          int *buf_idx, int *error_code);
 static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
                          ADIOI_Flatlist_node *flat_buf, ADIO_Offset 
-                         *offset_list, int *len_list, int *send_size, 
+                         *offset_list, ADIO_Offset *len_list, int *send_size, 
                          int *recv_size, ADIO_Offset off, int size,
                          int *count, int *start_pos, int *partial_recv, 
                          int *sent_to_proc, int nprocs, 
@@ -33,7 +33,7 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
                          MPI_Aint buftype_extent, int *buf_idx, int *error_code);
 static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
                            *flat_buf, char **send_buf, ADIO_Offset 
-                           *offset_list, int *len_list, int *send_size, 
+                           *offset_list, ADIO_Offset *len_list, int *send_size, 
                            MPI_Request *requests, int *sent_to_proc, 
                            int nprocs, int myrank, 
                            int contig_access_count, ADIO_Offset
@@ -72,7 +72,8 @@ void ADIOI_GEN_WriteStridedColl(ADIO_File fd, void *buf, int count,
     ADIO_Offset orig_fp, start_offset, end_offset, fd_size, min_st_offset, off;
     ADIO_Offset *offset_list = NULL, *st_offsets = NULL, *fd_start = NULL,
 	*fd_end = NULL, *end_offsets = NULL;
-    int *buf_idx = NULL, *len_list = NULL;
+    int *buf_idx = NULL;
+    ADIO_Offset *len_list = NULL;
     int old_error, tmp_error;
 
 
@@ -136,7 +137,7 @@ void ADIOI_GEN_WriteStridedColl(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_WriteContig(fd, buf, count, datatype,
 				 ADIO_EXPLICIT_OFFSET,
 				 off, status, error_code);
@@ -276,9 +277,8 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 				 int myrank,
 				 ADIOI_Access
 				 *others_req, ADIO_Offset *offset_list,
-				 int *len_list, int contig_access_count,
-				 ADIO_Offset
-				 min_st_offset, ADIO_Offset fd_size,
+				 ADIO_Offset *len_list, int contig_access_count,
+				 ADIO_Offset min_st_offset, ADIO_Offset fd_size,
 				 ADIO_Offset *fd_start, ADIO_Offset *fd_end,
 				 int *buf_idx, int *error_code)
 {
@@ -291,7 +291,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;
+    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;
@@ -421,7 +423,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
 
 	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) {
@@ -445,12 +447,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, 
+                                      (ADIO_Offset)(unsigned)req_len));
 
-			if (off+size-req_off < req_len)
+			if (off+size-req_off < (ADIO_Offset)(unsigned)req_len)
 			{
 			    partial_recv[i] = (int) (off + size - req_off);
 
@@ -494,7 +498,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;
 	}
@@ -537,7 +542,7 @@ static void ADIOI_Exch_and_write(ADIO_File fd, void *buf, MPI_Datatype
  */
 static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
 				  ADIOI_Flatlist_node *flat_buf, ADIO_Offset 
-				  *offset_list, int *len_list, int *send_size, 
+				  *offset_list, ADIO_Offset *len_list, int *send_size, 
 				  int *recv_size, ADIO_Offset off, int size,
 				  int *count, int *start_pos,
 				  int *partial_recv,
@@ -770,6 +775,24 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
     }
 }
 
+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, 
+                           MPI_Request *requests, int *sent_to_proc, 
+                           int nprocs, int myrank, 
+                           int contig_access_count, 
+                           ADIO_Offset min_st_offset, ADIO_Offset fd_size,
+                           ADIO_Offset *fd_start, ADIO_Offset *fd_end, 
+                           int *send_buf_idx, int *curr_to_proc, 
+                           int *done_to_proc, int iter,
+                           MPI_Aint buftype_extent)
+{
+/* this function is only called if buftype is not contig */
+
+    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;
 
 #define ADIOI_BUF_INCR \
 { \
@@ -784,7 +807,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; \
@@ -796,6 +819,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; \
@@ -808,7 +833,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; \
@@ -819,23 +844,6 @@ static void ADIOI_W_Exchange_data(ADIO_File fd, void *buf, char *write_buf,
 
 
 
-static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
-                           *flat_buf, char **send_buf, ADIO_Offset 
-                           *offset_list, int *len_list, int *send_size, 
-                           MPI_Request *requests, int *sent_to_proc, 
-                           int nprocs, int myrank, 
-                           int contig_access_count, 
-                           ADIO_Offset min_st_offset, ADIO_Offset fd_size,
-                           ADIO_Offset *fd_start, ADIO_Offset *fd_end, 
-                           int *send_buf_idx, int *curr_to_proc, 
-                           int *done_to_proc, int iter,
-                           MPI_Aint buftype_extent)
-{
-/* 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;
-    ADIO_Offset off, len, rem_len, user_buf_idx;
 
 /*  curr_to_proc[p] = amount of data sent to proc. p that has already
     been accounted for so far
@@ -861,7 +869,7 @@ static void ADIOI_Fill_send_buffer(ADIO_File fd, void *buf, ADIOI_Flatlist_node
 
     for (i=0; i<contig_access_count; i++) { 
 	off     = offset_list[i];
-	rem_len = (ADIO_Offset) len_list[i];
+	rem_len = len_list[i];
 
 	/*this request may span the file domains of more than one process*/
 	while (rem_len != 0) {
@@ -881,17 +889,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
 		    }
@@ -902,13 +913,14 @@ 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;
-		    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/common/ad_write_nolock.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_nolock.c
index 16293a2..9530cf2 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_nolock.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_nolock.c
@@ -28,16 +28,18 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
 /* offset is in units of etype relative to the filetype. */
 
     ADIOI_Flatlist_node *flat_buf, *flat_file;
-    int i, j, k, err=-1, bwr_size, fwr_size=0, st_index=0;
-    int bufsize, num, size, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
-    ADIO_Offset abs_off_in_filetype=0;
+    int j, k, err=-1, st_index=0;
+    ADIO_Offset fwr_size=0, bwr_size, new_bwr_size, new_fwr_size, i_offset, num;
+    unsigned bufsize; 
+    int n_etypes_in_filetype;
+    ADIO_Offset n_filetypes, etype_in_filetype, size, sum;
+    ADIO_Offset abs_off_in_filetype=0, size_in_filetype;
     int filetype_size, etype_size, buftype_size;
     MPI_Aint filetype_extent, buftype_extent, indx;
     int buf_count, buftype_is_contig, filetype_is_contig;
     ADIO_Offset off, disp;
-    int flag, new_bwr_size, new_fwr_size, err_flag=0;
-    static char myname[] = "ADIOI_PVFS_WRITESTRIDED";
+    int flag, err_flag=0;
+    static char myname[] = "ADIOI_NOLOCK_WRITESTRIDED";
 #ifdef IO_DEBUG
     int rank,nprocs;
 #endif
@@ -71,6 +73,7 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
     MPI_Type_extent(datatype, &buftype_extent);
     etype_size = fd->etype_size;
     
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
     if (!buftype_is_contig && filetype_is_contig) {
@@ -101,6 +104,7 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
 	 * is also handled.
 	 */
 	for (j=0; j<count; j++) {
+    int i;
 	    for (i=0; i<flat_buf->count; i++) {
 		if (flat_buf->blocklens[i] > combine_buf_remain && combine_buf != combine_buf_ptr) {
 		    /* there is data in the buffer; write out the buffer so far */
@@ -129,9 +133,11 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
 				    rank, nprocs, off, 
 				    flat_buf->blocklens[i]);
 #endif
+        ADIOI_Assert(flat_buf->blocklens[i] == (unsigned)flat_buf->blocklens[i]);
+        ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + j*buftype_extent + flat_buf->indices[i]) == (ADIO_Offset)(buf + j*buftype_extent + flat_buf->indices[i]));
 		    err = write(fd->fd_sys,
 				     ((char *) buf) + j*buftype_extent + flat_buf->indices[i],
-				     flat_buf->blocklens[i]);
+				     (unsigned)flat_buf->blocklens[i]);
 		    if (err == -1) err_flag = 1;
 		    off += flat_buf->blocklens[i]; /* keep up with the final file offset too */
 		}
@@ -189,14 +195,15 @@ void ADIOI_NOLOCK_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 = disp + flat_file->indices[i] + 
-                                (ADIO_Offset) n_filetypes*filetype_extent
+                                n_filetypes*(ADIO_Offset)filetype_extent
                                  + flat_file->blocklens[i] - offset;
                         flag = 1;
                         break;
@@ -205,9 +212,10 @@ void ADIOI_NOLOCK_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;
@@ -223,7 +231,7 @@ void ADIOI_NOLOCK_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;
 	}
 
 	if (buftype_is_contig && !filetype_is_contig) {
@@ -231,11 +239,11 @@ void ADIOI_NOLOCK_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;
 	    fwr_size = ADIOI_MIN(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 */ 
@@ -247,16 +255,16 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
 			    rank, nprocs, off, 
 			     fwr_size);
 #endif
-		    err = pwrite(fd->fd_sys, ((char *) buf) + i, fwr_size, off);
+		    err = pwrite(fd->fd_sys, ((char *) buf) + i_offset, fwr_size, off);
 #ifdef PROFILE
 		    MPE_Log_event(6, 0, "end write");
 #endif
 		    if (err == -1) err_flag = 1;
 		}
-		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. */
@@ -267,8 +275,8 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[j] + 
-                                        (ADIO_Offset) n_filetypes*filetype_extent;
-		    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+                                        n_filetypes*(ADIO_Offset)filetype_extent;
+		    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 		}
 	    }
 	}
@@ -295,6 +303,8 @@ void ADIOI_NOLOCK_WriteStrided(ADIO_File fd, void *buf, int count,
 	    printf("[%d/%d] nc mem nc file writing loc = %Ld sz = %d\n", 
 			    rank, nprocs, off, size);
 #endif
+        ADIOI_Assert(size == (size_t) size);
+        ADIOI_Assert(off == (off_t) off);
 		    err = pwrite(fd->fd_sys, ((char *) buf) + indx, size, off);
 #ifdef PROFILE
 		    MPE_Log_event(6, 0, "end write");
@@ -314,7 +324,7 @@ void ADIOI_NOLOCK_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) {
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str.c
index 8ad385a..2bf0539 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str.c
@@ -8,6 +8,12 @@
 #include "adio.h"
 #include "adio_extern.h"
 
+void ADIOI_GEN_WriteStrided(ADIO_File fd, void *buf, int count,
+                       MPI_Datatype datatype, int file_ptr_type,
+                       ADIO_Offset offset, ADIO_Status *status, int
+                       *error_code)
+{
+
 #define ADIOI_BUFFERED_WRITE \
 { \
     if (req_off >= writebuf_off + writebuf_len) { \
@@ -24,7 +30,7 @@
            } \
         } \
 	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); \
 	ADIO_ReadContig(fd, writebuf, writebuf_len, MPI_BYTE, \
                  ADIO_EXPLICIT_OFFSET, writebuf_off, &status1, error_code); \
@@ -36,7 +42,8 @@
 	    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) { \
         ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE, \
@@ -52,7 +59,7 @@
         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); \
         ADIO_ReadContig(fd, writebuf, writebuf_len, MPI_BYTE, \
                   ADIO_EXPLICIT_OFFSET, writebuf_off, &status1, error_code); \
@@ -84,9 +91,10 @@
             return; \
         } \
 	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) { \
         ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE, \
@@ -101,34 +109,31 @@
         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);\
     } \
 }
 
 
-void ADIOI_GEN_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, bwr_size, fwr_size=0, st_index=0;
-    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, 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;
-    int flag, st_fwr_size, st_n_filetypes, writebuf_len, write_sz;
+    int flag;
+    unsigned bufsize, writebuf_len, max_bufsize, write_sz;
     ADIO_Status status1;
-    int new_bwr_size, new_fwr_size, max_bufsize;
+    ADIO_Offset new_bwr_size, new_fwr_size, st_fwr_size, fwr_size=0, bwr_size, req_len;
     static char myname[] = "ADIOI_GEN_WriteStrided";
 
     if (fd->hints->ds_write == ADIOI_HINT_DISABLE) {
@@ -162,6 +167,7 @@ void ADIOI_GEN_WriteStrided(ADIO_File fd, void *buf, int count,
     MPI_Type_extent(datatype, &buftype_extent);
     etype_size = fd->etype_size;
 
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
 /* get max_bufsize from the info object. */
@@ -177,26 +183,29 @@ void ADIOI_GEN_WriteStrided(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;
         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++) 
-            for (i=0; i<flat_buf->count; i++) {
-                userbuf_off = j*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];
-            }
+        {
+          int i;
+              for (i=0; i<flat_buf->count; 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 */
         ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
@@ -224,15 +233,16 @@ void ADIOI_GEN_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;
 		    }
@@ -240,9 +250,10 @@ void ADIOI_GEN_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;
@@ -258,7 +269,7 @@ void ADIOI_GEN_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;
@@ -268,12 +279,12 @@ void ADIOI_GEN_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++;
@@ -282,8 +293,8 @@ void ADIOI_GEN_WriteStrided(ADIO_File fd, void *buf, int count,
 		n_filetypes++;
 	    }
 
-	    off = disp + flat_file->indices[j] + (ADIO_Offset) n_filetypes*filetype_extent;
-	    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+	    off = disp + flat_file->indices[j] + n_filetypes*(ADIO_Offset)filetype_extent;
+	    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 	}
 
 /* if atomicity is true, lock the region to be accessed */
@@ -300,27 +311,27 @@ void ADIOI_GEN_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. */
@@ -331,8 +342,8 @@ void ADIOI_GEN_WriteStrided(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[j] + 
-                                        (ADIO_Offset) n_filetypes*filetype_extent;
-		    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
+                                        n_filetypes*(ADIO_Offset)filetype_extent;
+		    fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i_offset);
 		}
 	    }
 	}
@@ -344,7 +355,7 @@ void ADIOI_GEN_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;
@@ -355,11 +366,11 @@ void ADIOI_GEN_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
 		}
 
@@ -375,11 +386,11 @@ void ADIOI_GEN_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;
 		    }
 		}
@@ -389,8 +400,8 @@ void ADIOI_GEN_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_write_str_naive.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str_naive.c
index c8247fb..60c44e8 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str_naive.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/ad_write_str_naive.c
@@ -17,11 +17,13 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 
     ADIOI_Flatlist_node *flat_buf, *flat_file;
     /* bwr == buffer write; fwr == file write */
-    int bwr_size, fwr_size=0, b_index;
-    int bufsize, size, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
-    ADIO_Offset abs_off_in_filetype=0;
-    int filetype_size, etype_size, buftype_size, req_len;
+    ADIO_Offset bwr_size, fwr_size=0, sum, size_in_filetype; 
+    int b_index;
+    unsigned bufsize; 
+    int n_etypes_in_filetype;
+    ADIO_Offset size, n_filetypes, etype_in_filetype;
+    ADIO_Offset abs_off_in_filetype=0, 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;
@@ -44,6 +46,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
     MPI_Type_extent(buftype, &buftype_extent);
     etype_size = fd->etype_size;
 
+    ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
     bufsize = buftype_size * count;
 
     /* contiguous in buftype and filetype is handled elsewhere */
@@ -57,7 +60,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 	while (flat_buf->type != buftype) 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;
@@ -74,14 +77,16 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 	 */
         for (b_count=0; b_count < count; b_count++) {
             for (b_index=0; b_index < flat_buf->count; b_index++) {
-                userbuf_off = b_count*buftype_extent + 
+                userbuf_off = (ADIO_Offset)b_count*(ADIO_Offset)buftype_extent + 
 		              flat_buf->indices[b_index];
 		req_off = off;
 		req_len = flat_buf->blocklens[b_index];
 
+    ADIOI_Assert(req_len == (int) req_len);
+    ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + userbuf_off) == (ADIO_Offset)(unsigned long)(buf + userbuf_off));
 		ADIO_WriteContig(fd, 
 				(char *) buf + userbuf_off,
-				req_len, 
+				(int)req_len, 
 				MPI_BYTE, 
 		    		ADIO_EXPLICIT_OFFSET,
 				req_off,
@@ -105,7 +110,8 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
     }
 
     else {  /* noncontiguous in file */
-    	int f_index, st_fwr_size, st_index = 0, st_n_filetypes;
+    	int f_index, st_index = 0;
+      ADIO_Offset st_fwr_size, st_n_filetypes;
 	int flag;
 
         /* First we're going to calculate a set of values for use in all
@@ -135,15 +141,15 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
                 n_filetypes++;
 		for (f_index=0; f_index < flat_file->count; f_index++) {
 		    if (disp + flat_file->indices[f_index] + 
-                       (ADIO_Offset) n_filetypes*filetype_extent + 
+                       n_filetypes*(ADIO_Offset)filetype_extent + 
 		       flat_file->blocklens[f_index] >= start_off) 
 		    {
 		    	/* this block contains our starting position */
 
 			st_index = f_index;
-			fwr_size = (int) (disp + flat_file->indices[f_index] + 
-		 	           (ADIO_Offset) n_filetypes*filetype_extent + 
-				   flat_file->blocklens[f_index] - start_off);
+			fwr_size = disp + flat_file->indices[f_index] + 
+		 	           n_filetypes*(ADIO_Offset)filetype_extent + 
+				   flat_file->blocklens[f_index] - start_off;
 			flag = 1;
 			break;
 		    }
@@ -152,8 +158,8 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 	}
 	else {
 	    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;
@@ -170,7 +176,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 	    }
 
 	    /* abs. offset in bytes in the file */
-	    start_off = disp + (ADIO_Offset) n_filetypes*filetype_extent + 
+	    start_off = disp + n_filetypes*(ADIO_Offset)filetype_extent + 
 	    	        abs_off_in_filetype;
 	}
 
@@ -199,9 +205,9 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 	    }
 
 	    off = disp + flat_file->indices[f_index] + 
-	          (ADIO_Offset) n_filetypes*filetype_extent;
+	          n_filetypes*(ADIO_Offset)filetype_extent;
 	    fwr_size = ADIOI_MIN(flat_file->blocklens[f_index], 
-	                         bufsize-(int)userbuf_off);
+	                         bufsize-(unsigned)userbuf_off);
 	}
 
 	/* End of calculations.  At this point the following values have
@@ -239,9 +245,11 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 		    req_off = off;
 		    req_len = fwr_size;
 
+        ADIOI_Assert(req_len == (int) req_len);
+        ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + userbuf_off) == (ADIO_Offset)(unsigned long)(buf + userbuf_off));
 		    ADIO_WriteContig(fd, 
 				    (char *) buf + userbuf_off,
-				    req_len, 
+				    (int)req_len, 
 				    MPI_BYTE, 
 				    ADIO_EXPLICIT_OFFSET,
 				    req_off,
@@ -253,7 +261,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 
                 if (off + fwr_size < disp + flat_file->indices[f_index] +
                    flat_file->blocklens[f_index] + 
-		   (ADIO_Offset) n_filetypes*filetype_extent)
+		   n_filetypes*(ADIO_Offset)filetype_extent)
 		{
 		    /* important that this value be correct, as it is
 		     * used to set the offset in the fd near the end of
@@ -271,14 +279,14 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 			n_filetypes++;
 		    }
 		    off = disp + flat_file->indices[f_index] + 
-                          (ADIO_Offset) n_filetypes*filetype_extent;
+                          n_filetypes*(ADIO_Offset)filetype_extent;
 		    fwr_size = ADIOI_MIN(flat_file->blocklens[f_index], 
-		                         bufsize-(int)userbuf_off);
+		                         bufsize-(unsigned)userbuf_off);
 		}
 	    }
 	}
 	else {
-	    int i, tmp_bufsize = 0;
+	    ADIO_Offset i_offset, tmp_bufsize = 0;
 	    /* noncontiguous in memory as well as in file */
 
 	    ADIOI_Flatten_datatype(buftype);
@@ -286,7 +294,7 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 	    while (flat_buf->type != buftype) flat_buf = flat_buf->next;
 
 	    b_index = buf_count = 0;
-	    i = (int) (flat_buf->indices[0]);
+	    i_offset = flat_buf->indices[0];
 	    f_index = st_index;
 	    off = start_off;
 	    n_filetypes = st_n_filetypes;
@@ -295,17 +303,19 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 
 	    /* while we haven't read size * count bytes, keep going */
 	    while (tmp_bufsize < bufsize) {
-    		int new_bwr_size = bwr_size, new_fwr_size = fwr_size;
+    		ADIO_Offset new_bwr_size = bwr_size, new_fwr_size = fwr_size;
 
 		size = ADIOI_MIN(fwr_size, bwr_size);
 		if (size) {
 		    req_off = off;
 		    req_len = size;
-		    userbuf_off = i;
+		    userbuf_off = i_offset;
 
+        ADIOI_Assert(req_len == (int) req_len);
+        ADIOI_Assert((((ADIO_Offset)(unsigned long)buf) + userbuf_off) == (ADIO_Offset)(unsigned long)(buf + userbuf_off));
 		    ADIO_WriteContig(fd, 
 				    (char *) buf + userbuf_off,
-				    req_len, 
+				    (int)req_len, 
 				    MPI_BYTE, 
 				    ADIO_EXPLICIT_OFFSET,
 				    req_off,
@@ -323,11 +333,11 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 		    }
 
 		    off = disp + flat_file->indices[f_index] + 
-                          (ADIO_Offset) n_filetypes*filetype_extent;
+                          n_filetypes*(ADIO_Offset)filetype_extent;
 
 		    new_fwr_size = flat_file->blocklens[f_index];
 		    if (size != bwr_size) {
-			i += size;
+			i_offset += size;
 			new_bwr_size -= size;
 		    }
 		}
@@ -337,8 +347,8 @@ void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
 
 		    b_index = (b_index + 1)%flat_buf->count;
 		    buf_count++;
-		    i = (int) (buftype_extent*(buf_count/flat_buf->count) +
-			flat_buf->indices[b_index]);
+		    i_offset = (ADIO_Offset)buftype_extent*(ADIO_Offset)(buf_count/flat_buf->count) +
+			flat_buf->indices[b_index];
 		    new_bwr_size = flat_buf->blocklens[b_index];
 		    if (size != fwr_size) {
 			off += size;
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/byte_offset.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/byte_offset.c
index e23acf3..ce88cf1 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/byte_offset.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/byte_offset.c
@@ -14,10 +14,10 @@
 void ADIOI_Get_byte_offset(ADIO_File fd, ADIO_Offset offset, ADIO_Offset *disp)
 {
     ADIOI_Flatlist_node *flat_file;
-    int i, sum, n_etypes_in_filetype, size_in_filetype;
-    int n_filetypes, etype_in_filetype;
-    ADIO_Offset abs_off_in_filetype=0;
-    int filetype_size, etype_size, filetype_is_contig;
+    int i;
+    ADIO_Offset n_filetypes, etype_in_filetype, sum, abs_off_in_filetype=0, size_in_filetype;
+    unsigned n_etypes_in_filetype, filetype_size, etype_size;
+    int filetype_is_contig;
     MPI_Aint filetype_extent;
 
     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
@@ -29,10 +29,10 @@ void ADIOI_Get_byte_offset(ADIO_File fd, ADIO_Offset offset, ADIO_Offset *disp)
         flat_file = ADIOI_Flatlist;
         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
 
-	MPI_Type_size(fd->filetype, &filetype_size);
+	MPI_Type_size(fd->filetype, (int*)&filetype_size);
 	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;
@@ -47,6 +47,6 @@ void ADIOI_Get_byte_offset(ADIO_File fd, ADIO_Offset offset, ADIO_Offset *disp)
 
 	/* abs. offset in bytes in the file */
 	MPI_Type_extent(fd->filetype, &filetype_extent);
-	*disp = fd->disp + (ADIO_Offset) n_filetypes*filetype_extent + abs_off_in_filetype;
+	*disp = fd->disp + n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent + abs_off_in_filetype;
     }
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/eof_offset.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/eof_offset.c
index e8ddbd3..981efa0 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/eof_offset.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/eof_offset.c
@@ -13,9 +13,10 @@
 
 void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset *eof_offset)
 {
-    int error_code, filetype_is_contig, etype_size, filetype_size;
-    ADIO_Offset fsize, disp, sum=0, size_in_file;
-    int n_filetypes, flag, i, rem;
+    unsigned filetype_size;
+    int error_code, filetype_is_contig, etype_size;
+    ADIO_Offset fsize, disp, sum=0, size_in_file, n_filetypes, rem;
+    int flag, i;
     ADIO_Fcntl_t *fcntl_struct;
     MPI_Aint filetype_extent;
     ADIOI_Flatlist_node *flat_file;
@@ -43,7 +44,7 @@ void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset *eof_offset)
 	while (flat_file->type != fd->filetype) 
 	    flat_file = flat_file->next;
 	
-	MPI_Type_size(fd->filetype, &filetype_size);
+	MPI_Type_size(fd->filetype, (int*)&filetype_size);
 	MPI_Type_extent(fd->filetype, &filetype_extent);
 
 	disp = fd->disp;
@@ -55,14 +56,14 @@ void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset *eof_offset)
 	    for (i=0; i<flat_file->count; i++) {
 		sum += flat_file->blocklens[i];
 		if (disp + flat_file->indices[i] + 
-		    (ADIO_Offset) n_filetypes*filetype_extent + 
+		    n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent + 
 		       flat_file->blocklens[i] >= fsize) {
 		    if (disp + flat_file->indices[i] + 
-			   (ADIO_Offset) n_filetypes*filetype_extent >= fsize)
+			   n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent >= fsize)
 			sum -= flat_file->blocklens[i];
 		    else {
-			rem = (int) (disp + flat_file->indices[i] + 
-				(ADIO_Offset) n_filetypes*filetype_extent
+			rem = (disp + flat_file->indices[i] + 
+				n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent
 				+ flat_file->blocklens[i] - fsize);
 			sum -= rem;
 		    }
@@ -71,7 +72,7 @@ void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset *eof_offset)
 		}
 	    }
 	}
-	size_in_file = (ADIO_Offset) n_filetypes*filetype_size + sum;
+	size_in_file = n_filetypes*(ADIO_Offset)filetype_size + sum;
 	*eof_offset = (size_in_file+etype_size-1)/etype_size; /* ceiling division */
     }
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/flatten.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/flatten.c
index a092eaf..ecc1de6 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/flatten.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/flatten.c
@@ -19,12 +19,13 @@
 #endif
 
 void ADIOI_Optimize_flattened(ADIOI_Flatlist_node *flat_type);
+#if 0 /* unused function ADIOI_Flatten_copy_type()*/
 void ADIOI_Flatten_copy_type(ADIOI_Flatlist_node *flat,
 			     int old_type_start,
 			     int old_type_end,
 			     int new_type_start,
 			     ADIO_Offset offset_adjustment);
-
+#endif /* unused function ADIOI_Flatten_copy_type()*/
 /* flatten datatype and add it to Flatlist */
 void ADIOI_Flatten_datatype(MPI_Datatype datatype)
 {
@@ -118,14 +119,20 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 		  ADIO_Offset st_offset, int *curr_index)  
 {
     int i, j, k, m, n, num, basic_num, prev_index;
-    int top_count, combiner, old_combiner, old_is_contig;
-    int old_size, nints, nadds, ntypes, old_nints, old_nadds, old_ntypes;
-    MPI_Aint old_extent;
+    int combiner, old_combiner, old_is_contig;
+    int nints, nadds, ntypes, old_nints, old_nadds, old_ntypes;
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset top_count;
+    /* By using unsigned we avoid >2G integer arithmetic problems */
+    unsigned old_size;
+    MPI_Aint old_extent;/* Assume extents are non-negative */
     int *ints;
-    MPI_Aint *adds; 
+    MPI_Aint *adds; /* Make no assumptions about +/- sign on these */
     MPI_Datatype *types;
   #ifdef FLATTEN_DEBUG 
   DBG_FPRINTF(stderr,"ADIOI_Flatten:: st_offset %#llX, curr_index %#X\n",st_offset,*curr_index);
+  if(MPIU_DBG_SELECTED(DATATYPE,TYPICAL)) MPIDU_Datatype_debug(datatype, 4); /* use -env MPICH_DBG_OUTPUT=stdout */
   #endif
 
     MPI_Type_get_envelope(datatype, &nints, &nadds, &ntypes, &combiner);
@@ -220,7 +227,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 /* simplest case, made up of basic or contiguous types */
 	    j = *curr_index;
 	    flat->indices[j] = st_offset;
-	    MPI_Type_size(types[0], &old_size);
+	    MPI_Type_size(types[0], (int*)&old_size);
 	    flat->blocklens[j] = top_count * old_size;
       #ifdef FLATTEN_DEBUG 
       DBG_FPRINTF(stderr,"ADIOI_Flatten:: simple flat->indices[%#X] %#llX, flat->blocklens[%#X] %#llX\n",j, flat->indices[j], j, flat->blocklens[j]);
@@ -236,7 +243,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 	    MPI_Type_extent(types[0], &old_extent);
 	    for (m=1; m<top_count; m++) {
 		for (i=0; i<num; i++) {
-		    flat->indices[j] = flat->indices[j-num] + old_extent;
+		    flat->indices[j] = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
           #ifdef FLATTEN_DEBUG 
           DBG_FPRINTF(stderr,"ADIOI_Flatten:: derived flat->indices[%#X] %#llX, flat->blocklens[%#X] %#llX\n",j, flat->indices[j], j, flat->blocklens[j]);
@@ -263,19 +270,24 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 
 	if (prev_index == *curr_index) {
 /* simplest case, vector of basic or contiguous types */
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset blocklength = ints[1], stride = ints[2];
 	    j = *curr_index;
 	    flat->indices[j] = st_offset;
-	    MPI_Type_size(types[0], &old_size);
-	    flat->blocklens[j] = ints[1] * old_size;
+	    MPI_Type_size(types[0], (int*)&old_size);
+	    flat->blocklens[j] = blocklength * old_size;
 	    for (i=j+1; i<j+top_count; i++) {
-		flat->indices[i] = flat->indices[i-1] + 
-		    (unsigned) ints[2] * (unsigned) old_size; // TODO MPI_Aint
+		flat->indices[i] = flat->indices[i-1] + stride * old_size;
 		flat->blocklens[i] = flat->blocklens[j];
 	    }
 	    *curr_index = i;
 	}
 	else {
 /* vector of noncontiguous derived types */
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset blocklength = ints[1], stride = ints[2];
 
 	    j = *curr_index;
 	    num = *curr_index - prev_index;
@@ -283,9 +295,9 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 /* The noncontiguous types have to be replicated blocklen times
    and then strided. Replicate the first one. */
 	    MPI_Type_extent(types[0], &old_extent);
-	    for (m=1; m<ints[1]; m++) {
+	    for (m=1; m<blocklength; m++) {
 		for (i=0; i<num; i++) {
-		    flat->indices[j] = flat->indices[j-num] + old_extent;
+		    flat->indices[j] = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
@@ -296,8 +308,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 	    num = *curr_index - prev_index;
 	    for (i=1; i<top_count; i++) {
  		for (m=0; m<num; m++) {
-		   flat->indices[j] =  flat->indices[j-num] + ints[2]
-		       *old_extent;
+		   flat->indices[j] =  flat->indices[j-num] + stride * ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		   flat->blocklens[j] = flat->blocklens[j-num];
 		   j++;
 		}
@@ -322,10 +333,13 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 
 	if (prev_index == *curr_index) {
 /* simplest case, vector of basic or contiguous types */
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset blocklength = ints[1];
 	    j = *curr_index;
 	    flat->indices[j] = st_offset;
-	    MPI_Type_size(types[0], &old_size);
-	    flat->blocklens[j] = ints[1] * old_size;
+	    MPI_Type_size(types[0], (int*)&old_size);
+	    flat->blocklens[j] = blocklength * old_size;
 	    for (i=j+1; i<j+top_count; i++) {
 		flat->indices[i] = flat->indices[i-1] + adds[0];
 		flat->blocklens[i] = flat->blocklens[j];
@@ -334,6 +348,9 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 	}
 	else {
 /* vector of noncontiguous derived types */
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset blocklength = ints[1];
 
 	    j = *curr_index;
 	    num = *curr_index - prev_index;
@@ -341,9 +358,9 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 /* The noncontiguous types have to be replicated blocklen times
    and then strided. Replicate the first one. */
 	    MPI_Type_extent(types[0], &old_extent);
-	    for (m=1; m<ints[1]; m++) {
+	    for (m=1; m<blocklength; m++) {
 		for (i=0; i<num; i++) {
-		    flat->indices[j] = flat->indices[j-num] + old_extent;
+		    flat->indices[j] = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
@@ -375,15 +392,23 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 
 	prev_index = *curr_index;
 	if ((old_combiner != MPI_COMBINER_NAMED) && (!old_is_contig))
-	    ADIOI_Flatten(types[0], flat,
-			 st_offset+ints[top_count+1]*old_extent, curr_index);
+  {
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset stride = ints[top_count+1];
+        ADIOI_Flatten(types[0], flat,
+         st_offset+stride* ADIOI_AINT_CAST_TO_OFFSET old_extent, curr_index);
+  }
 
 	if (prev_index == *curr_index) {
 /* simplest case, indexed type made up of basic or contiguous types */
 	    j = *curr_index;
 	    for (i=j; i<j+top_count; i++) {
-		flat->indices[i] = st_offset + ints[top_count+1+i-j]*old_extent;
-		flat->blocklens[i] = (int) (ints[1+i-j]*old_extent);
+    /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+    ADIO_Offset blocklength = ints[1+i-j], stride = ints[top_count+1+i-j];
+		flat->indices[i] = st_offset + stride* ADIOI_AINT_CAST_TO_OFFSET old_extent;
+		flat->blocklens[i] = blocklength* ADIOI_AINT_CAST_TO_OFFSET old_extent;
 	    }
 	    *curr_index = i;
 	}
@@ -398,7 +423,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
    and then strided. Replicate the first one. */
 	    for (m=1; m<ints[1]; m++) {
 		for (i=0; i<num; i++) {
-		    flat->indices[j] = flat->indices[j-num] + old_extent;
+		    flat->indices[j] = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
@@ -410,15 +435,17 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 		num = *curr_index - prev_index;
 		prev_index = *curr_index;
 		for (m=0; m<basic_num; m++) {
-		    flat->indices[j] = flat->indices[j-num] + 
-                        (ints[top_count+1+i]-ints[top_count+i])*old_extent;
+      /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+      ADIO_Offset stride = ints[top_count+1+i]-ints[top_count+i];
+		    flat->indices[j] = flat->indices[j-num] + stride* ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
 		*curr_index = j;
 		for (m=1; m<ints[1+i]; m++) {
                     for (k=0; k<basic_num; k++) {
-                        flat->indices[j] = flat->indices[j-basic_num] + old_extent;
+                        flat->indices[j] = flat->indices[j-basic_num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
                         flat->blocklens[j] = flat->blocklens[j-basic_num];
                         j++;
                     }
@@ -440,15 +467,23 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 
 	prev_index = *curr_index;
 	if ((old_combiner != MPI_COMBINER_NAMED) && (!old_is_contig))
-	    ADIOI_Flatten(types[0], flat,
-			 st_offset+ints[1+1]*old_extent, curr_index);
+  {
+      /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+      ADIO_Offset stride = ints[1+1];
+        ADIOI_Flatten(types[0], flat,
+         st_offset+stride* ADIOI_AINT_CAST_TO_OFFSET old_extent, curr_index);
+  }
 
 	if (prev_index == *curr_index) {
 /* simplest case, indexed type made up of basic or contiguous types */
 	    j = *curr_index;
 	    for (i=j; i<j+top_count; i++) {
-		flat->indices[i]   = st_offset + ints[1+1+i-j]*old_extent;
-		flat->blocklens[i] = (int) (ints[1]*old_extent);
+      /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+      ADIO_Offset blocklength = ints[1], stride = ints[1+1+i-j];
+		flat->indices[i]   = st_offset + stride* ADIOI_AINT_CAST_TO_OFFSET old_extent;
+		flat->blocklens[i] = blocklength* ADIOI_AINT_CAST_TO_OFFSET old_extent;
 	    }
 	    *curr_index = i;
 	}
@@ -462,7 +497,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
    and then strided. Replicate the first one. */
 	    for (m=1; m<ints[1]; m++) {
 		for (i=0; i<num; i++) {
-		    flat->indices[j]   = flat->indices[j-num] + old_extent;
+		    flat->indices[j]   = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
@@ -473,7 +508,10 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 	    num = *curr_index - prev_index;
 	    for (i=1; i<top_count; i++) {
 		for (m=0; m<num; m++) {
-		    flat->indices[j]   = flat->indices[j-num] + (ints[2+i]-ints[1+i])*old_extent;
+      /* By using ADIO_Offset we preserve +/- sign and 
+         avoid >2G integer arithmetic problems */
+      ADIO_Offset stride = ints[2+i]-ints[1+i];
+		    flat->indices[j]   = flat->indices[j-num] + stride* ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
@@ -494,15 +532,20 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 
 	prev_index = *curr_index;
 	if ((old_combiner != MPI_COMBINER_NAMED) && (!old_is_contig))
-	    ADIOI_Flatten(types[0], flat, st_offset+adds[0], curr_index); 
+  {
+        ADIOI_Flatten(types[0], flat, st_offset+adds[0], curr_index); 
+  }
 
 	if (prev_index == *curr_index) {
 /* simplest case, indexed type made up of basic or contiguous types */
 	    j = *curr_index;
-	    MPI_Type_size(types[0], &old_size);
+	    MPI_Type_size(types[0], (int*)&old_size);
 	    for (i=j; i<j+top_count; i++) {
+        /* By using ADIO_Offset we preserve +/- sign and 
+           avoid >2G integer arithmetic problems */
+        ADIO_Offset blocklength = ints[1+i-j];
 		flat->indices[i] = st_offset + adds[i-j];
-		flat->blocklens[i] = ints[1+i-j]*old_size;
+		flat->blocklens[i] = blocklength*old_size;
 	    }
 	    *curr_index = i;
 	}
@@ -518,7 +561,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 	    MPI_Type_extent(types[0], &old_extent);
 	    for (m=1; m<ints[1]; m++) {
 		for (i=0; i<num; i++) {
-		    flat->indices[j] = flat->indices[j-num] + old_extent;
+		    flat->indices[j] = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 		    flat->blocklens[j] = flat->blocklens[j-num];
 		    j++;
 		}
@@ -537,7 +580,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 		*curr_index = j;
 		for (m=1; m<ints[1+i]; m++) {
                     for (k=0; k<basic_num; k++) {
-                        flat->indices[j] = flat->indices[j-basic_num] + old_extent;
+                        flat->indices[j] = flat->indices[j-basic_num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
                         flat->blocklens[j] = flat->blocklens[j-basic_num];
 		    j++;
                     }
@@ -564,10 +607,13 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 
 	    if (prev_index == *curr_index) {
 /* simplest case, current type is basic or contiguous types */
+        /* By using ADIO_Offset we preserve +/- sign and 
+           avoid >2G integer arithmetic problems */
+        ADIO_Offset blocklength = ints[1+n];
 		j = *curr_index;
 		flat->indices[j] = st_offset + adds[n];
-		MPI_Type_size(types[n], &old_size);
-		flat->blocklens[j] = ints[1+n] * old_size;
+		MPI_Type_size(types[n], (int*)&old_size);
+		flat->blocklens[j] = blocklength * old_size;
         #ifdef FLATTEN_DEBUG 
         DBG_FPRINTF(stderr,"ADIOI_Flatten:: simple adds[%#X} "MPI_AINT_FMT_HEX_SPEC", flat->indices[%#X] %#llX, flat->blocklens[%#X] %#llX\n",n,adds[n],j, flat->indices[j], j, flat->blocklens[j]);
         #endif
@@ -583,7 +629,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
 		MPI_Type_extent(types[n], &old_extent);
 		for (m=1; m<ints[1+n]; m++) {
 		    for (i=0; i<num; i++) {
-			flat->indices[j] = flat->indices[j-num] + old_extent;
+			flat->indices[j] = flat->indices[j-num] + ADIOI_AINT_CAST_TO_OFFSET old_extent;
 			flat->blocklens[j] = flat->blocklens[j-num];
             #ifdef FLATTEN_DEBUG 
             DBG_FPRINTF(stderr,"ADIOI_Flatten:: simple old_extent "MPI_AINT_FMT_HEX_SPEC", flat->indices[%#X] %#llX, flat->blocklens[%#X] %#llX\n",old_extent,j, flat->indices[j], j, flat->blocklens[j]);
@@ -644,7 +690,7 @@ int ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, int *curr_index)
     int top_count, combiner, old_combiner, old_is_contig;
     int nints, nadds, ntypes, old_nints, old_nadds, old_ntypes;
     int *ints;
-    MPI_Aint *adds;
+    MPI_Aint *adds; /* Make no assumptions about +/- sign on these */
     MPI_Datatype *types;
 
     MPI_Type_get_envelope(datatype, &nints, &nadds, &ntypes, &combiner);
@@ -960,7 +1006,7 @@ void ADIOI_Delete_flattened(MPI_Datatype datatype)
 	ADIOI_Free(flat);
     }
 }
-
+#if 0 /* unused function ADIOI_Flatten_copy_type()*/
 /* ADIOI_Flatten_copy_type()
  * flat - pointer to flatlist node holding offset and lengths
  * start - starting index of src type in arrays
@@ -982,4 +1028,4 @@ void ADIOI_Flatten_copy_type(ADIOI_Flatlist_node *flat,
 	out_index++;
     }
 }
-
+#endif /* unused function ADIOI_Flatten_copy_type()*/
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/get_fp_posn.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/get_fp_posn.c
index a5a422a..1d7cab8 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/get_fp_posn.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/get_fp_posn.c
@@ -7,6 +7,7 @@
 
 #include "adio.h"
 #include "adio_extern.h"
+#include "adioi.h"
 
 /* returns the current position of the individual file pointer
    in etype units relative to the current view. */
@@ -14,10 +15,11 @@
 void ADIOI_Get_position(ADIO_File fd, ADIO_Offset *offset)
 {
     ADIOI_Flatlist_node *flat_file;
-    int i, n_filetypes, flag, frd_size;
-    int filetype_size, etype_size, filetype_is_contig;
+    int i, flag;
+    unsigned filetype_size;
+    int etype_size, filetype_is_contig;
     MPI_Aint filetype_extent;
-    ADIO_Offset disp, byte_offset, sum=0, size_in_file;
+    ADIO_Offset disp, byte_offset, sum=0, size_in_file, n_filetypes, frd_size;
     
     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
     etype_size = fd->etype_size;
@@ -28,7 +30,7 @@ void ADIOI_Get_position(ADIO_File fd, ADIO_Offset *offset)
         flat_file = ADIOI_Flatlist;
         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
 
-	MPI_Type_size(fd->filetype, &filetype_size);
+	MPI_Type_size(fd->filetype, (int*)&filetype_size);
 	MPI_Type_extent(fd->filetype, &filetype_extent);
 
 	disp = fd->disp;
@@ -41,18 +43,18 @@ void ADIOI_Get_position(ADIO_File fd, ADIO_Offset *offset)
 	    for (i=0; i<flat_file->count; i++) {
 		sum += flat_file->blocklens[i];
 		if (disp + flat_file->indices[i] + 
-	     	    (ADIO_Offset) n_filetypes*filetype_extent + flat_file->blocklens[i] 
+	     	    n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent + flat_file->blocklens[i] 
 		    >= byte_offset) {
-		    frd_size = (int) (disp + flat_file->indices[i] + 
-			(ADIO_Offset) n_filetypes*filetype_extent
-			+ flat_file->blocklens[i] - byte_offset);
+		    frd_size = disp + flat_file->indices[i] + 
+			n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent
+			+ flat_file->blocklens[i] - byte_offset;
 		    sum -= frd_size;
 		    flag = 1;
 		    break;
 		}
 	    }
 	}
-	size_in_file = (ADIO_Offset) n_filetypes*filetype_size + sum;
+	size_in_file = n_filetypes * (ADIO_Offset)filetype_size + sum;
 	*offset = size_in_file/etype_size;
     }
 }
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/common/lock.c b/lib/mpi/mpich2/src/mpi/romio/adio/common/lock.c
index 5e83a1a..4ebc922 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/common/lock.c
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/common/lock.c
@@ -128,7 +128,7 @@ int ADIOI_Set_lock(FDTYPE fd, int cmd, int type, ADIO_Offset offset, int whence,
     if (err && (errno != EBADF)) {
 	/* FIXME: This should use the error message system, 
 	   especially for MPICH2 */
-	fprintf(stderr, "File locking failed in ADIOI_Set_lock(fd %X,cmd %s/%X,type %s/%X,whence %X) with return value %X and errno %X.\n"
+	fprintf(stderr, "File locking failed in ADIOI_Set_lock(fd %#X,cmd %s/%#X,type %s/%#X,whence %#X) with return value %#X and errno %#X.\n"
                   "If the file system is NFS, you need to use NFS version 3, ensure that the lockd daemon is running on all the machines, and mount the directory with the 'noac' option (no attribute caching).\n",
           fd,
           ((cmd == F_GETLK   )? "F_GETLK" :
@@ -173,7 +173,7 @@ int ADIOI_Set_lock64(FDTYPE fd, int cmd, int type, ADIO_Offset offset,
     } while (err && (errno == EINTR));
 
     if (err && (errno != EBADF)) {
-	fprintf(stderr, "File locking failed in ADIOI_Set_lock64(fd %X,cmd %s/%X,type %s/%X,whence %X) with return value %X and errno %X.\n"
+	fprintf(stderr, "File locking failed in ADIOI_Set_lock64(fd %#X,cmd %s/%#X,type %s/%#X,whence %#X) with return value %#X and errno %#X.\n"
                   "If the file system is NFS, you need to use NFS version 3, ensure that the lockd daemon is running on all the machines, and mount the directory with the 'noac' option (no attribute caching).\n",
           fd,
           ((cmd == F_GETLK   )? "F_GETLK" :
diff --git a/lib/mpi/mpich2/src/mpi/romio/adio/include/adioi.h b/lib/mpi/mpich2/src/mpi/romio/adio/include/adioi.h
index 6a16fb2..68c328f 100644
--- a/lib/mpi/mpich2/src/mpi/romio/adio/include/adioi.h
+++ b/lib/mpi/mpich2/src/mpi/romio/adio/include/adioi.h
@@ -274,7 +274,9 @@ struct ADIOI_Fns_struct {
    as array of structures indexed by process number. */
 typedef struct {
     ADIO_Offset *offsets;   /* array of offsets */
-    int *lens;              /* array of lengths */
+    int *lens;              /* array of lengths */ 
+    /* consider aints or offsets for lens? Seems to be used as in-memory
+       buffer lengths, so it should be < 2G and ok as an int          */
     MPI_Aint *mem_ptrs;     /* array of pointers. used in the read/write
 			       phase to indicate where the data
 			       is stored in memory */
@@ -370,7 +372,7 @@ void ADIOI_GEN_WriteStridedColl(ADIO_File fd, void *buf, int count,
                        *error_code);
 void ADIOI_Calc_my_off_len(ADIO_File fd, int bufcount, MPI_Datatype
 			    datatype, int file_ptr_type, ADIO_Offset 
-			    offset, ADIO_Offset **offset_list_ptr, int
+			    offset, ADIO_Offset **offset_list_ptr, ADIO_Offset
 			    **len_list_ptr, ADIO_Offset *start_offset_ptr,
 			    ADIO_Offset *end_offset_ptr, int
 			   *contig_access_count_ptr);
@@ -387,7 +389,7 @@ int ADIOI_Calc_aggregator(ADIO_File fd,
                                  ADIO_Offset *fd_start,
                                  ADIO_Offset *fd_end);
 void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, 
-			    int *len_list, int
+			    ADIO_Offset *len_list, int
 			    contig_access_count, ADIO_Offset 
 			    min_st_offset, ADIO_Offset *fd_start,
 			    ADIO_Offset *fd_end, ADIO_Offset fd_size,
@@ -654,11 +656,20 @@ int  ADIOI_MPE_postwrite_b;
   #include "mpiimpl.h"
 
   #define ADIOI_AINT_CAST_TO_VOID_PTR MPI_AINT_CAST_TO_VOID_PTR
+  /* The next two casts are only used when you don't want sign extension
+     when casting a (possible 4 byte) aint to a (8 byte) long long or offset */
+  #define ADIOI_AINT_CAST_TO_LONG_LONG MPI_AINT_CAST_TO_LONG_LONG
+  #define ADIOI_AINT_CAST_TO_OFFSET ADIOI_AINT_CAST_TO_LONG_LONG
+
   #define ADIOI_ENSURE_AINT_FITS_IN_PTR(aint_value) MPID_Ensure_Aint_fits_in_pointer(aint_value)
+  #define ADIOI_Assert MPIU_Assert
 #else
   #include <assert.h>
   #define ADIOI_AINT_CAST_TO_VOID_PTR (void*)
+  #define ADIOI_AINT_CAST_TO_LONG_LONG (long long*)
+  #define ADIOI_AINT_CAST_TO_OFFSET ADIOI_AINT_CAST_TO_LONG_LONG
   #define ADIOI_ENSURE_AINT_FITS_IN_PTR(aint_value) 
+  #define ADIOI_Assert assert
 #endif
 
 #ifdef USE_DBG_LOGGING    /*todo fix dependency on mpich?*/
-- 
1.5.3.7




More information about the mpich2-dev mailing list