[mpich2-dev] [PATCH 1/1] Issue 4120: mpi attr changes for MPI_Aint

Jeff Parker jjparker at us.ibm.com
Wed Mar 19 16:43:42 CDT 2008


These are primarily changes to src/mpi/attr for the MPI_Aint work.  They
add casting necessary to ensure correct results when MPI_Aint is larger than
a pointer.

Signed-off-by: Jeff Parker <jjparker at us.ibm.com>
---
 lib/mpi/mpich2/src/mpi/attr/attr_get.c             |    2 +-
 lib/mpi/mpich2/src/mpi/attr/attrutil.c             |   12 ++++++------
 lib/mpi/mpich2/src/mpi/attr/comm_get_attr.c        |    2 +-
 lib/mpi/mpich2/src/mpi/attr/type_get_attr.c        |    2 +-
 lib/mpi/mpich2/src/mpi/attr/win_get_attr.c         |    4 ++--
 .../mpid/common/datatype/dataloop/segment_ops.c    |    4 ++--
 .../src/mpid/common/datatype/dataloop/veccpy.h     |    4 ++--
 .../mpich2/src/mpid/dcmf/src/onesided/mpid_put.c   |    3 ++-
 8 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/lib/mpi/mpich2/src/mpi/attr/attr_get.c b/lib/mpi/mpich2/src/mpi/attr/attr_get.c
index 2dc717f..095c979 100644
--- a/lib/mpi/mpich2/src/mpi/attr/attr_get.c
+++ b/lib/mpi/mpich2/src/mpi/attr/attr_get.c
@@ -94,7 +94,7 @@ int MPI_Attr_get(MPI_Comm comm, int keyval, void *attr_value, int *flag)
 	       should have been used.  We can test for this specific
 	       case.  Note that this code assumes sizeof(MPI_Aint) is 
 	       a power of 2. */
