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

Jeff Parker jjparker at us.ibm.com
Fri Mar 7 10:29:10 CST 2008


This is a continuation of changes to the high-level MPICH2 datatype modules
for supporting an 8-byte MPI_Aint on a 32-bit platform.  Recall from
previous posts that this work is currently being done on a 1.0.7rc1 base,
and may contain other Blue Gene/P-specific patches that are being
worked separately.  At this time, these patches are being made available
to the mpich2-dev mailing list for comment.

Signed-off-by: Jeff Parker <jjparker at us.ibm.com>
---
 .../mpich2/src/mpi/datatype/type_create_darray.c   |   19 +++++++++++++++--
 .../mpich2/src/mpi/datatype/type_create_resized.c  |    9 +++++--
 .../mpich2/src/mpi/datatype/type_create_struct.c   |    2 +-
 .../mpich2/src/mpi/datatype/type_create_subarray.c |   21 ++++++++++++++++---
 .../mpich2/src/mpi/datatype/type_get_true_extent.c |    4 +-
 lib/mpi/mpich2/src/mpi/datatype/type_hvector.c     |    4 ++-
 lib/mpi/mpich2/src/mpi/datatype/type_lb.c          |    2 +-
 lib/mpi/mpich2/src/mpi/datatype/type_ub.c          |    2 +-
 lib/mpi/mpich2/src/mpi/datatype/unpack.c           |    3 ++
 lib/mpi/mpich2/src/mpi/datatype/unpack_external.c  |   13 ++++++++---
 lib/mpi/mpich2/src/mpi/errhan/errnames.txt         |   14 ++++++++++--
 .../src/mpid/common/datatype/mpid_type_indexed.c   |    5 ++-
 12 files changed, 73 insertions(+), 25 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 1a16ad9..c27174b 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_create_darray.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_create_darray.c
