[mpich2-dev] [PATCH 1/1] Issue 4120: MPI_Aint changes to MPICH2 datatype modules Part 2

Jeff Parker jjparker at us.ibm.com
Tue Mar 18 10:51:26 CDT 2008


This is part 2 of the MPI_Aint changes to MPICH2 datatype modules.
They largely involve casting calculations involving mixed MPI_Aint and int datatypes.
Also, using the configurable printf format specs for printing MPI_Aint variables.

Signed-off-by: Jeff Parker <jjparker at us.ibm.com>
---
 .../mpich2/src/mpi/datatype/type_create_darray.c   |   26 +++---
 .../mpich2/src/mpi/datatype/type_create_subarray.c |   26 +++---
 .../mpid/common/datatype/dataloop/darray_support.c |   24 +++---
 .../src/mpid/common/datatype/dataloop/dataloop.c   |   89 +++++++++++--------
 .../dataloop/dataloop_create_blockindexed.c        |    2 +-
 .../datatype/dataloop/dataloop_create_indexed.c    |    8 +-
 .../datatype/dataloop/dataloop_create_pairtype.c   |    2 +-
 .../datatype/dataloop/dataloop_create_struct.c     |    4 +-
 .../src/mpid/common/datatype/dataloop/segment.c    |   50 ++++++------
 .../mpid/common/datatype/dataloop/segment_ops.c    |   88 ++++++++++---------
 .../common/datatype/dataloop/subarray_support.c    |   22 +++---
 .../src/mpid/common/datatype/dataloop/veccpy.h     |   14 ++-
 .../mpich2/src/mpid/common/datatype/mpid_segment.c |   74 ++++++++--------
 .../mpid/common/datatype/mpid_type_blockindexed.c  |   19 +++--
 .../mpid/common/datatype/mpid_type_contiguous.c    |    2 +-
 .../common/datatype/mpid_type_create_pairtype.c    |    8 +-
 .../src/mpid/common/datatype/mpid_type_debug.c     |   92 ++++++++++----------
 .../src/mpid/common/datatype/mpid_type_indexed.c   |   22 +++--
 .../src/mpid/common/datatype/mpid_type_struct.c    |   21 +++--
 .../src/mpid/common/datatype/mpid_type_vector.c    |   13 ++--
 .../src/mpid/dcmf/src/onesided/mpid_rma_common.c   |    3 +-
 21 files changed, 323 insertions(+), 286 deletions(-)

diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_create_darray.c b/lib/mpi/mpich2/src/mpi/datatype/type_create_darray.c
index c27174b..ae98321 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_create_darray.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_create_darray.c
@@ -123,7 +123,7 @@ PMPI_LOCAL int MPIR_Type_block(int *array_of_gsizes,
 	    /* --END ERROR HANDLING-- */
 	}
 	else {
-	    for (i=0; i<dim; i++) stride *= array_of_gsizes[i];
+	    for (i=0; i<dim; i++) stride *= (MPI_Aint)(unsigned long)(array_of_gsizes[i]);
 	    mpi_errno = MPID_Type_vector(mysize,
 					 1,
 					 stride,
@@ -153,7 +153,7 @@ PMPI_LOCAL int MPIR_Type_block(int *array_of_gsizes,
 	    /* --END ERROR HANDLING-- */
 	}
 	else {
-	    for (i=ndims-1; i>dim; i--) stride *= array_of_gsizes[i];
+	    for (i=ndims-1; i>dim; i--) stride *= (MPI_Aint)(unsigned long)(array_of_gsizes[i]);
 	    mpi_errno = MPID_Type_vector(mysize,
 					 1,
 					 stride,
@@ -170,7 +170,7 @@ PMPI_LOCAL int MPIR_Type_block(int *array_of_gsizes,
 	}
     }
 
-    *st_offset = blksize * rank;
+    *st_offset = (MPI_Aint)(unsigned long)blksize * (MPI_Aint)(unsigned long)rank;
      /* in terms of no. of elements of type oldtype in this dimension */
     if (mysize == 0) *st_offset = 0;
 
@@ -231,10 +231,10 @@ PMPI_LOCAL int MPIR_Type_cyclic(int *array_of_gsizes,
     count = local_size/blksize;
     rem = local_size % blksize;
     
-    stride = nprocs*blksize*orig_extent;
+    stride = (MPI_Aint)(unsigned long)nprocs * (MPI_Aint)(unsigned long)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)(unsigned long)(array_of_gsizes[i]);
+    else for (i=ndims-1; i>dim; i--) stride *= (MPI_Aint)(unsigned long)(array_of_gsizes[i]);
 
     mpi_errno = MPID_Type_vector(count,
 				 blksize,
@@ -257,7 +257,7 @@ PMPI_LOCAL int MPIR_Type_cyclic(int *array_of_gsizes,
 	types[0] = *type_new;
 	types[1] = type_old;
 	disps[0] = 0;
-	disps[1] = count*stride;
+	disps[1] = (MPI_Aint)(unsigned long)count * stride;
 	blklens[0] = 1;
 	blklens[1] = rem;
 
@@ -288,9 +288,9 @@ PMPI_LOCAL int MPIR_Type_cyclic(int *array_of_gsizes,
         types[0] = MPI_LB;
         disps[0] = 0;
         types[1] = *type_new;
-        disps[1] = rank * blksize * orig_extent;
+        disps[1] = (MPI_Aint)(unsigned long)rank * (MPI_Aint)(unsigned long)blksize * orig_extent;
         types[2] = MPI_UB;
-        disps[2] = orig_extent * array_of_gsizes[dim];
+        disps[2] = orig_extent * (MPI_Aint)(unsigned long)(array_of_gsizes[dim]);
         blklens[0] = blklens[1] = blklens[2] = 1;
         mpi_errno = MPID_Type_struct(3,
 				     blklens,
@@ -314,7 +314,7 @@ PMPI_LOCAL int MPIR_Type_cyclic(int *array_of_gsizes,
                             the struct above */
     }
     else {
-        *st_offset = rank * blksize; 
+        *st_offset = (MPI_Aint)(unsigned long)rank * (MPI_Aint)(unsigned long)blksize; 
         /* st_offset is in terms of no. of elements of type oldtype in
          * this dimension */ 
     }
@@ -591,7 +591,7 @@ int MPI_Type_create_darray(int size,
 	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)(unsigned long)tmp_size * st_offsets[i];
 	}
         /* rest done below for both Fortran and C order */
     }
@@ -659,14 +659,14 @@ int MPI_Type_create_darray(int size,
 	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)(unsigned long)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)(unsigned long)(array_of_gsizes[i]);
 	
     disps[0] = 0;
     blklens[0] = blklens[1] = blklens[2] = 1;
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_create_subarray.c b/lib/mpi/mpich2/src/mpi/datatype/type_create_subarray.c
index 460a6b6..1c3efc0 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_create_subarray.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_create_subarray.c
@@ -194,14 +194,14 @@ int MPI_Type_create_subarray(int ndims,
 	else {
 	    mpi_errno = MPID_Type_vector(array_of_subsizes[1],
 					 array_of_subsizes[0],
-					 array_of_sizes[0],
+					 (MPI_Aint)(unsigned long)(array_of_sizes[0]),
 					 0, /* stride in types */
 					 oldtype,
 					 &tmp1);
 	    
-	    size = array_of_sizes[0]*extent;
+	    size = ((MPI_Aint)(unsigned long)array_of_sizes[0]) * extent;
 	    for (i=2; i<ndims; i++) {
-		size *= array_of_sizes[i-1];
+		size *= (MPI_Aint)(unsigned long)(array_of_sizes[i-1]);
 		mpi_errno = MPID_Type_vector(array_of_subsizes[i],
 					     1,
 					     size,
@@ -215,11 +215,11 @@ int MPI_Type_create_subarray(int ndims,
 	
 	/* add displacement and UB */
 	
-	disps[1] = array_of_starts[0];
+	disps[1] = (MPI_Aint)(unsigned long)(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)(unsigned long)(array_of_sizes[i-1]);
+	    disps[1] += size * (MPI_Aint)(unsigned long)(array_of_starts[i]);
 	}  
         /* rest done below for both Fortran and C order */
     }
@@ -234,15 +234,15 @@ int MPI_Type_create_subarray(int ndims,
 	else {
 	    mpi_errno = MPID_Type_vector(array_of_subsizes[ndims-2],
 					 array_of_subsizes[ndims-1],
-					 array_of_sizes[ndims-1],
+					 (MPI_Aint)(unsigned long)(array_of_sizes[ndims-1]),
 					 0, /* stride in types */
 					 oldtype,
 					 &tmp1);
 	    
 
-	    size = array_of_sizes[ndims-1]*extent;
+	    size = (MPI_Aint)(unsigned long)(array_of_sizes[ndims-1]) * extent;
 	    for (i=ndims-3; i>=0; i--) {
-		size *= array_of_sizes[i+1];
+		size *= (MPI_Aint)(unsigned long)(array_of_sizes[i+1]);
 		mpi_errno = MPID_Type_vector(array_of_subsizes[i],
 					     1,    /* blocklen */
 					     size, /* stride */
@@ -257,18 +257,18 @@ int MPI_Type_create_subarray(int ndims,
 	
 	/* add displacement and UB */
 	
-	disps[1] = array_of_starts[ndims-1];
+	disps[1] = (MPI_Aint)(unsigned long)(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)(unsigned long)(array_of_sizes[i+1]);
+	    disps[1] += size * (MPI_Aint)(unsigned long)(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)(unsigned long)(array_of_sizes[i]);
     
     disps[0] = 0;
     blklens[0] = blklens[1] = blklens[2] = 1;
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/darray_support.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/darray_support.c
index da1270a..0cce041 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/darray_support.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/darray_support.c
@@ -87,7 +87,7 @@ int PREPEND_PREFIX(Type_convert_darray)(int size,
 	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 */
     }
@@ -125,14 +125,14 @@ int PREPEND_PREFIX(Type_convert_darray)(int size,
 	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;
@@ -189,7 +189,7 @@ static int MPIOI_Type_block(int *array_of_gsizes, int dim, int ndims, int nprocs
 	if (dim == 0) 
 	    PMPI_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]);
 	    PMPI_Type_hvector(mysize, 1, stride, type_old, type_new);
 	}
     }
@@ -197,7 +197,7 @@ static int MPIOI_Type_block(int *array_of_gsizes, int dim, int ndims, int nprocs
 	if (dim == ndims-1) 
 	    PMPI_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]);
 	    PMPI_Type_hvector(mysize, 1, stride, type_old, type_new);
 	}
 
@@ -247,10 +247,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]);
 
     PMPI_Type_hvector(count, blksize, stride, type_old, type_new);
 
@@ -261,7 +261,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;
 
@@ -278,9 +278,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;
         PMPI_Type_struct(3, blklens, disps, types, &type_tmp);
         PMPI_Type_free(type_new);
@@ -290,7 +290,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/mpid/common/datatype/dataloop/dataloop.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c
index 411b47e..cf8ad79 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop.c
@@ -114,7 +114,7 @@ void PREPEND_PREFIX(Dataloop_copy)(void *dest,
      * adding this difference to them. This way we can just copy the
      * structure, including pointers, in one big block.
      */
-    ptrdiff = (char *) dest - (char *) src;
+    ptrdiff = MPI_VOID_PTR_CAST_TO_MPI_AINT ( (char *) dest - (char *) src );
 
     /* traverse structure updating pointers */
     PREPEND_PREFIX(Dataloop_update)(dest, ptrdiff);
@@ -152,48 +152,57 @@ void PREPEND_PREFIX(Dataloop_update)(DLOOP_Dataloop *dataloop,
 	     * LHS, so we get this much nastier form instead (using common
 	     * struct for contig and vector): 
 	     */
-	    dataloop->loop_params.cm_t.dataloop = (DLOOP_Dataloop *) 
-		((char *) dataloop->loop_params.cm_t.dataloop + ptrdiff);
+	    dataloop->loop_params.cm_t.dataloop = 
+		(DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.cm_t.dataloop + ptrdiff);
 
 	    if (!(dataloop->kind & DLOOP_FINAL_MASK))
 		PREPEND_PREFIX(Dataloop_update)(dataloop->loop_params.cm_t.dataloop, ptrdiff);
 	    break;
 
 	case DLOOP_KIND_BLOCKINDEXED:
-	    dataloop->loop_params.bi_t.offset_array = (DLOOP_Offset *)
-		((char *) dataloop->loop_params.bi_t.offset_array + ptrdiff);
-	    dataloop->loop_params.bi_t.dataloop = (DLOOP_Dataloop *)
-		((char *) dataloop->loop_params.bi_t.dataloop + ptrdiff);
+	    dataloop->loop_params.bi_t.offset_array = 
+		(DLOOP_Offset *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.bi_t.offset_array + ptrdiff);
+	    dataloop->loop_params.bi_t.dataloop = 
+		(DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.bi_t.dataloop + ptrdiff);
 
 	    if (!(dataloop->kind & DLOOP_FINAL_MASK))
 		PREPEND_PREFIX(Dataloop_update)(dataloop->loop_params.bi_t.dataloop, ptrdiff);
 	    break;
 
 	case DLOOP_KIND_INDEXED:
-	    dataloop->loop_params.i_t.blocksize_array = (DLOOP_Count *)
-		((char *) dataloop->loop_params.i_t.blocksize_array + ptrdiff);
-	    dataloop->loop_params.i_t.offset_array = (DLOOP_Offset *)
-		((char *) dataloop->loop_params.i_t.offset_array + ptrdiff);
-	    dataloop->loop_params.i_t.dataloop = (DLOOP_Dataloop *)
-		((char *) dataloop->loop_params.i_t.dataloop + ptrdiff);
+	    dataloop->loop_params.i_t.blocksize_array = 
+		(DLOOP_Count *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.blocksize_array + ptrdiff);
+	    dataloop->loop_params.i_t.offset_array = 
+		(DLOOP_Offset *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.offset_array + ptrdiff);
+	    dataloop->loop_params.i_t.dataloop = 
+		(DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.i_t.dataloop + ptrdiff);
 
 	    if (!(dataloop->kind & DLOOP_FINAL_MASK))
 		PREPEND_PREFIX(Dataloop_update)(dataloop->loop_params.i_t.dataloop, ptrdiff);
 	    break;
 
 	case DLOOP_KIND_STRUCT:
-	    dataloop->loop_params.s_t.blocksize_array = (DLOOP_Count *)
-		((char *) dataloop->loop_params.s_t.blocksize_array + ptrdiff);
-	    dataloop->loop_params.s_t.offset_array = (DLOOP_Offset *)
-		((char *) dataloop->loop_params.s_t.offset_array + ptrdiff);
-	    dataloop->loop_params.s_t.dataloop_array = (DLOOP_Dataloop **)
-		((char *) dataloop->loop_params.s_t.dataloop_array + ptrdiff);
+	    dataloop->loop_params.s_t.blocksize_array = 
+		(DLOOP_Count *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.blocksize_array + ptrdiff);
+	    dataloop->loop_params.s_t.offset_array = 
+		(DLOOP_Offset *) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.offset_array + ptrdiff);
+	    dataloop->loop_params.s_t.dataloop_array = 
+		(DLOOP_Dataloop **) MPI_AINT_CAST_TO_VOID_PTR
+		(MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) dataloop->loop_params.s_t.dataloop_array + ptrdiff);
 
 	    /* fix the N dataloop pointers too */
 	    looparray = dataloop->loop_params.s_t.dataloop_array;
 	    for (i=0; i < dataloop->loop_params.s_t.count; i++) {
-		looparray[i] = (DLOOP_Dataloop *)
-		    ((char *) looparray[i] + ptrdiff);
+		looparray[i] = (DLOOP_Dataloop *) MPI_AINT_CAST_TO_VOID_PTR
+		    (MPI_VOID_PTR_CAST_TO_MPI_AINT (char *) looparray[i] + ptrdiff);
 	    }
 
 	    if (dataloop->kind & DLOOP_FINAL_MASK) break;
@@ -589,7 +598,7 @@ PREPEND_PREFIX(Dataloop_stream_size)(struct DLOOP_Dataloop *dl_p,
             tmp_sz = 0;
             for (i = 0; i < dl_p->loop_params.s_t.count; i++)
             {
-                ret += dl_p->loop_params.s_t.blocksize_array[i] *
+                ret += (DLOOP_Offset)(unsigned long)(dl_p->loop_params.s_t.blocksize_array[i]) *
                     PREPEND_PREFIX(Dataloop_stream_size)(dl_p->loop_params.s_t.dataloop_array[i], sizefn);
             }
             return tmp_sz * tmp_ct;
@@ -597,36 +606,38 @@ PREPEND_PREFIX(Dataloop_stream_size)(struct DLOOP_Dataloop *dl_p,
 
         switch (dl_p->kind & DLOOP_KIND_MASK) {
         case DLOOP_KIND_CONTIG:
-            tmp_ct *= dl_p->loop_params.c_t.count;
+            tmp_ct *= (DLOOP_Offset)(unsigned long)(dl_p->loop_params.c_t.count);
 #ifdef DLOOP_DEBUG_SIZE
-            DLOOP_dbg_printf("stream_size: contig: ct = %d; new tot_ct = %d\n",
-                             (int) dl_p->loop_params.c_t.count, (int) tmp_ct);
+            DLOOP_dbg_printf("stream_size: contig: ct = %d; new tot_ct = " MPI_AINT_FMT_DEC_SPEC "\n",
+                             (int) dl_p->loop_params.c_t.count, (MPI_Aint) tmp_ct);
 #endif
             break;
         case DLOOP_KIND_VECTOR:
-            tmp_ct *= dl_p->loop_params.v_t.count * dl_p->loop_params.v_t.blocksize;
+            tmp_ct *= (DLOOP_Offset)(unsigned long)(dl_p->loop_params.v_t.count) * 
+		      (DLOOP_Offset)(unsigned long)(dl_p->loop_params.v_t.blocksize);
 #ifdef DLOOP_DEBUG_SIZE
-            DLOOP_dbg_printf("stream_size: vector: ct = %d; blk = %d; new tot_ct = %d\n",
+            DLOOP_dbg_printf("stream_size: vector: ct = %d; blk = %d; new tot_ct = " MPI_AINT_FMT_DEC_SPEC "\n",
                              (int) dl_p->loop_params.v_t.count,
                              (int) dl_p->loop_params.v_t.blocksize,
-                             (int) tmp_ct);
+                             (MPI_Aint) tmp_ct);
 #endif
             break;
         case DLOOP_KIND_BLOCKINDEXED:
-            tmp_ct *= dl_p->loop_params.bi_t.count * dl_p->loop_params.bi_t.blocksize;
+            tmp_ct *= (DLOOP_Offset)(unsigned long)(dl_p->loop_params.bi_t.count) * 
+		      (DLOOP_Offset)(unsigned long)(dl_p->loop_params.bi_t.blocksize);
 #ifdef DLOOP_DEBUG_SIZE
-            DLOOP_dbg_printf("stream_size: blkindexed: blks = %d; new tot_ct = %d\n",
+            DLOOP_dbg_printf("stream_size: blkindexed: blks = %d; new tot_ct = " MPI_AINT_FMT_DEC_SPEC "\n",
                              (int) dl_p->loop_params.bi_t.count *
                              (int) dl_p->loop_params.bi_t.blocksize,
-                             (int) tmp_ct);
+                             (MPI_Aint) tmp_ct);
 #endif
             break;
         case DLOOP_KIND_INDEXED:
-            tmp_ct *= dl_p->loop_params.i_t.total_blocks;
+            tmp_ct *= (DLOOP_Offset)(unsigned long)(dl_p->loop_params.i_t.total_blocks);
 #ifdef DLOOP_DEBUG_SIZE
-            DLOOP_dbg_printf("stream_size: contig: blks = %d; new tot_ct = %d\n",
+            DLOOP_dbg_printf("stream_size: contig: blks = %d; new tot_ct = " MPI_AINT_FMT_DEC_SPEC "\n",
                              (int) dl_p->loop_params.i_t.total_blocks,
-                             (int) tmp_ct);
+                             (MPI_Aint) tmp_ct);
 #endif
             break;
         default:
@@ -669,8 +680,8 @@ void PREPEND_PREFIX(Dataloop_print)(struct DLOOP_Dataloop *dataloop,
         return;
     }
 
-    DLOOP_dbg_printf("loc=%p, treedepth=%d, kind=%d, el_extent=%ld\n",
-		     dataloop, (int) depth, (int) dataloop->kind, (long) dataloop->el_extent);
+    DLOOP_dbg_printf("loc=%p, treedepth=%d, kind=%d, el_extent=" MPI_AINT_FMT_DEC_SPEC "\n",
+		     dataloop, (int) depth, (int) dataloop->kind, (MPI_Aint) dataloop->el_extent);
     switch(dataloop->kind & DLOOP_KIND_MASK) {
 	case DLOOP_KIND_CONTIG:
 	    DLOOP_dbg_printf("\tCONTIG: count=%d, datatype=%p\n", 
@@ -680,10 +691,10 @@ void PREPEND_PREFIX(Dataloop_print)(struct DLOOP_Dataloop *dataloop,
 		PREPEND_PREFIX(Dataloop_print)(dataloop->loop_params.c_t.dataloop, depth+1);
 	    break;
 	case DLOOP_KIND_VECTOR:
-	    DLOOP_dbg_printf("\tVECTOR: count=%d, blksz=%d, stride=%d, datatype=%p\n",
+	    DLOOP_dbg_printf("\tVECTOR: count=%d, blksz=%d, stride=" MPI_AINT_FMT_DEC_SPEC ", datatype=%p\n",
 			     (int) dataloop->loop_params.v_t.count, 
 			     (int) dataloop->loop_params.v_t.blocksize, 
-			     (int) dataloop->loop_params.v_t.stride,
+			     (MPI_Aint) dataloop->loop_params.v_t.stride,
 			     dataloop->loop_params.v_t.dataloop);
 	    if (!(dataloop->kind & DLOOP_FINAL_MASK))
 		PREPEND_PREFIX(Dataloop_print)(dataloop->loop_params.v_t.dataloop, depth+1);
@@ -712,7 +723,7 @@ void PREPEND_PREFIX(Dataloop_print)(struct DLOOP_Dataloop *dataloop,
 		DLOOP_dbg_printf("\t\t%d\n", (int) dataloop->loop_params.s_t.blocksize_array[i]);
 	    DLOOP_dbg_printf("\toffsets:\n");
 	    for (i=0; i < dataloop->loop_params.s_t.count; i++)
-		DLOOP_dbg_printf("\t\t%d\n", (int) dataloop->loop_params.s_t.offset_array[i]);
+		DLOOP_dbg_printf("\t\t" MPI_AINT_FMT_DEC_SPEC "\n", (MPI_Aint) dataloop->loop_params.s_t.offset_array[i]);
 	    DLOOP_dbg_printf("\tdatatypes:\n");
 	    for (i=0; i < dataloop->loop_params.s_t.count; i++)
 		DLOOP_dbg_printf("\t\t%p\n", dataloop->loop_params.s_t.dataloop_array[i]);
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_blockindexed.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_blockindexed.c
index 0cbcc96..8546edf 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_blockindexed.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_blockindexed.c
@@ -297,7 +297,7 @@ static DLOOP_Count DLOOP_Type_blockindexed_count_contig(DLOOP_Count count,
 	{
 	    DLOOP_Offset next_tdisp = (DLOOP_Offset) ((int *) disp_array)[i];
 
-	    if (cur_tdisp + blklen != next_tdisp)
+	    if (cur_tdisp + (DLOOP_Offset)blklen != next_tdisp)
 	    {
 		contig_count++;
 	    }
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_indexed.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_indexed.c
index 18cb0dd..7bd4a2c 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_indexed.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_indexed.c
@@ -299,8 +299,8 @@ static void DLOOP_Type_indexed_array_copy(DLOOP_Count count,
 
     if (!dispinbytes)
     {
-	out_disp_array[0] = (DLOOP_Offset)
-	    ((int *) in_disp_array)[0] * old_extent;
+	out_disp_array[0] = 
+	    ((DLOOP_Offset)((int *) in_disp_array)[0]) * old_extent;
 	
 	for (i = 1; i < count; i++)
 	{
@@ -385,7 +385,7 @@ static DLOOP_Count DLOOP_Type_indexed_count_contig(DLOOP_Count count,
 	    {
 		continue;
 	    }
-	    else if (cur_tdisp + cur_blklen ==
+	    else if (cur_tdisp + (DLOOP_Offset)cur_blklen ==
 		     (DLOOP_Offset) ((int *) displacement_array)[i])
 	    {
 		/* adjacent to current block; add to block */
@@ -410,7 +410,7 @@ static DLOOP_Count DLOOP_Type_indexed_count_contig(DLOOP_Count count,
 	    {
 		continue;
 	    }
-	    else if (cur_bdisp + cur_blklen * old_extent ==
+	    else if (cur_bdisp + (DLOOP_Offset)cur_blklen * old_extent ==
 		     (DLOOP_Offset) ((MPI_Aint *) displacement_array)[i])
 	    {
 		/* adjacent to current block; add to block */
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_pairtype.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_pairtype.c
index acf3ef0..d5f7b86 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_pairtype.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_pairtype.c
@@ -11,7 +11,7 @@
     {									\
 	struct { ut1_ a; ut2_ b; } foo;					\
 	disps[0] = 0;							\
-	disps[1] = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);	\
+	disps[1] = MPI_VOID_PTR_CAST_TO_MPI_AINT ((char *) &foo.b - (char *) &foo.a);	\
 	types[0] = mt1_;						\
 	types[1] = mt2_;						\
     }
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_struct.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_struct.c
index af3a1f1..d9fc694 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_struct.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/dataloop_create_struct.c
@@ -622,7 +622,7 @@ static int DLOOP_Dataloop_create_flattened_struct(int count,
 	 */
 	if (oldtypes[i] != MPI_UB && oldtypes[i] != MPI_LB && blklens[i] != 0)
 	{
-	    PREPEND_PREFIX(Segment_init)((char *) disps[i],
+	    PREPEND_PREFIX(Segment_init)((char *) MPI_AINT_CAST_TO_VOID_PTR disps[i],
 					 (DLOOP_Count) blklens[i],
 					 oldtypes[i],
 					 segp,
@@ -646,7 +646,7 @@ static int DLOOP_Dataloop_create_flattened_struct(int count,
 	MPIU_DBG_OUT(DATATYPE,"--- start of flattened type ---");
         for (i=0; i < nr_blks; i++) {
 	MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-				   "a[%d] = (%d, %d)\n", i,
+				   "a[%d] = (%d, " MPI_AINT_FMT_DEC_SPEC ")\n", i,
 				   tmp_blklens[i], tmp_disps[i]));
 	}
 	MPIU_DBG_OUT(DATATYPE,"--- end of flattened type ---");
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment.c
index 25c6635..f902375 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment.c
@@ -367,14 +367,14 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 
     if (first == *lastp) {
 	/* nothing to do */
-	DLOOP_dbg_printf("dloop_segment_manipulate: warning: first == last (%d)\n", (int) first);
+	DLOOP_dbg_printf("dloop_segment_manipulate: warning: first == last (" MPI_AINT_FMT_DEC_SPEC ")\n", first);
 	return;
     }
 
     /* first we ensure that stream_off and first are in the same spot */
     if (first != stream_off) {
 #ifdef DLOOP_DEBUG_MANIPULATE
-	DLOOP_dbg_printf("first=%d; stream_off=%ld; resetting.\n",
+	DLOOP_dbg_printf("first=" MPI_AINT_FMT_DEC_SPEC "; stream_off=" MPI_AINT_FMT_DEC_SPEC "; resetting.\n",
 			 first, stream_off);
 #endif
 
@@ -408,7 +408,7 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 	DLOOP_SEGMENT_LOAD_LOCAL_VALUES;
 
 #ifdef DLOOP_DEBUG_MANIPULATE
-	DLOOP_dbg_printf("done repositioning stream_off; first=%d, stream_off=%ld, last=%d\n",
+	DLOOP_dbg_printf("done repositioning stream_off; first=" MPI_AINT_FMT_DEC_SPEC ", stream_off=" MPI_AINT_FMT_DEC_SPEC ", last=" MPI_AINT_FMT_DEC_SPEC "\n",
 		   first, stream_off, last);
 #endif
     }
@@ -493,7 +493,7 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 	    }
 
 #ifdef DLOOP_DEBUG_MANIPULATE
-	    DLOOP_dbg_printf("\thit leaf; cur_sp=%d, elmp=%x, piece_sz=%d\n",
+	    DLOOP_dbg_printf("\thit leaf; cur_sp=%d, elmp=%x, piece_sz=" MPI_AINT_FMT_DEC_SPEC "\n",
 			     cur_sp,
 		             (unsigned) cur_elmp, myblocks * local_el_size);
 #endif
@@ -504,9 +504,9 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 	    {
 		myblocks = ((last - stream_off) / stream_el_size);
 #ifdef DLOOP_DEBUG_MANIPULATE
-		DLOOP_dbg_printf("\tpartial block count=%d (%d bytes)\n",
+		DLOOP_dbg_printf("\tpartial block count=" MPI_AINT_FMT_DEC_SPEC " (" MPI_AINT_FMT_DEC_SPEC " bytes)\n",
 				 myblocks,
-                                 (int) myblocks * stream_el_size);
+                                 myblocks * stream_el_size);
 #endif
 		if (myblocks == 0) {
 		    DLOOP_SEGMENT_SAVE_LOCAL_VALUES;
@@ -580,7 +580,7 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 		DLOOP_SEGMENT_SAVE_LOCAL_VALUES;
 		return;
 	    }
-	    else if (myblocks < cur_elmp->curblock) {
+	    else if (myblocks < (DLOOP_Offset)(cur_elmp->curblock) ) {
 		cur_elmp->curoffset += myblocks * local_el_size;
 		cur_elmp->curblock  -= myblocks;
 
@@ -597,8 +597,8 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 
 		switch (cur_elmp->loop_p->kind & DLOOP_KIND_MASK) {
 		    case DLOOP_KIND_INDEXED:
-			while (myblocks > 0 && myblocks >= cur_elmp->curblock) {
-			    myblocks -= cur_elmp->curblock;
+			while (myblocks > 0 && myblocks >= (DLOOP_Offset)(cur_elmp->curblock) ) {
+			    myblocks -= (DLOOP_Offset)(cur_elmp->curblock);
 			    cur_elmp->curcount--;
 			    DLOOP_Assert(cur_elmp->curcount >= 0);
 
@@ -626,9 +626,9 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 			break;
 		    case DLOOP_KIND_VECTOR:
 			/* this math relies on assertions at top of code block */
-			cur_elmp->curcount -= myblocks / cur_elmp->curblock;
+			cur_elmp->curcount -= myblocks / (DLOOP_Offset)(cur_elmp->curblock);
 			if (cur_elmp->curcount == 0) {
-			    DLOOP_Assert(myblocks % cur_elmp->curblock == 0);
+			    DLOOP_Assert(myblocks % ((DLOOP_Offset)(cur_elmp->curblock)) == 0);
 			    DLOOP_SEGMENT_POP_AND_MAYBE_EXIT;
 			}
 			else {
@@ -636,15 +636,15 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 			     * block
 			     */
 			    cur_elmp->curblock = cur_elmp->orig_block -
-				(myblocks % cur_elmp->curblock);
+				(myblocks % (DLOOP_Offset)(cur_elmp->curblock) );
 			    /* new offset = original offset +
 			     *              stride * whole blocks +
 			     *              leftover bytes
 			     */
 			    cur_elmp->curoffset = cur_elmp->orig_offset +
-				((cur_elmp->orig_count - cur_elmp->curcount) *
+				(((DLOOP_Offset)(cur_elmp->orig_count - cur_elmp->curcount)) *
 				 cur_elmp->loop_p->loop_params.v_t.stride) +
-				((cur_elmp->orig_block - cur_elmp->curblock) *
+				(((DLOOP_Offset)(cur_elmp->orig_block - cur_elmp->curblock)) *
 				 local_el_size);
 			}
 			break;
@@ -652,14 +652,14 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 			/* contigs that reach this point have always been
 			 * completely processed
 			 */
-			DLOOP_Assert(myblocks == cur_elmp->curblock &&
+			DLOOP_Assert(myblocks == (DLOOP_Offset)(cur_elmp->curblock) &&
 			       cur_elmp->curcount == 1);
 			DLOOP_SEGMENT_POP_AND_MAYBE_EXIT;
 			break;
 		    case DLOOP_KIND_BLOCKINDEXED:
-			while (myblocks > 0 && myblocks >= cur_elmp->curblock)
+			while (myblocks > 0 && myblocks >= (DLOOP_Offset)(cur_elmp->curblock) )
 			{
-			    myblocks -= cur_elmp->curblock;
+			    myblocks -= (DLOOP_Offset)(cur_elmp->curblock);
 			    cur_elmp->curcount--;
 			    DLOOP_Assert(cur_elmp->curcount >= 0);
 
@@ -782,28 +782,28 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 	    switch (cur_elmp->loop_p->kind & DLOOP_KIND_MASK) {
 		case DLOOP_KIND_CONTIG:
 		    next_elmp->orig_offset = cur_elmp->curoffset +
-			block_index * cur_elmp->loop_p->el_extent;
+			(DLOOP_Offset)block_index * cur_elmp->loop_p->el_extent;
 		    break;
 		case DLOOP_KIND_VECTOR:
 		    /* note: stride is in bytes */
 		    next_elmp->orig_offset = cur_elmp->orig_offset +
-			count_index * cur_elmp->loop_p->loop_params.v_t.stride +
-			block_index * cur_elmp->loop_p->el_extent;
+			(DLOOP_Offset)count_index * cur_elmp->loop_p->loop_params.v_t.stride +
+			(DLOOP_Offset)block_index * cur_elmp->loop_p->el_extent;
 		    break;
 		case DLOOP_KIND_BLOCKINDEXED:
 		    next_elmp->orig_offset = cur_elmp->orig_offset +
-			block_index * cur_elmp->loop_p->el_extent +
+			(DLOOP_Offset)block_index * cur_elmp->loop_p->el_extent +
 			DLOOP_STACKELM_BLOCKINDEXED_OFFSET(cur_elmp,
 							   count_index);
 		    break;
 		case DLOOP_KIND_INDEXED:
 		    next_elmp->orig_offset = cur_elmp->orig_offset +
-			block_index * cur_elmp->loop_p->el_extent +
+			(DLOOP_Offset)block_index * cur_elmp->loop_p->el_extent +
 			DLOOP_STACKELM_INDEXED_OFFSET(cur_elmp, count_index);
 		    break;
 		case DLOOP_KIND_STRUCT:
 		    next_elmp->orig_offset = cur_elmp->orig_offset +
-			block_index * DLOOP_STACKELM_STRUCT_EL_EXTENT(cur_elmp, count_index) +
+			(DLOOP_Offset)block_index * DLOOP_STACKELM_STRUCT_EL_EXTENT(cur_elmp, count_index) +
 			DLOOP_STACKELM_STRUCT_OFFSET(cur_elmp, count_index);
 		    break;
 		default:
@@ -814,7 +814,7 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 	    }
 
 #ifdef DLOOP_DEBUG_MANIPULATE
-	    DLOOP_dbg_printf("\tstep 1: next orig_offset = %d (0x%x)\n",
+	    DLOOP_dbg_printf("\tstep 1: next orig_offset = " MPI_AINT_FMT_DEC_SPEC " (0x" MPI_AINT_FMT_HEX_SPEC ")\n",
 			     next_elmp->orig_offset,
 			     next_elmp->orig_offset);
 #endif
@@ -854,7 +854,7 @@ void PREPEND_PREFIX(Segment_manipulate)(struct DLOOP_Segment *segp,
 	    }
 
 #ifdef DLOOP_DEBUG_MANIPULATE
-	    DLOOP_dbg_printf("\tstep 2: next curoffset = %d (0x%x)\n",
+	    DLOOP_dbg_printf("\tstep 2: next curoffset = " MPI_AINT_FMT_DEC_SPEC " (0x" MPI_AINT_FMT_HEX_SPEC ")\n",
 			     next_elmp->curoffset,
 			     next_elmp->curoffset);
 #endif
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
index 3b779fe..294e3d0 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
@@ -27,19 +27,23 @@ int PREPEND_PREFIX(Segment_contig_m2m)(DLOOP_Offset *blocks_p,
     size = *blocks_p * el_size;
 
 #ifdef MPID_SU_VERBOSE
-    dbg_printf("\t[contig unpack: do=%d, dp=%x, bp=%x, sz=%d, blksz=%d]\n",
+    dbg_printf("\t[contig unpack: do=" MPI_AINT_FMT_DEC_SPEC ", dp=%x, bp=%x, sz=" MPI_AINT_FMT_DEC_SPEC ", blksz=" MPI_AINT_FMT_DEC_SPEC "]\n",
 	       rel_off, 
 	       (unsigned) bufp,
 	       (unsigned) paramp->u.unpack.unpack_buffer,
 	       el_size,
-	       (int) *blocks_p);
+	       *blocks_p);
 #endif
 
     if (paramp->direction == DLOOP_M2M_TO_USERBUF) {
-	memcpy((char *) (paramp->userbuf + rel_off), paramp->streambuf, size);
+	memcpy((char *) MPI_AINT_CAST_TO_VOID_PTR ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off), 
+	       paramp->streambuf, 
+	       size);
     }
     else {
-	memcpy(paramp->streambuf, (char *) (paramp->userbuf + rel_off), size);
+	memcpy(paramp->streambuf, 
+	       (char *) ( MPI_AINT_CAST_TO_VOID_PTR ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off) ), 
+	       size);
     }
     paramp->streambuf += size;
     return 0;
@@ -66,11 +70,11 @@ int PREPEND_PREFIX(Segment_vector_m2m)(DLOOP_Offset *blocks_p,
     struct PREPEND_PREFIX(m2m_params) *paramp = v_paramp;
     char *cbufp;
 
-    cbufp = paramp->userbuf + rel_off;
+    cbufp = (char*)( MPI_AINT_CAST_TO_VOID_PTR ( (MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + rel_off ) );
     DLOOP_Handle_get_size_macro(el_type, el_size);
 
-    whole_count = (blksz > 0) ? (*blocks_p / blksz) : 0;
-    blocks_left = (blksz > 0) ? (*blocks_p % blksz) : 0;
+    whole_count = (blksz > 0) ? (*blocks_p / (DLOOP_Offset)blksz) : 0;
+    blocks_left = (blksz > 0) ? (*blocks_p % (DLOOP_Offset)blksz) : 0;
 
     if (paramp->direction == DLOOP_M2M_TO_USERBUF) {
 	if (el_size == 8 
@@ -97,13 +101,13 @@ int PREPEND_PREFIX(Segment_vector_m2m)(DLOOP_Offset *blocks_p,
 	}
 	else {
 	    for (i=0; i < whole_count; i++) {
-		memcpy(cbufp, paramp->streambuf, blksz * el_size);
-		paramp->streambuf += blksz * el_size;
+		memcpy(cbufp, paramp->streambuf, ((DLOOP_Offset)blksz) * el_size);
+		paramp->streambuf += ((DLOOP_Offset)blksz) * el_size;
 		cbufp += stride;
 	    }
 	    if (blocks_left) {
-		memcpy(cbufp, paramp->streambuf, blocks_left * el_size);
-		paramp->streambuf += blocks_left * el_size;
+		memcpy(cbufp, paramp->streambuf, ((DLOOP_Offset)blocks_left) * el_size);
+		paramp->streambuf += ((DLOOP_Offset)blocks_left) * el_size;
 	    }
 	}
     }
@@ -132,13 +136,13 @@ int PREPEND_PREFIX(Segment_vector_m2m)(DLOOP_Offset *blocks_p,
 	}
 	else {
 	    for (i=0; i < whole_count; i++) {
-		memcpy(paramp->streambuf, cbufp, blksz * el_size);
-		paramp->streambuf += blksz * el_size;
+		memcpy(paramp->streambuf, cbufp, (DLOOP_Offset)blksz * el_size);
+		paramp->streambuf += (DLOOP_Offset)blksz * el_size;
 		cbufp += stride;
 	    }
 	    if (blocks_left) {
-		memcpy(paramp->streambuf, cbufp, blocks_left * el_size);
-		paramp->streambuf += blocks_left * el_size;
+		memcpy(paramp->streambuf, cbufp, (DLOOP_Offset)blocks_left * el_size);
+		paramp->streambuf += (DLOOP_Offset)blocks_left * el_size;
 	    }
 	}
     }
@@ -170,7 +174,9 @@ int PREPEND_PREFIX(Segment_blkidx_m2m)(DLOOP_Offset *blocks_p,
 
 	DLOOP_Assert(curblock < count);
 
-	cbufp = paramp->userbuf + rel_off + offsetarray[curblock];
+	cbufp = (char*) MPI_AINT_CAST_TO_VOID_PTR
+	          ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + 
+		   rel_off + offsetarray[curblock]);
 
 	if (blocklen > blocks_left) blocklen = blocks_left;
 
@@ -198,10 +204,10 @@ int PREPEND_PREFIX(Segment_blkidx_m2m)(DLOOP_Offset *blocks_p,
 	    MPIDI_COPY_FROM_VEC(src, dest, 0, int16_t, blocklen, 1);
 	}
 	else {
-	    memcpy(dest, src, blocklen * el_size);
+	    memcpy(dest, src, (DLOOP_Offset)blocklen * el_size);
 	}
 
-	paramp->streambuf += blocklen * el_size;
+	paramp->streambuf += (DLOOP_Offset)blocklen * el_size;
 	blocks_left -= blocklen;
 	curblock++;
     }
@@ -234,7 +240,9 @@ int PREPEND_PREFIX(Segment_index_m2m)(DLOOP_Offset *blocks_p,
 	DLOOP_Assert(curblock < count);
 	cur_block_sz = blockarray[curblock];
 
-	cbufp = paramp->userbuf + rel_off + offsetarray[curblock];
+	cbufp = (char*) MPI_AINT_CAST_TO_VOID_PTR
+	          ((MPI_VOID_PTR_CAST_TO_MPI_AINT (paramp->userbuf)) + 
+		   rel_off + offsetarray[curblock]);
 
 	if (cur_block_sz > blocks_left) cur_block_sz = blocks_left;
 
@@ -348,10 +356,10 @@ static int DLOOP_Segment_contig_count_block(DLOOP_Offset *blocks_p,
     size = *blocks_p * el_size;
 
 #ifdef MPID_SP_VERBOSE
-    MPIU_dbg_printf("contig count block: count = %d, buf+off = %d, lastloc = %d\n",
+    MPIU_dbg_printf("contig count block: count = %d, buf+off = %d, lastloc = " MPI_AINT_FMT_DEC_SPEC "\n",
 		    (int) paramp->count,
 		    (int) ((char *) bufp + rel_off),
-		    (int) paramp->last_loc);
+		    paramp->last_loc);
 #endif
 
     if (paramp->count > 0 && rel_off == paramp->last_loc)
@@ -408,7 +416,7 @@ static int DLOOP_Segment_vector_count_block(DLOOP_Offset *blocks_p,
 	new_blk_count--;
     }
 
-    paramp->last_loc = rel_off + (count-1) * stride + size;
+    paramp->last_loc = rel_off + ((DLOOP_Offset)(count-1)) * stride + size;
     paramp->count += new_blk_count;
     return 0;
 }
@@ -434,7 +442,7 @@ static int DLOOP_Segment_blkidx_count_block(DLOOP_Offset *blocks_p,
     DLOOP_Assert(count > 0 && blksz > 0 && *blocks_p > 0);
 
     DLOOP_Handle_get_size_macro(el_type, el_size);
-    size = el_size * blksz;
+    size = el_size * (DLOOP_Offset)blksz;
     new_blk_count = count;
 
     if (paramp->count > 0 && rel_off == paramp->last_loc)
@@ -492,14 +500,14 @@ static int DLOOP_Segment_index_count_block(DLOOP_Offset *blocks_p,
      *       declared above.
      */
 #if 0
-    last_loc = rel_off * offsetarray[0] + blockarray[0] * el_size;
+    last_loc = rel_off * offsetarray[0] + ((DLOOP_Offset)blockarray[0]) * el_size;
     for (i=1; i < count; i++) {
 	if (last_loc == rel_off + offsetarray[i]) new_blk_count--;
 
-	last_loc = rel_off + offsetarray[i] + blockarray[i] * el_size;
+	last_loc = rel_off + offsetarray[i] + ((DLOOP_Offset)blockarray[i]) * el_size;
     }
 #else
-    last_loc = rel_off + offsetarray[count-1] + blockarray[count-1] * el_size;
+    last_loc = rel_off + offsetarray[count-1] + ((DLOOP_Offset)blockarray[count-1]) * el_size;
 #endif
 
     paramp->last_loc = last_loc;
@@ -570,12 +578,12 @@ static int DLOOP_Segment_contig_mpi_flatten(DLOOP_Offset *blocks_p,
     struct PREPEND_PREFIX(mpi_flatten_params) *paramp = v_paramp;
 
     DLOOP_Handle_get_size_macro(el_type, el_size);
-    size = *blocks_p * (int) el_size;
+    size = *blocks_p * el_size;
     
     last_idx = paramp->index - 1;
     if (last_idx >= 0) {
-	last_end = ((char *) paramp->disps[last_idx]) +
-	    paramp->blklens[last_idx];
+	last_end = (char*) MPI_AINT_CAST_TO_VOID_PTR 
+	           (paramp->disps[last_idx] + ((DLOOP_Offset)paramp->blklens[last_idx]));
     }
 
     if ((last_idx == paramp->length-1) &&
@@ -635,15 +643,15 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 
 #if 0
     MPIU_DBG_MSG_FMT(DATATYPE,VERBOSE,(MPIU_DBG_FDEST,
-	     "\t[vector to vec: do=%d, dp=%x, len=%d, ind=%d, ct=%d, blksz=%d, str=%d, blks=%d]\n",
-		    (unsigned) rel_off,
-		    (unsigned) (MPI_Aint)bufp,
+	     "\t[vector to vec: do=" MPI_AINT_FMT_DEC_SPEC ", dp=%x, len=%d, ind=%d, ct=%d, blksz=%d, str=" MPI_AINT_FMT_DEC_SPEC ", blks=" MPI_AINT_FMT_DEC_SPEC "]\n",
+		    rel_off,
+		    (unsigned) bufp,
 		    paramp->u.pack_vector.length,
 		    paramp->u.pack_vector.index,
 		    count,
 		    blksz,
 		    stride,
-		    (int) *blocks_p));
+		    *blocks_p));
 #endif
 
     for (i=0; i < count && blocks_left > 0; i++) {
@@ -662,8 +670,8 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 
 	last_idx = paramp->index - 1;
 	if (last_idx >= 0) {
-	    last_end = ((char *) paramp->disps[last_idx]) +
-		paramp->blklens[last_idx];
+	    last_end = (char*) MPI_AINT_CAST_TO_VOID_PTR 
+		       (paramp->disps[last_idx] + ((DLOOP_Offset)paramp->blklens[last_idx]));
 	}
 
 	if ((last_idx == paramp->length-1) &&
@@ -672,14 +680,14 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 	    /* we have used up all our entries, and this one doesn't fit on
 	     * the end of the last one.
 	     */
-	    *blocks_p -= (blocks_left + (size / (int) el_size));
+	    *blocks_p -= ((DLOOP_Offset)blocks_left + (((DLOOP_Offset)size) / el_size));
 #if 0
 	    paramp->u.pack_vector.index++;
 #endif
 #ifdef MPID_SP_VERBOSE
-	    MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, %d blocks processed.\n",
+	    MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 			    paramp->u.pack_vector.index,
-			    (int) *blocks_p);
+			    *blocks_p);
 #endif
 	    return 1;
 	}
@@ -698,9 +706,9 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
     }
 
 #ifdef MPID_SP_VERBOSE
-    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, %d blocks processed.\n",
+    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 		    paramp->u.pack_vector.index,
-		    (int) *blocks_p);
+		    *blocks_p);
 #endif
 
     /* if we get here then we processed ALL the blocks; don't need to update
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/subarray_support.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/subarray_support.c
index becce18..ebff90a 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/subarray_support.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/subarray_support.c
@@ -33,9 +33,9 @@ int PREPEND_PREFIX(Type_convert_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]);
 		PMPI_Type_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
 		PMPI_Type_free(&tmp1);
 		tmp1 = tmp2;
@@ -43,11 +43,11 @@ int PREPEND_PREFIX(Type_convert_subarray)(int ndims,
 	}
 	
 	/* add displacement and UB */
-	disps[1] = array_of_starts[0];
+	disps[1] = (MPI_Aint)(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 */
     }
@@ -62,9 +62,9 @@ int PREPEND_PREFIX(Type_convert_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]);
 		PMPI_Type_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
 		PMPI_Type_free(&tmp1);
 		tmp1 = tmp2;
@@ -72,18 +72,18 @@ int PREPEND_PREFIX(Type_convert_subarray)(int ndims,
 	}
 	
 	/* add displacement and UB */
-	disps[1] = array_of_starts[ndims-1];
+	disps[1] = (MPI_Aint)(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/mpid/common/datatype/dataloop/veccpy.h b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/veccpy.h
index 0a2fa72..13fae8d 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/veccpy.h
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/veccpy.h
@@ -23,26 +23,30 @@
 #define MPIDI_COPY_FROM_VEC(src,dest,stride,type,nelms,count) \
 { \
     if (!nelms) { \
-        src = (char*) (src + (count * stride)); \
+        src = (char*) MPI_AINT_CAST_TO_VOID_PTR                        \
+                      ((MPI_VOID_PTR_CAST_TO_MPI_AINT (src)) +         \
+		       ((DLOOP_Offset)count * (DLOOP_Offset)stride) ); \
     } \
     else if (stride % sizeof(type)) { \
         MPIDI_COPY_FROM_VEC_UNALIGNED(src,dest,stride,type,nelms,count); \
     } \
     else { \
-        MPIDI_COPY_FROM_VEC_ALIGNED(src,dest,stride/sizeof(type),type,nelms,count); \
+        MPIDI_COPY_FROM_VEC_ALIGNED(src,dest,stride/(DLOOP_Offset)sizeof(type),type,nelms,count); \
     } \
 }
 
 #define MPIDI_COPY_TO_VEC(src,dest,stride,type,nelms,count) \
 { \
     if (!nelms) { \
-        dest = (char*) (dest + (count * stride)); \
+        dest = (char*) MPI_AINT_CAST_TO_VOID_PTR                        \
+                       ((MPI_VOID_PTR_CAST_TO_MPI_AINT (dest)) +        \
+                        ((DLOOP_Offset)count * (DLOOP_Offset)stride) ); \
     } \
-    else if (stride % sizeof(type)) { \
+    else if (stride % (DLOOP_Offset)sizeof(type)) { \
         MPIDI_COPY_TO_VEC_UNALIGNED(src,dest,stride,type,nelms,count); \
     } \
     else { \
-        MPIDI_COPY_TO_VEC_ALIGNED(src,dest,stride/sizeof(type),type,nelms,count); \
+        MPIDI_COPY_TO_VEC_ALIGNED(src,dest,stride/(DLOOP_Offset)sizeof(type),type,nelms,count); \
     } \
 }
 
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c
index 2b6e901..7e90351 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_segment.c
@@ -235,12 +235,12 @@ static int MPID_Segment_contig_pack_to_iov(DLOOP_Offset *blocks_p,
     size = *blocks_p * (DLOOP_Offset) el_size;
 
     MPIU_DBG_MSG_FMT(DATATYPE,VERBOSE,(MPIU_DBG_FDEST,
-             "\t[contig to vec: do=%d, dp=%x, ind=%d, sz=%d, blksz=%d]\n",
-		    (unsigned) rel_off,
+             "\t[contig to vec: do=MPI_AINT_FMT_DEC_SPEC, dp=%x, ind=%d, sz=%d, blksz="MPI_AINT_FMT_DEC_SPEC"]\n",
+		    (MPI_Aint) rel_off,
 		    (unsigned) (MPI_Aint)bufp,
 		    paramp->u.pack_vector.index,
 		    el_size,
-		    (int) *blocks_p));
+		    (MPI_Aint) *blocks_p));
     
     last_idx = paramp->u.pack_vector.index - 1;
     if (last_idx >= 0) {
@@ -299,39 +299,39 @@ static int MPID_Segment_vector_pack_to_iov(DLOOP_Offset *blocks_p,
 					   void *bufp, /* start of buffer */
 					   void *v_paramp)
 {
-    int i, basic_size;
-    DLOOP_Offset size, blocks_left;
+    int i;
+    DLOOP_Offset size, blocks_left, basic_size;
     struct MPID_Segment_piece_params *paramp = v_paramp;
     MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV);
 
     MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV);
 
-    basic_size = MPID_Datatype_get_basic_size(el_type);
+    basic_size = (DLOOP_Offset)(unsigned long)MPID_Datatype_get_basic_size(el_type);
     blocks_left = *blocks_p;
 
     MPIU_DBG_MSG_FMT(DATATYPE,VERBOSE,(MPIU_DBG_FDEST,
-             "\t[vector to vec: do=%d"
+             "\t[vector to vec: do=" MPI_AINT_FMT_DEC_SPEC
              ", dp=" MPI_AINT_FMT_HEX_SPEC
              ", len=%d, ind=%d, ct=%d, blksz=%d"
              ", str=" MPI_AINT_FMT_DEC_SPEC
              ", blks=" MPI_AINT_FMT_DEC_SPEC
              "]\n",
-		    (unsigned) rel_off,
+		    (MPI_Aint) rel_off,
 		    (MPI_Aint)bufp,
 		    paramp->u.pack_vector.length,
 		    paramp->u.pack_vector.index,
 		    count,
 		    blksz,
-		    stride,
-		    *blocks_p));
+		    (MPI_Aint)stride,
+		    (MPI_Aint)*blocks_p));
 
     for (i=0; i < count && blocks_left > 0; i++) {
 	int last_idx;
 	char *last_end = NULL;
 
-	if (blocks_left > blksz) {
-	    size = blksz * basic_size;
-	    blocks_left -= blksz;
+	if (blocks_left > (DLOOP_Offset)(unsigned long)blksz) {
+	    size = ((DLOOP_Offset)(unsigned long)blksz) * basic_size;
+	    blocks_left -= (DLOOP_Offset)(unsigned long)blksz;
 	}
 	else {
 	    /* last pass */
@@ -356,21 +356,21 @@ static int MPID_Segment_vector_pack_to_iov(DLOOP_Offset *blocks_p,
 	    paramp->u.pack_vector.index++;
 #endif
 #ifdef MPID_SP_VERBOSE
-	    MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, %d blocks processed.\n",
+	    MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 			    paramp->u.pack_vector.index,
-			    (int) *blocks_p);
+			    (MPI_Aint) *blocks_p);
 #endif
 	    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV);
 	    return 1;
 	}
-	else if (last_idx >= 0 && (last_end == ((char *) bufp + rel_off)))
+	else if (last_idx >= 0 && (last_end == ((char *) bufp + (int)rel_off)))
 	{
 	    /* add this size to the last vector rather than using up new one */
 	    paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_LEN += size;
 	}
 	else {
 	    paramp->u.pack_vector.vectorp[last_idx+1].DLOOP_VECTOR_BUF =
-		(char *) bufp + rel_off;
+		(char *) bufp + (int)rel_off;
 	    paramp->u.pack_vector.vectorp[last_idx+1].DLOOP_VECTOR_LEN = size;
 	    paramp->u.pack_vector.index++;
 	}
@@ -380,9 +380,9 @@ static int MPID_Segment_vector_pack_to_iov(DLOOP_Offset *blocks_p,
     }
 
 #ifdef MPID_SP_VERBOSE
-    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, %d blocks processed.\n",
+    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 		    paramp->u.pack_vector.index,
-		    (int) *blocks_p);
+		    (MPI_Aint) *blocks_p);
 #endif
 
     /* if we get here then we processed ALL the blocks; don't need to update
@@ -415,27 +415,27 @@ static int MPID_Segment_contig_flatten(DLOOP_Offset *blocks_p,
     MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_CONTIG_FLATTEN);
 
     el_size = MPID_Datatype_get_basic_size(el_type);
-    size = *blocks_p * (DLOOP_Offset) el_size;
+    size = *blocks_p * (DLOOP_Offset)(unsigned long)el_size;
     index = paramp->u.flatten.index;
 
 #ifdef MPID_SP_VERBOSE
-    MPIU_dbg_printf("\t[contig flatten: index = %d, loc = (%x + %x) = %x, size = %d]\n",
+    MPIU_dbg_printf("\t[contig flatten: index = %d, loc = (" MPI_AINT_FMT_HEX_SPEC " + " MPI_AINT_FMT_HEX_SPEC ") = " MPI_AINT_FMT_HEX_SPEC ", size = " MPI_AINT_FMT_DEC_SPEC "]\n",
 		    index,
-		    (unsigned) bufp,
-		    (unsigned) rel_off,
-		    (unsigned) bufp + rel_off,
-		    (int) size);
+		    MPI_VOID_PTR_CAST_TO_MPI_AINT bufp,
+		    (MPI_Aint) rel_off,
+		    MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off,
+		    (MPI_Aint) size);
 #endif
     
-    if (index > 0 && ((DLOOP_Offset) bufp + rel_off) ==
+    if (index > 0 && ((DLOOP_Offset) MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ==
 	((paramp->u.flatten.offp[index - 1]) +
-	 (DLOOP_Offset) paramp->u.flatten.sizep[index - 1]))
+	 (DLOOP_Offset)(unsigned long)paramp->u.flatten.sizep[index - 1]))
     {
 	/* add this size to the last vector rather than using up another one */
 	paramp->u.flatten.sizep[index - 1] += size;
     }
     else {
-	paramp->u.flatten.offp[index] =  ((int64_t) (MPI_Aint) bufp) + (int64_t) rel_off;
+	paramp->u.flatten.offp[index] =  ((int64_t) MPI_VOID_PTR_CAST_TO_MPI_AINT bufp) + (int64_t) rel_off;
 	paramp->u.flatten.sizep[index] = size;
 
 	paramp->u.flatten.index++;
@@ -475,22 +475,22 @@ static int MPID_Segment_vector_flatten(DLOOP_Offset *blocks_p,
 				       void *bufp, /* start of buffer */
 				       void *v_paramp)
 {
-    int i, basic_size;
-    DLOOP_Offset size, blocks_left;
+    int i;
+    DLOOP_Offset size, blocks_left, basic_size;
     struct MPID_Segment_piece_params *paramp = v_paramp;
     MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_VECTOR_FLATTEN);
 
     MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_VECTOR_FLATTEN);
 
-    basic_size = MPID_Datatype_get_basic_size(el_type);
+    basic_size = (DLOOP_Offset)(unsigned long)MPID_Datatype_get_basic_size(el_type);
     blocks_left = *blocks_p;
 
     for (i=0; i < count && blocks_left > 0; i++) {
 	int index = paramp->u.flatten.index;
 
-	if (blocks_left > blksz) {
-	    size = blksz * (DLOOP_Offset) basic_size;
-	    blocks_left -= blksz;
+	if (blocks_left > (DLOOP_Offset)(unsigned long)blksz) {
+	    size = ((DLOOP_Offset)(unsigned long)blksz) * basic_size;
+	    blocks_left -= (DLOOP_Offset)(unsigned long)blksz;
 	}
 	else {
 	    /* last pass */
@@ -498,15 +498,15 @@ static int MPID_Segment_vector_flatten(DLOOP_Offset *blocks_p,
 	    blocks_left = 0;
 	}
 
-	if (index > 0 && ((DLOOP_Offset) bufp + rel_off) ==
-	    ((paramp->u.flatten.offp[index - 1]) + (DLOOP_Offset) paramp->u.flatten.sizep[index - 1]))
+	if (index > 0 && ((DLOOP_Offset) MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ==
+	    ((paramp->u.flatten.offp[index - 1]) + (DLOOP_Offset)(unsigned long)paramp->u.flatten.sizep[index - 1]))
 	{
 	    /* add this size to the last region rather than using up another one */
 	    paramp->u.flatten.sizep[index - 1] += size;
 	}
 	else if (index < paramp->u.flatten.length) {
 	    /* take up another region */
-	    paramp->u.flatten.offp[index]  = (DLOOP_Offset) bufp + rel_off;
+	    paramp->u.flatten.offp[index]  = (DLOOP_Offset) MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off;
 	    paramp->u.flatten.sizep[index] = size;
 	    paramp->u.flatten.index++;
 	}
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_blockindexed.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_blockindexed.c
index 91cb964..b69c49e 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_blockindexed.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_blockindexed.c
@@ -86,7 +86,7 @@ int MPID_Type_blockindexed(int count,
 
     if (is_builtin)
     {
-	el_sz   = MPID_Datatype_get_basic_size(oldtype);
+	el_sz   = (MPI_Aint)(unsigned long)MPID_Datatype_get_basic_size(oldtype);
 	el_type = oldtype;
 
 	old_lb        = 0;
@@ -96,7 +96,8 @@ int MPID_Type_blockindexed(int count,
 	old_extent    = el_sz;
 	old_is_contig = 1;
 
-	new_dtp->size          = count * blocklength * el_sz;
+	new_dtp->size          = (MPI_Aint)(unsigned long)count * 
+	                         (MPI_Aint)(unsigned long)blocklength * el_sz;
 	new_dtp->has_sticky_lb = 0;
 	new_dtp->has_sticky_ub = 0;
 
@@ -123,7 +124,9 @@ int MPID_Type_blockindexed(int count,
 	old_extent    = old_dtp->extent;
 	old_is_contig = old_dtp->is_contig;
 
-	new_dtp->size           = count * blocklength * old_dtp->size;
+	new_dtp->size           = (MPI_Aint)(unsigned long)count * 
+	                          (MPI_Aint)(unsigned long)blocklength * 
+	                          (MPI_Aint)(unsigned long)old_dtp->size;
 	new_dtp->has_sticky_lb  = old_dtp->has_sticky_lb;
 	new_dtp->has_sticky_ub  = old_dtp->has_sticky_ub;
 
@@ -138,7 +141,7 @@ int MPID_Type_blockindexed(int count,
     /* priming for loop */
     eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[0] :
 	(((MPI_Aint) ((int *) displacement_array)[0]) * old_extent);
-    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength,
+    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint)(unsigned long)blocklength,
 			      eff_disp,
 			      old_lb,
 			      old_ub,
@@ -153,7 +156,7 @@ int MPID_Type_blockindexed(int count,
 
 	eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[i] :
 	    (((MPI_Aint) ((int *) displacement_array)[i]) * old_extent);
-	MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength,
+	MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint)(unsigned long)blocklength,
 				  eff_disp,
 				  old_lb,
 				  old_ub,
@@ -175,7 +178,7 @@ int MPID_Type_blockindexed(int count,
      * its size and extent are the same, and the old type was also
      * contiguous.
      */
-    if (old_is_contig && (new_dtp->size == new_dtp->extent))
+    if (old_is_contig && ((MPI_Aint)(unsigned long)new_dtp->size == new_dtp->extent))
     {
 	contig_count = MPIDI_Type_blockindexed_count_contig(count,
 							    blocklength,
@@ -216,11 +219,11 @@ int MPIDI_Type_blockindexed_count_contig(int count,
     }
     else
     {
-	int cur_bdisp = ((MPI_Aint *) disp_array)[0];
+	MPI_Aint cur_bdisp = ((MPI_Aint *) disp_array)[0];
 
 	for (i=1; i < count; i++)
 	{
-	    if (cur_bdisp + blklen * old_extent !=
+	    if (cur_bdisp + (MPI_Aint)(unsigned long)blklen * old_extent !=
 		((MPI_Aint *) disp_array)[i])
 	    {
 		contig_count++;
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_contiguous.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_contiguous.c
index 540379f..951590b 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_contiguous.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_contiguous.c
@@ -101,7 +101,7 @@ int MPID_Type_contiguous(int count,
 	new_dtp->has_sticky_ub  = old_dtp->has_sticky_ub;
 	new_dtp->has_sticky_lb  = old_dtp->has_sticky_lb;
 
-	MPID_DATATYPE_CONTIG_LB_UB(count,
+	MPID_DATATYPE_CONTIG_LB_UB((MPI_Aint)(unsigned long)count,
 				   old_dtp->lb,
 				   old_dtp->ub,
 				   old_dtp->extent,
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_create_pairtype.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_create_pairtype.c
index 55d2bea..1484b86 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_create_pairtype.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_create_pairtype.c
@@ -19,7 +19,9 @@
 	type_size   = sizeof(foo.a) + sizeof(foo.b);			\
 	type_extent = (MPI_Aint) sizeof(foo);				\
 	el_size = (sizeof(foo.a) == sizeof(foo.b)) ? (int) sizeof(foo.a) : -1; \
-	true_ub = ((char *) &foo.b - (char *) &foo.a) + (MPI_Aint) sizeof(foo.b); \
+	true_ub = (MPI_VOID_PTR_CAST_TO_MPI_AINT ((char *) &foo.b -     \
+                                                  (char *) &foo.a)) +   \
+                  (MPI_Aint) sizeof(foo.b);                             \
 	alignsize = MPIR_MAX(MPID_Datatype_get_basic_size(mt1_),	\
                              MPID_Datatype_get_basic_size(mt2_));	\
     }
@@ -164,8 +166,8 @@ int MPID_Type_create_pairtype(MPI_Datatype type,
 	    break;
     }
 				   
-    new_dtp->is_contig       = (type_size == type_extent) ? 1 : 0;
-    new_dtp->n_contig_blocks = (type_size == type_extent) ? 1 : 2;
+    new_dtp->is_contig       = ( ((MPI_Aint)(unsigned long)type_size) == type_extent) ? 1 : 0;
+    new_dtp->n_contig_blocks = ( ((MPI_Aint)(unsigned long)type_size) == type_extent) ? 1 : 2;
 
     /* fill in dataloops -- only case where we precreate dataloops
      *
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_debug.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_debug.c
index 74ec9ec..1e3c761 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_debug.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_debug.c
@@ -71,21 +71,21 @@ void MPIDI_Dataloop_dot_printf(MPID_Dataloop *loop_p,
     switch (loop_p->kind & DLOOP_KIND_MASK) {
 	case DLOOP_KIND_CONTIG:
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-	    "      dl%d [shape = record, label = \"contig |{ ct = %d; el_sz = %d; el_ext = %d }\"];",
+	    "      dl%d [shape = record, label = \"contig |{ ct = %d; el_sz = " MPI_AINT_FMT_DEC_SPEC "; el_ext = " MPI_AINT_FMT_DEC_SPEC " }\"];",
 			    depth,
 			    (int) loop_p->loop_params.c_t.count,
-			    (int) loop_p->el_size,
-			    (int) loop_p->el_extent));
+			    (MPI_Aint)loop_p->el_size,
+			    (MPI_Aint) loop_p->el_extent));
 	    break;
 	case DLOOP_KIND_VECTOR:
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-	    "      dl%d [shape = record, label = \"vector |{ ct = %d; blk = %d; str = %d; el_sz = %d; el_ext = %d }\"];",
+	    "      dl%d [shape = record, label = \"vector |{ ct = %d; blk = %d; str = " MPI_AINT_FMT_DEC_SPEC "; el_sz = " MPI_AINT_FMT_DEC_SPEC "; el_ext =  "MPI_AINT_FMT_DEC_SPEC " }\"];",
 			    depth,
 			    (int) loop_p->loop_params.v_t.count,
 			    (int) loop_p->loop_params.v_t.blocksize,
-			    (int) loop_p->loop_params.v_t.stride,
-			    (int) loop_p->el_size,
-			    (int) loop_p->el_extent));
+			    (MPI_Aint) loop_p->loop_params.v_t.stride,
+			    (MPI_Aint) loop_p->el_size,
+			    (MPI_Aint) loop_p->el_extent));
 	    break;
 	case DLOOP_KIND_INDEXED:
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
@@ -99,14 +99,14 @@ void MPIDI_Dataloop_dot_printf(MPID_Dataloop *loop_p,
 		if (i + 1 < loop_p->loop_params.i_t.count) {
 		    /* more regions after this one */
 		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-		    "(%d, %d), ",
-			  (int) loop_p->loop_params.i_t.offset_array[i],
+		    "(" MPI_AINT_FMT_DEC_SPEC ", %d), ",
+			  (MPI_Aint) loop_p->loop_params.i_t.offset_array[i],
 		          (int) loop_p->loop_params.i_t.blocksize_array[i]));
 		}
 		else {
 		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-		           "(%d, %d); ",
-		           (int) loop_p->loop_params.i_t.offset_array[i],
+		           "(" MPI_AINT_FMT_DEC_SPEC ", %d); ",
+		           (MPI_Aint) loop_p->loop_params.i_t.offset_array[i],
 			   (int) loop_p->loop_params.i_t.blocksize_array[i]));
 		}
 	    }
@@ -115,9 +115,9 @@ void MPIDI_Dataloop_dot_printf(MPID_Dataloop *loop_p,
 	    }
 
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-				       "el_sz = %d; el_ext = %d }\"];\n",
-				       (int) loop_p->el_size,
-				       (int) loop_p->el_extent));
+				       "el_sz = " MPI_AINT_FMT_DEC_SPEC "; el_ext = " MPI_AINT_FMT_DEC_SPEC " }\"];\n",
+				       (MPI_Aint) loop_p->el_size,
+				       (MPI_Aint) loop_p->el_extent));
 	    break;
 	case DLOOP_KIND_BLOCKINDEXED:
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
@@ -131,13 +131,13 @@ void MPIDI_Dataloop_dot_printf(MPID_Dataloop *loop_p,
 		if (i + 1 < loop_p->loop_params.bi_t.count) {
 		    /* more regions after this one */
 		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-		        "%d, ",
-			(int) loop_p->loop_params.bi_t.offset_array[i]));
+		        MPI_AINT_FMT_DEC_SPEC ", ",
+			(MPI_Aint) loop_p->loop_params.bi_t.offset_array[i]));
 		}
 		else {
 		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-		         "%d; ",
-		         (int) loop_p->loop_params.bi_t.offset_array[i]));
+		         MPI_AINT_FMT_DEC_SPEC "; ",
+		         (MPI_Aint) loop_p->loop_params.bi_t.offset_array[i]));
 		}
 	    }
 	    if (i < loop_p->loop_params.bi_t.count) {
@@ -145,9 +145,9 @@ void MPIDI_Dataloop_dot_printf(MPID_Dataloop *loop_p,
 	    }
 
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-				      "el_sz = %d; el_ext = %d }\"];",
-				       (int) loop_p->el_size,
-				       (int) loop_p->el_extent));
+				      "el_sz = " MPI_AINT_FMT_DEC_SPEC "; el_ext = " MPI_AINT_FMT_DEC_SPEC " }\"];",
+				       (MPI_Aint) loop_p->el_size,
+				       (MPI_Aint) loop_p->el_extent));
 	    break;
 	case DLOOP_KIND_STRUCT:
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
@@ -173,12 +173,12 @@ void MPIDI_Dataloop_dot_printf(MPID_Dataloop *loop_p,
 
 	    for (i=0; i < 3 && i < loop_p->loop_params.s_t.count; i++) {
 		if (i + 1 < loop_p->loop_params.s_t.count) {
-		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,"%d, ",
-			    (int) loop_p->loop_params.s_t.offset_array[i]));
+		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,MPI_AINT_FMT_DEC_SPEC ", ",
+			    (MPI_Aint) loop_p->loop_params.s_t.offset_array[i]));
 		}
 		else {
-		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,"%d; ",
-			    (int) loop_p->loop_params.s_t.offset_array[i]));
+		    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,MPI_AINT_FMT_DEC_SPEC "; ",
+			    (MPI_Aint) loop_p->loop_params.s_t.offset_array[i]));
 		}
 	    }
 	    if (i < loop_p->loop_params.s_t.count) {
@@ -270,18 +270,18 @@ void MPIDI_Datatype_printf(MPI_Datatype type,
 	MPIU_DBG_OUT(DATATYPE,"depth                   type         size       extent      true_lb      true_ub           lb(s)           ub(s)         disp       blklen\n");
 	MPIU_DBG_OUT(DATATYPE,"------------------------------------------------------------------------------------------------------------------------------------------\n");
     }
-    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,"%5d  %21s  %11d  %11d  %11d  %11d  %11d(%1d)  %11d(%1d)  %11d  %11d",
+    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,"%5d  %21s  %11d  " MPI_AINT_FMT_DEC_SPEC "  " MPI_AINT_FMT_DEC_SPEC "  " MPI_AINT_FMT_DEC_SPEC "  " MPI_AINT_FMT_DEC_SPEC "(" MPI_AINT_FMT_DEC_SPEC ")  " MPI_AINT_FMT_DEC_SPEC "(" MPI_AINT_FMT_DEC_SPEC ")  " MPI_AINT_FMT_DEC_SPEC "  %11d",
 		    depth,
 		    string,
 		    (int) size,
-		    (int) extent,
-		    (int) true_lb,
-		    (int) true_ub,
-		    (int) lb,
-		    (int) sticky_lb,
-		    (int) ub,
-		    (int) sticky_ub,
-		    (int) displacement,
+		    (MPI_Aint) extent,
+		    (MPI_Aint) true_lb,
+		    (MPI_Aint) true_ub,
+		    (MPI_Aint) lb,
+		    (MPI_Aint) sticky_lb,
+		    (MPI_Aint) ub,
+		    (MPI_Aint) sticky_ub,
+		    (MPI_Aint) displacement,
 		    (int) blocklength));
     return;
 }
@@ -456,15 +456,15 @@ void MPIDU_Datatype_debug(MPI_Datatype type,
     MPIU_Assert(dtp != NULL);
 
     MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-      "# Size = %d, Extent = %d, LB = %d%s, UB = %d%s, Extent = %d, Element Size = %d (%s), %s",
+      "# Size = %d, Extent = " MPI_AINT_FMT_DEC_SPEC ", LB = " MPI_AINT_FMT_DEC_SPEC "%s, UB = " MPI_AINT_FMT_DEC_SPEC "%s, Extent = " MPI_AINT_FMT_DEC_SPEC ", Element Size = " MPI_AINT_FMT_DEC_SPEC " (%s), %s",
 		    (int) dtp->size,
-		    (int) dtp->extent,
-		    (int) dtp->lb,
+		    (MPI_Aint) dtp->extent,
+		    (MPI_Aint) dtp->lb,
 		    (dtp->has_sticky_lb) ? "(sticky)" : "",
-		    (int) dtp->ub,
+		    (MPI_Aint) dtp->ub,
 		    (dtp->has_sticky_ub) ? "(sticky)" : "",
-		    (int) dtp->extent,
-		    (int) dtp->element_size,
+		    (MPI_Aint) dtp->extent,
+		    (MPI_Aint) dtp->element_size,
 		    dtp->element_size == -1 ? "multiple types" :
 		    MPIDU_Datatype_builtin_to_string(dtp->eltype),
 		    dtp->is_contig ? "is N contig" : "is not N contig"));
@@ -561,11 +561,11 @@ void MPIDI_Datatype_contents_printf(MPI_Datatype type,
 	    return;
         case MPI_COMBINER_HVECTOR:
 	    MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-	                  "# %shvector ct = %d, blk = %d, str = %d\n",
+	                  "# %shvector ct = %d, blk = %d, str = " MPI_AINT_FMT_DEC_SPEC "\n",
 			    MPIDI_Datatype_depth_spacing(depth),
 			    ints[0],
 			    ints[1],
-			    (int) aints[0]));
+			    (MPI_Aint) aints[0]));
 	    MPIDI_Datatype_contents_printf(*types,
 					   depth + 1,
 					   acount);
@@ -592,11 +592,11 @@ void MPIDI_Datatype_contents_printf(MPI_Datatype type,
 			    ints[0]));
 	    for (i=0; i < acount && i < ints[0]; i++) {
 		MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-		            "# %s  hindexed [%d]: blk = %d, disp = %d\n",
+		            "# %s  hindexed [%d]: blk = %d, disp = " MPI_AINT_FMT_DEC_SPEC "\n",
 				MPIDI_Datatype_depth_spacing(depth),
 				i,
 				(int) ints[i+1],
-				(int) aints[i]));
+				(MPI_Aint) aints[i]));
 		MPIDI_Datatype_contents_printf(*types,
 					       depth + 1,
 					       acount);
@@ -608,11 +608,11 @@ void MPIDI_Datatype_contents_printf(MPI_Datatype type,
 			    (int) ints[0]));
 	    for (i=0; i < acount && i < ints[0]; i++) {
 		MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,
-		           "# %s  struct[%d]: blk = %d, disp = %d\n",
+		           "# %s  struct[%d]: blk = %d, disp = " MPI_AINT_FMT_DEC_SPEC "\n",
 				MPIDI_Datatype_depth_spacing(depth),
 				i,
 				(int) ints[i+1],
-				(int) aints[i]));
+				(MPI_Aint) aints[i]));
 		MPIDI_Datatype_contents_printf(types[i],
 					       depth + 1,
 					       acount);
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_indexed.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_indexed.c
index be21c21..73d5d74 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_indexed.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_indexed.c
@@ -102,16 +102,16 @@ int MPID_Type_indexed(int count,
 
 	old_lb        = 0;
 	old_true_lb   = 0;
-	old_ub        = el_sz;
-	old_true_ub   = el_sz;
-	old_extent    = el_sz;
+	old_ub        = (MPI_Aint)(unsigned long)el_sz;
+	old_true_ub   = (MPI_Aint)(unsigned long)el_sz;
+	old_extent    = (MPI_Aint)(unsigned long)el_sz;
 	old_is_contig = 1;
 
 	new_dtp->has_sticky_ub = 0;
 	new_dtp->has_sticky_lb = 0;
 
 	new_dtp->alignsize    = el_sz; /* ??? */
-	new_dtp->element_size = el_sz;
+	new_dtp->element_size = (MPI_Aint)(unsigned long)el_sz;
 	new_dtp->eltype       = el_type;
 
 	new_dtp->n_contig_blocks = count;
@@ -122,6 +122,10 @@ int MPID_Type_indexed(int count,
 	MPID_Datatype *old_dtp;
 
 	MPID_Datatype_get_ptr(oldtype, old_dtp);
+
+	/* Ensure that "element_size" fits into an int datatype and is positive. */
+	MPID_Ensure_Aint_fits_in_positive_int( old_dtp->element_size );
+
 	el_sz   = old_dtp->element_size;
 	old_sz  = old_dtp->size;
 	el_ct   = old_dtp->n_elements;
@@ -136,7 +140,7 @@ int MPID_Type_indexed(int count,
 
 	new_dtp->has_sticky_lb = old_dtp->has_sticky_lb;
 	new_dtp->has_sticky_ub = old_dtp->has_sticky_ub;
-	new_dtp->element_size  = el_sz;
+	new_dtp->element_size  = (MPI_Aint)(unsigned long)el_sz;
 	new_dtp->eltype        = el_type;
 
 	new_dtp->n_contig_blocks = old_dtp->n_contig_blocks * count;
@@ -156,7 +160,7 @@ int MPID_Type_indexed(int count,
     eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[i] :
 	(((MPI_Aint) ((int *) displacement_array)[i]) * old_extent);
     
-    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength_array[i],
+    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint)(unsigned long)blocklength_array[i],
 			      eff_disp,
 			      old_lb,
 			      old_ub,
@@ -178,7 +182,7 @@ int MPID_Type_indexed(int count,
 		(((MPI_Aint) ((int *) displacement_array)[i]) * old_extent);
 	
 	    /* calculate ub and lb for this block */
-	    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength_array[i],
+	    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint)(unsigned long)(blocklength_array[i]),
 				      eff_disp,
 				      old_lb,
 				      old_ub,
@@ -211,7 +215,7 @@ int MPID_Type_indexed(int count,
 						   dispinbytes,
 						   old_extent);
     
-    if ((contig_count == 1) && (new_dtp->size == new_dtp->extent))
+    if ((contig_count == 1) && ((MPI_Aint)(unsigned long)new_dtp->size == new_dtp->extent))
     {
 	new_dtp->is_contig = old_is_contig;
     }
@@ -274,7 +278,7 @@ int MPIDI_Type_indexed_count_contig(int count,
 	    {
 		continue;
 	    }
-	    else if (cur_bdisp + cur_blklen * old_extent ==
+	    else if (cur_bdisp + (MPI_Aint)(unsigned long)cur_blklen * old_extent ==
 		     ((MPI_Aint *) displacement_array)[i])
 	    {
 		/* adjacent to current block; add to block */
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_struct.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_struct.c
index f0f0ca0..2c72b60 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_struct.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_struct.c
@@ -228,11 +228,11 @@ int MPID_Type_struct(int count,
 	    tmp_el_sz   = MPID_Datatype_get_basic_size(oldtype_array[i]);
 	    tmp_el_type = oldtype_array[i];
 
-	    MPID_DATATYPE_BLOCK_LB_UB(blocklength_array[i],
+	    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint)(unsigned long)(blocklength_array[i]),
 				      displacement_array[i],
 				      0,
-				      tmp_el_sz,
-				      tmp_el_sz,
+				      (MPI_Aint)(unsigned long)tmp_el_sz,
+				      (MPI_Aint)(unsigned long)tmp_el_sz,
 				      tmp_lb,
 				      tmp_ub);
 	    tmp_true_lb = tmp_lb;
@@ -246,10 +246,13 @@ int MPID_Type_struct(int count,
 	{
 	    MPID_Datatype_get_ptr(oldtype_array[i], old_dtp);
 
+	    /* Ensure that "element_size" fits into an int datatype and is positive. */
+	    MPID_Ensure_Aint_fits_in_positive_int( old_dtp->element_size );
+
 	    tmp_el_sz   = old_dtp->element_size;
 	    tmp_el_type = old_dtp->eltype;
 
-	    MPID_DATATYPE_BLOCK_LB_UB(blocklength_array[i],
+	    MPID_DATATYPE_BLOCK_LB_UB((MPI_Aint)(unsigned long)blocklength_array[i],
 				      displacement_array[i],
 				      old_dtp->lb,
 				      old_dtp->ub,
@@ -356,7 +359,7 @@ int MPID_Type_struct(int count,
     }
 
     new_dtp->n_elements = -1; /* TODO */
-    new_dtp->element_size = el_sz;
+    new_dtp->element_size = (MPI_Aint)(unsigned long)el_sz;
     new_dtp->eltype = el_type;
 
     new_dtp->has_sticky_lb = found_sticky_lb;
@@ -376,11 +379,11 @@ int MPID_Type_struct(int count,
     {
 	/* account for padding */
 	MPI_Aint epsilon = (new_dtp->alignsize > 0) ?
-	    new_dtp->extent % new_dtp->alignsize : 0;
+	    new_dtp->extent % ((MPI_Aint)(unsigned long)(new_dtp->alignsize)) : 0;
 
 	if (epsilon)
 	{
-	    new_dtp->ub    += (new_dtp->alignsize - epsilon);
+	    new_dtp->ub    += ((MPI_Aint)(unsigned long)(new_dtp->alignsize) - epsilon);
 	    new_dtp->extent = new_dtp->ub - new_dtp->lb;
 	}
     }
@@ -391,8 +394,8 @@ int MPID_Type_struct(int count,
      * same, and the old type was also contiguous, and we didn't see
      * something noncontiguous based on true ub/ub.
      */
-    if ((new_dtp->size == new_dtp->extent) && old_are_contig &&
-	(! definitely_not_contig))
+    if (((MPI_Aint)(unsigned long)(new_dtp->size) == new_dtp->extent) && 
+	old_are_contig && (! definitely_not_contig))
     {
 	new_dtp->is_contig = 1;
     }
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_vector.c b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_vector.c
index 46417a1..97ecfe8 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_vector.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/mpid_type_vector.c
@@ -76,7 +76,7 @@ int MPID_Type_vector(int count,
     is_builtin = (HANDLE_GET_KIND(oldtype) == HANDLE_KIND_BUILTIN);
 
     if (is_builtin) {
-	el_sz   = MPID_Datatype_get_basic_size(oldtype);
+	el_sz   = (MPI_Aint)(unsigned long)MPID_Datatype_get_basic_size(oldtype);
 	el_type = oldtype;
 
 	old_lb        = 0;
@@ -87,7 +87,8 @@ int MPID_Type_vector(int count,
 	old_extent    = el_sz;
 	old_is_contig = 1;
 
-	new_dtp->size           = count * blocklength * el_sz;
+	new_dtp->size           = (MPI_Aint)(unsigned long)count * 
+	                          (MPI_Aint)(unsigned long)blocklength * el_sz;
 	new_dtp->has_sticky_lb  = 0;
 	new_dtp->has_sticky_ub  = 0;
 
@@ -129,9 +130,9 @@ int MPID_Type_vector(int count,
 	eff_stride = (strideinbytes) ? stride : (stride * old_dtp->extent);
     }
 
-    MPID_DATATYPE_VECTOR_LB_UB(count,
+    MPID_DATATYPE_VECTOR_LB_UB((MPI_Aint)(unsigned long)count,
 			       eff_stride,
-			       blocklength,
+			       (MPI_Aint)(unsigned long)blocklength,
 			       old_lb,
 			       old_ub,
 			       old_extent,
@@ -145,8 +146,8 @@ int MPID_Type_vector(int count,
      * size and extent of new type are equivalent, and stride is
      * equal to blocklength * size of old type.
      */
-    if (new_dtp->size == new_dtp->extent &&
-	eff_stride == blocklength * old_sz &&
+    if ((MPI_Aint)(unsigned long)(new_dtp->size) == new_dtp->extent &&
+	eff_stride == (MPI_Aint)(unsigned long)blocklength * old_sz &&
 	old_is_contig)
     {
 	new_dtp->is_contig = 1;
diff --git a/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_rma_common.c b/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_rma_common.c
index f3a8756..8603f8e 100644
--- a/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_rma_common.c
+++ b/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_rma_common.c
@@ -83,7 +83,8 @@ unsigned mpid_my_lpid = -1;
  * \param[out] dti	Pointer to datatype info struct
  */
 void make_dt_map_vec(MPI_Datatype dt, mpid_dt_info *dti) {
-        int nb, last;
+        int nb;
+	DLOOP_Offset last;
         MPID_Segment seg;
         MPID_Type_map *mv;
         DLOOP_VECTOR *iv;
-- 
1.5.3.7




More information about the mpich2-dev mailing list