-	    if ((MPI_Aint)attr_value & (sizeof(MPI_Aint)-1)) {
+	    if (MPI_VOID_PTR_CAST_TO_MPI_AINT attr_value & (sizeof(MPI_Aint)-1)) {
 		MPIU_ERR_SET(mpi_errno,MPI_ERR_ARG,"**attrnotptr");
 	    }
 #           endif
diff --git a/lib/mpi/mpich2/src/mpi/attr/attrutil.c b/lib/mpi/mpich2/src/mpi/attr/attrutil.c
index 9e32d70..99497b5 100644
--- a/lib/mpi/mpich2/src/mpi/attr/attrutil.c
+++ b/lib/mpi/mpich2/src/mpi/attr/attrutil.c
@@ -119,7 +119,7 @@ int MPIR_Call_attr_delete( int handle, MPID_Attribute *attr_p )
                    are MPI_Fint values, and we assume 
 		   sizeof(MPI_Fint) <= sizeof(MPI_Aint).  
 		   See also src/binding/f77/attr_getf.c . */
-		fvalue  = (MPI_Fint) (MPI_Aint)(attr_p->value);
+		fvalue  = (MPI_Fint) MPI_VOID_PTR_CAST_TO_MPI_AINT (attr_p->value);
 		fextra  = (MPI_Fint*) (attr_p->keyval->extra_state);
 		delfn.F77_DeleteFunction( &fhandle, &fkeyval, &fvalue, 
 					  fextra, &ierr );
@@ -141,7 +141,7 @@ int MPIR_Call_attr_delete( int handle, MPID_Attribute *attr_p )
 	    if (delfn.F90_DeleteFunction) {
 		fhandle = (MPI_Fint) (handle);
 		fkeyval = (MPI_Fint) (attr_p->keyval->handle);
-		fvalue  = (MPI_Aint) (attr_p->value);
+		fvalue  = MPI_VOID_PTR_CAST_TO_MPI_AINT (attr_p->value);
 		fextra  = (MPI_Aint*) (attr_p->keyval->extra_state );
 		delfn.F90_DeleteFunction( &fhandle, &fkeyval, &fvalue, 
 					  fextra, &ierr );
@@ -241,13 +241,13 @@ int MPIR_Attr_dup_list( int handle, MPID_Attribute *old_attrs,
 		    fkeyval = (MPI_Fint) (p->keyval->handle);
 		    /* The following cast can lose data on systems whose
 		       pointers are longer than integers */
-		    fvalue  = (MPI_Fint) (MPI_Aint)(p->value);
+		    fvalue  = (MPI_Fint) MPI_VOID_PTR_CAST_TO_MPI_AINT (p->value);
 		    fextra  = (MPI_Fint*) (p->keyval->extra_state );
 		    copyfn.F77_CopyFunction( &fhandle, &fkeyval, fextra,
 					     &fvalue, &fnew, &fflag, &ierr );
 		    if (ierr) mpi_errno = (int)ierr;
 		    flag      = fflag;
-		    new_value = (void *)(MPI_Aint)fnew;
+		    new_value = MPI_AINT_CAST_TO_VOID_PTR (MPI_Aint) fnew;
 		    /* --BEGIN ERROR HANDLING-- */
 		    if (mpi_errno != 0)
 		    {
@@ -264,13 +264,13 @@ int MPIR_Attr_dup_list( int handle, MPID_Attribute *old_attrs,
 		    MPI_Aint fvalue, fnew, *fextra;
 		    fhandle = (MPI_Fint) (handle);
 		    fkeyval = (MPI_Fint) (p->keyval->handle);
-		    fvalue  = (MPI_Aint) (p->value);
+		    fvalue  = MPI_VOID_PTR_CAST_TO_MPI_AINT (p->value);
 		    fextra  = (MPI_Aint*) (p->keyval->extra_state );
 		    copyfn.F90_CopyFunction( &fhandle, &fkeyval, fextra,
 					     &fvalue, &fnew, &fflag, &ierr );
 		    if (ierr) mpi_errno = (int)ierr;
 		    flag = fflag;
-		    new_value = (void *)fnew;
+		    new_value = MPI_AINT_CAST_TO_VOID_PTR fnew;
 		    /* --BEGIN ERROR HANDLING-- */
 		    if (mpi_errno != 0)
 		    {
diff --git a/lib/mpi/mpich2/src/mpi/attr/comm_get_attr.c b/lib/mpi/mpich2/src/mpi/attr/comm_get_attr.c
index 3b8ba17..ce5c836 100644
--- a/lib/mpi/mpich2/src/mpi/attr/comm_get_attr.c
+++ b/lib/mpi/mpich2/src/mpi/attr/comm_get_attr.c
@@ -86,7 +86,7 @@ int MPI_Comm_get_attr(MPI_Comm comm, int comm_keyval, void *attribute_val, int *
 	       should have been used.  We can test for this specific
 	       case.  Note that this code assumes sizeof(MPI_Aint) is 
 	       a power of 2. */
-	    if ((MPI_Aint)attribute_val & (sizeof(MPI_Aint)-1)) {
+	    if (MPI_VOID_PTR_CAST_TO_MPI_AINT attribute_val & (sizeof(MPI_Aint)-1)) {
 		MPIU_ERR_SET(mpi_errno,MPI_ERR_ARG,"**attrnotptr");
 	    }
 #           endif
diff --git a/lib/mpi/mpich2/src/mpi/attr/type_get_attr.c b/lib/mpi/mpich2/src/mpi/attr/type_get_attr.c
index b21bfe9..7547bbb 100644
--- a/lib/mpi/mpich2/src/mpi/attr/type_get_attr.c
+++ b/lib/mpi/mpich2/src/mpi/attr/type_get_attr.c
@@ -88,7 +88,7 @@ int MPI_Type_get_attr(MPI_Datatype type, int type_keyval, void *attribute_val,
 	       should have been used.  We can test for this specific
 	       case.  Note that this code assumes sizeof(MPI_Aint) is 
 	       a power of 2. */
-	    if ((MPI_Aint)attribute_val & (sizeof(MPI_Aint)-1)) {
+	    if (MPI_VOID_PTR_CAST_TO_MPI_AINT attribute_val & (sizeof(MPI_Aint)-1)) {
 		MPIU_ERR_SET(mpi_errno,MPI_ERR_ARG,"**attrnotptr");
 	    }
 #           endif
diff --git a/lib/mpi/mpich2/src/mpi/attr/win_get_attr.c b/lib/mpi/mpich2/src/mpi/attr/win_get_attr.c
index 46dcd0a..5fbef66 100644
--- a/lib/mpi/mpich2/src/mpi/attr/win_get_attr.c
+++ b/lib/mpi/mpich2/src/mpi/attr/win_get_attr.c
@@ -84,7 +84,7 @@ int MPI_Win_get_attr(MPI_Win win, int win_keyval, void *attribute_val,
 	       should have been used.  We can test for this specific
 	       case.  Note that this code assumes sizeof(MPI_Aint) is 
 	       a power of 2. */
-	    if ((MPI_Aint)attribute_val & (sizeof(MPI_Aint)-1)) {
+	    if (MPI_VOID_PTR_CAST_TO_MPI_AINT attribute_val & (sizeof(MPI_Aint)-1)) {
 		MPIU_ERR_SET(mpi_errno,MPI_ERR_ARG,"**attrnotptr");
 	    }
 #           endif
@@ -152,7 +152,7 @@ int MPI_Win_get_attr(MPI_Win win, int win_keyval, void *attribute_val,
 	case 2: /* Fortran BASE */
 	    /* The Fortran routine that matches this routine should
 	       provide an address-sized integer, not an MPI_Fint */
-	    *attr_int = (MPI_Aint)(win_ptr->base);
+	    *attr_int = MPI_VOID_PTR_CAST_TO_MPI_AINT (win_ptr->base);
 	    break;
 	case 4: /* Fortran SIZE */
 	    /* We do not need to copy because we return the value,
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 294e3d0..982de22 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
@@ -602,7 +602,7 @@ static int DLOOP_Segment_contig_mpi_flatten(DLOOP_Offset *blocks_p,
 	paramp->blklens[last_idx] += size;
     }
     else {
-	paramp->disps[last_idx+1]   = (MPI_Aint) ((char *) bufp + rel_off);
+	paramp->disps[last_idx+1]   = MPI_VOID_PTR_CAST_TO_MPI_AINT ((char *) bufp + rel_off);
 	paramp->blklens[last_idx+1] = size;
 	paramp->index++;
     }
@@ -697,7 +697,7 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 	    paramp->blklens[last_idx] += size;
 	}
 	else {
-	    paramp->disps[last_idx+1]   = (MPI_Aint) ((char *) bufp + rel_off);
+	    paramp->disps[last_idx+1]   = MPI_VOID_PTR_CAST_TO_MPI_AINT ((char *) bufp + rel_off);
 	    paramp->blklens[last_idx+1] = size;
 	    paramp->index++;
 	}
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 13fae8d..04a4858 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/veccpy.h
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/veccpy.h
@@ -11,13 +11,13 @@
 #ifdef HAVE_ANY_INT64_T_ALIGNEMENT
 #define MPIR_ALIGN8_TEST(p1,p2)
 #else
-#define MPIR_ALIGN8_TEST(p1,p2) && ((((MPI_Aint)p1 | (MPI_Aint)p2) & 0x7) == 0)
+#define MPIR_ALIGN8_TEST(p1,p2) && (((MPI_VOID_PTR_CAST_TO_MPI_AINT p1 | MPI_VOID_PTR_CAST_TO_MPI_AINT p2) & 0x7) == 0)
 #endif
 
 #ifdef HAVE_ANY_INT32_T_ALIGNEMENT
 #define MPIR_ALIGN4_TEST(p1,p2)
 #else
-#define MPIR_ALIGN4_TEST(p1,p2) && ((((MPI_Aint)p1 | (MPI_Aint)p2) & 0x3) == 0)
+#define MPIR_ALIGN4_TEST(p1,p2) && (((MPI_VOID_PTR_CAST_TO_MPI_AINT p1 | MPI_VOID_PTR_CAST_TO_MPI_AINT p2) & 0x3) == 0)
 #endif
 
 #define MPIDI_COPY_FROM_VEC(src,dest,stride,type,nelms,count) \
diff --git a/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_put.c b/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_put.c
index 6a4b602..0ea00e7 100644
--- a/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_put.c
+++ b/lib/mpi/mpich2/src/mpid/dcmf/src/onesided/mpid_put.c
@@ -125,7 +125,8 @@ int MPID_Put(void *origin_addr, int origin_count,
                 MPIDI_msg_sz_t t_data_sz;
                 MPID_Segment segment;
                 mpid_dt_info dti;
-                int i, j, last, sent = 0;
+                int i, j, sent = 0;
+		DLOOP_Offset last;
                 char *b, *s, *buf;
                 MPIDU_Onesided_info_t *info;
                 int lpid;
-- 
1.5.3.7




More information about the mpich2-dev mailing list