@@ -373,6 +373,11 @@ int MPI_Type_create_darray(int size,
     MPI_Aint *st_offsets, orig_extent, disps[3];
     MPI_Datatype type_old, type_new = MPI_DATATYPE_NULL, types[3];
 
+#   ifdef HAVE_ERROR_CHECKING
+    MPI_Aint   size_with_aint;
+    MPI_Offset size_with_offset;
+#   endif
+
     int *ints;
     MPID_Datatype *datatype_ptr = NULL;
     MPIU_THREADPRIV_DECL;
@@ -472,7 +477,7 @@ int MPI_Type_create_darray(int size,
 	    }
 
 	    /* TODO: GET THIS CHECK IN ALSO */
-#if 0
+#if 1
 	    /* check if MPI_Aint is large enough for size of global array. 
 	       if not, complain. */
 	    
@@ -481,8 +486,16 @@ int MPI_Type_create_darray(int size,
 	    size_with_offset = orig_extent;
 	    for (i=0; i<ndims; i++) size_with_offset *= array_of_gsizes[i];
 	    if (size_with_aint != size_with_offset) {
-		FPRINTF(stderr, "MPI_Type_create_darray: Can't use an array of this size unless the MPI implementation defines a 64-bit MPI_Aint\n");
-		MPI_Abort(MPI_COMM_WORLD, 1);
+		/* FPRINTF(stderr, "MPI_Type_create_darray: Can't use an array of this size unless the MPI implementation defines a 64-bit MPI_Aint\n"); */
+		/* MPI_Abort(MPI_COMM_WORLD, 1); */
+		mpi_errno = MPIR_Err_create_code(MPI_SUCCESS,
+						 MPIR_ERR_FATAL,
+						 FCNAME,
+						 __LINE__,
+						 MPI_ERR_ARG,
+						 "**darrayoverflow",
+						 "**darrayoverflow %L",
+						 size_with_offset);
 	    }
 #endif	    
 
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_create_resized.c b/lib/mpi/mpich2/src/mpi/datatype/type_create_resized.c
index 27f109e..991fe8d 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_create_resized.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_create_resized.c
@@ -34,8 +34,8 @@
 
    Input Parameters:
 + oldtype - input datatype (handle) 
-. lb - new lower bound of datatype (integer) 
-- extent - new extent of datatype (integer) 
+. lb - new lower bound of datatype (address integer) 
+- extent - new extent of datatype (address integer) 
 
    Output Parameter:
 . newtype - output datatype (handle) 
@@ -120,7 +120,10 @@ int MPI_Type_create_resized(MPI_Datatype oldtype,
     {
 	mpi_errno = MPIR_Err_create_code(
 	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_create_resized",
-	    "**mpi_type_create_resized %D %d %d %p", oldtype, lb, extent, newtype);
+	    "**mpi_type_create_resized %D %L %L %p", oldtype, 
+	    MPI_AINT_CAST_TO_LONG_LONG lb, 
+	    MPI_AINT_CAST_TO_LONG_LONG extent, 
+	    newtype);
     }
 #   endif
     mpi_errno = MPIR_Err_return_comm( NULL, FCNAME, mpi_errno );
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_create_struct.c b/lib/mpi/mpich2/src/mpi/datatype/type_create_struct.c
index 2e9f1fa..baf73dd 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_create_struct.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_create_struct.c
@@ -36,7 +36,7 @@
 + count - number of blocks (integer) --- also number of entries in arrays 
   array_of_types, array_of_displacements and array_of_blocklengths 
 . array_of_blocklength - number of elements in each block (array of integer) 
-. array_of_displacements - byte displacement of each block (array of integer) 
+. array_of_displacements - byte displacement of each block (array of address integer) 
 - array_of_types - type of elements in each block (array of handles to 
   datatype objects) 
 
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 7957c3e..460a6b6 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_create_subarray.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_create_subarray.c
@@ -70,6 +70,11 @@ int MPI_Type_create_subarray(int ndims,
     int blklens[3];
     MPI_Datatype tmp1, tmp2, types[3];
 
+#   ifdef HAVE_ERROR_CHECKING
+    MPI_Aint   size_with_aint;
+    MPI_Offset size_with_offset;
+#   endif
+
     /* for saving contents */
     int *ints;
     MPID_Datatype *new_dtp;
@@ -140,7 +145,7 @@ int MPI_Type_create_subarray(int ndims,
 						 "order");
 	    }
 
-#if 0
+#if 1
 	    /* TODO: INTEGRATE THIS CHECK AS WELL */
 	    NMPI_Type_extent(oldtype, &extent);
 
@@ -152,9 +157,17 @@ int MPI_Type_create_subarray(int ndims,
 	    size_with_offset = extent;
 	    for (i=0; i<ndims; i++) size_with_offset *= array_of_sizes[i];
 	    if (size_with_aint != size_with_offset) {
-		FPRINTF(stderr, "MPI_Type_create_subarray: Can't use an array of this size unless the MPI implementation defines a 64-bit MPI_Aint\n");
-		MPI_Abort(MPI_COMM_WORLD, 1);
-    }
+		/* FPRINTF(stderr, "MPI_Type_create_subarray: Can't use an array of this size unless the MPI implementation defines a 64-bit MPI_Aint\n"); */
+		/* MPI_Abort(MPI_COMM_WORLD, 1); */
+		mpi_errno = MPIR_Err_create_code(MPI_SUCCESS,
+						 MPIR_ERR_FATAL,
+						 FCNAME,
+						 __LINE__,
+						 MPI_ERR_ARG,
+						 "**subarrayoflow",
+						 "**subarrayoflow %L",
+						 size_with_offset);
+            }
 #endif
 
             /* Validate datatype_ptr */
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_get_true_extent.c b/lib/mpi/mpich2/src/mpi/datatype/type_get_true_extent.c
index 2bf026f..250780d 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_get_true_extent.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_get_true_extent.c
@@ -38,8 +38,8 @@
 . datatype - datatype to get information on (handle) 
 
    Output Parameters:
-+ true_lb - true lower bound of datatype (integer) 
-- true_extent - true size of datatype (integer) 
++ true_lb - true lower bound of datatype (address integer) 
+- true_extent - true size of datatype (address integer) 
 
 .N SignalSafe
 
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_hvector.c b/lib/mpi/mpich2/src/mpi/datatype/type_hvector.c
index b0bac32..8e6f87b 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_hvector.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_hvector.c
@@ -120,7 +120,9 @@ int MPI_Type_hvector(int count,
     {
 	mpi_errno = MPIR_Err_create_code(
 	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_hvector",
-	    "**mpi_type_hvector %d %d %d %D %p", count, blocklen, stride, old_type, newtype_p);
+	    "**mpi_type_hvector %d %d %L %D %p", count, blocklen, 
+	    MPI_AINT_CAST_TO_LONG_LONG stride, 
+	    old_type, newtype_p);
     }
 #   endif
     mpi_errno = MPIR_Err_return_comm( NULL, FCNAME, mpi_errno );
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_lb.c b/lib/mpi/mpich2/src/mpi/datatype/type_lb.c
index 4dcb55b..4ffbd5c 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_lb.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_lb.c
@@ -38,7 +38,7 @@ Input Parameters:
 
 Output Parameter:
 . displacement - displacement of lower bound from origin, 
-                             in bytes (integer) 
+                             in bytes (address integer) 
 
 .N Deprecated
 The replacement for this routine is 'MPI_Type_Get_extent'.
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_ub.c b/lib/mpi/mpich2/src/mpi/datatype/type_ub.c
index 1779138..4f6be3a 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_ub.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_ub.c
@@ -38,7 +38,7 @@ Input Parameters:
 
 Output Parameter:
 . displacement - displacement of upper bound from origin, 
-                             in bytes (integer) 
+                             in bytes (address integer) 
 
 .N Deprecated
 The replacement for this routine is 'MPI_Type_get_extent'
diff --git a/lib/mpi/mpich2/src/mpi/datatype/unpack.c b/lib/mpi/mpich2/src/mpi/datatype/unpack.c
index dcffdd5..3018ba7 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/unpack.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/unpack.c
@@ -138,6 +138,9 @@ int MPI_Unpack(void *inbuf, int insize, int *position,
 			&last,
 			(void *) ((char *) inbuf + *position));
 
+    /* Ensure that "last" fits into an int datatype and is positive. */
+    MPID_Ensure_Aint_fits_in_positive_int( last );
+
     *position += (int) last;
 
     MPID_Segment_free(segp);
diff --git a/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c b/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c
index 9bfe6db..3a17994 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/unpack_external.c
@@ -35,12 +35,12 @@
    Input Parameters:
 + datarep - data representation (string)  
 . inbuf - input buffer start (choice)  
-. insize - input buffer size, in bytes (integer)  
+. insize - input buffer size, in bytes (address integer)  
 . outcount - number of output data items (integer)  
 . datatype - datatype of output data item (handle)  
 
    Input/Output Parameter:
-. position - current position in buffer, in bytes (integer)  
+. position - current position in buffer, in bytes (address integer)  
 
    Output Parameter:
 . outbuf - output buffer start (choice)  
@@ -118,12 +118,15 @@ int MPI_Unpack_external(char *datarep,
     first = 0;
     last  = SEGMENT_IGNORE_LAST;
 
+    /* Ensure that position fits in a pointer */
+    MPID_Ensure_Aint_fits_in_pointer( *position );
+
     MPID_Segment_unpack_external32(segp,
 				   first,
 				   &last,
 				   (void *) ((char *) inbuf + *position));
 
-    *position += (int) last;
+    *position += last;
 
     MPID_Segment_free(segp);
     if (mpi_errno != MPI_SUCCESS) goto fn_fail;
@@ -140,7 +143,9 @@ int MPI_Unpack_external(char *datarep,
     {
 	mpi_errno = MPIR_Err_create_code(
 	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_unpack_external",
-	    "**mpi_unpack_external %s %p %d %p %p %d %D", datarep, inbuf, insize, position, outbuf, outcount, datatype);
+	    "**mpi_unpack_external %s %p %L %p %p %d %D", datarep, inbuf, 
+	    MPI_AINT_CAST_TO_LONG_LONG insize, 
+	    position, outbuf, outcount, datatype);
     }
 #   endif
     mpi_errno = MPIR_Err_return_comm( NULL, FCNAME, mpi_errno );
diff --git a/lib/mpi/mpich2/src/mpi/errhan/errnames.txt b/lib/mpi/mpich2/src/mpi/errhan/errnames.txt
index c4ba160..597caad 100644
--- a/lib/mpi/mpich2/src/mpi/errhan/errnames.txt
+++ b/lib/mpi/mpich2/src/mpi/errhan/errnames.txt
@@ -248,6 +248,10 @@ be in the range 0 to %d
       dimension of the grid must be 1
 **darraydist %d %d:For MPI_DISTRIBUTE_NONE, the value of array_of_psizes[%d] \
  is %d but must have value 1
+**darrayoverflow:Cannot use an array of this size unless the MPI implementation \
+ defines a 64-bit MPI_Aint
+**darrayoverflow %L:Total size of array_of_gsizes[] is %L which requires the MPI \
+ implementation to use a 64-bit MPI_Aint
 **darrayunknown:Unknown distribution type 
 **darrayblock:Value of m must be positive for block(m) distribution
 **darrayblock %d:Value of m in block(m) distribution is %d must must be \
@@ -260,6 +264,10 @@ be in the range 0 to %d
 **darraycyclic:Value of m must be positive for a cyclic(m) distribution
 **darraycyclic %d:Value of m is %d but must be positive for a cyclic(m) \
  distribution
+**subarrayoflow:Cannot use an array of this size unless the MPI implementation \
+ defines a 64-bit MPI_Aint
+**subarrayoflow %L:Total size of array_of_sizes[] is %L which requires the MPI \
+ implementation to use a 64-bit MPI_Aint
 **argposneg:Value of position must be nonnegative
 **argposneg %d:Value of position is %d but must be nonnegative
 **argpackbuf:Pack buffer is too small for data
@@ -986,7 +994,7 @@ with MPI_Alloc_mem.
 **mpi_type_vector:MPI_Type_vector failed
 **mpi_type_vector %d %d %d %D %p:MPI_Type_vector(count=%d, blocklength=%d, stride=%d, %D, new_type_p=%p) failed
 **mpi_type_hvector:MPI_Type_hvector failed
-**mpi_type_hvector %d %d %d %D %p:MPI_Type_hvector(count=%d, blocklen=%d, stride=%d, %D, new_type_p=%p) failed
+**mpi_type_hvector %d %d %L %D %p:MPI_Type_hvector(count=%d, blocklen=%d, stride=%L, %D, new_type_p=%p) failed
 **mpi_type_indexed:MPI_Type_indexed failed
 **mpi_type_indexed %d %p %p %D %p:MPI_Type_indexed(count=%d, blocklens=%p, indices=%p, %D, new_type_p=%p) failed
 **mpi_type_hindexed:MPI_Type_hindexed failed
@@ -1355,7 +1363,7 @@ with MPI_Alloc_mem.
 **mpi_type_create_indexed_block:MPI_Type_create_indexed_block failed
 **mpi_type_create_indexed_block %d %d %p %D %p:MPI_Type_create_indexed_block(count=%d, blocklength=%d, array_of_displacements=%p, %D, newtype=%p) failed
 **mpi_type_create_resized:MPI_Type_create_resized failed
-**mpi_type_create_resized %D %d %d %p:MPI_Type_create_resized(%D, lb=%d, extent=%d, newtype=%p) failed
+**mpi_type_create_resized %D %L %L %p:MPI_Type_create_resized(%D, lb=%L, extent=%L, newtype=%p) failed
 **mpi_type_create_struct:MPI_Type_create_struct failed
 **mpi_type_create_struct %d %p %p %p %p:MPI_Type_create_struct(count=%d, array_of_blocklengths=%p, array_of_displacements=%p, array_of_types=%p, newtype=%p) failed
 **mpi_type_create_subarray:MPI_Type_create_subarray failed
@@ -1366,7 +1374,7 @@ with MPI_Alloc_mem.
 **mpi_type_get_true_extent %D %p %p:MPI_Type_get_true_extent(%D, lb=%p, true_extent=%p) failed
 **mpi_type_test:MPI_Type_test failed
 **mpi_unpack_external:MPI_Unpack_external failed
-**mpi_unpack_external %s %p %d %p %p %d %D:MPI_Unpack_external(datarep=%s, inbuf=%p, insize=%d, position=%p, outbuf=%p, outcount=%d, %D) failed
+**mpi_unpack_external %s %p %L %p %p %d %D:MPI_Unpack_external(datarep=%s, inbuf=%p, insize=%L, position=%p, outbuf=%p, outcount=%d, %D) failed
 **mpi_win_create_errhandler:MPI_Win_create_errhandler failed
 **mpi_win_create_errhandler %p %p:MPI_Win_create_errhandler(function=%p, errhandler=%p) failed
 **mpi_win_get_errhandler:MPI_Win_get_errhandler failed
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 f846562..be21c21 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
@@ -25,8 +25,9 @@ int MPIDI_Type_indexed_count_contig(int count,
 . blocklength_array - number of elements in each block
 . displacement_array - offsets of blocks from start of type (see next
   parameter for units)
-. dispinbytes - if nonzero, then displacements are in bytes, otherwise
-  they in terms of extent of oldtype
+. dispinbytes - if nonzero, then displacements are in bytes (the 
+  displacement_array is an array of ints), otherwise they in terms of 
+  extent of oldtype (the displacement_array is an array of MPI_Aints)
 - oldtype - type (using handle) of datatype on which new type is based
 
   Output Parameters:
-- 
1.5.4.3




More information about the mpich2-dev mailing list