Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add more checking to inputs of SMPI functions
authordegomme <degomme@debian.localdomain>
Fri, 5 Oct 2012 09:14:21 +0000 (11:14 +0200)
committerdegomme <degomme@debian.localdomain>
Fri, 5 Oct 2012 14:02:09 +0000 (16:02 +0200)
warns about too complex datatypes
avoid creating a complex datatype if it is actually contiguous

include/smpi/smpi.h
src/smpi/smpi_base.c
src/smpi/smpi_mpi_dt.c
src/smpi/smpi_pmpi.c

index ad88e27..9343b9f 100644 (file)
@@ -383,6 +383,9 @@ MPI_CALL(XBT_PUBLIC(int), MPI_Probe,
 
 
 //FIXME: these are not yet implemented
 
 
 //FIXME: these are not yet implemented
+
+#define MPI_UB MPI_CHAR
+
 typedef void MPI_Handler_function(MPI_Comm*, int*, ...);
 typedef void* MPI_Errhandler;
 typedef int MPI_Copy_function(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in,
 typedef void MPI_Handler_function(MPI_Comm*, int*, ...);
 typedef void* MPI_Errhandler;
 typedef int MPI_Copy_function(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in,
index 9993cb4..01ef02d 100644 (file)
@@ -161,10 +161,10 @@ void smpi_mpi_start(MPI_Request request)
   } else {
 
     int receiver = smpi_group_index(smpi_comm_group(request->comm), request->dst);
   } else {
 
     int receiver = smpi_group_index(smpi_comm_group(request->comm), request->dst);
-    if(receiver == MPI_UNDEFINED) {
-      XBT_WARN("Trying to send a message to a wrong rank");
-      return;
-    }
+/*    if(receiver == MPI_UNDEFINED) {*/
+/*      XBT_WARN("Trying to send a message to a wrong rank");*/
+/*      return;*/
+/*    }*/
     print_request("New send", request);
     if (request->size < xbt_cfg_get_int(_surf_cfg_set, "smpi/async_small_thres")) { // eager mode
       mailbox = smpi_process_remote_mailbox_small(receiver);
     print_request("New send", request);
     if (request->size < xbt_cfg_get_int(_surf_cfg_set, "smpi/async_small_thres")) { // eager mode
       mailbox = smpi_process_remote_mailbox_small(receiver);
index b332061..5467a33 100644 (file)
@@ -290,6 +290,8 @@ int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_t
     retval = MPI_ERR_TYPE;
   } else {
     if(stride != blocklen){
     retval = MPI_ERR_TYPE;
   } else {
     if(stride != blocklen){
+if (old_type->has_subtype == 1)
+      XBT_WARN("vector contains a complex type - not yet handled");
       s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
                                                                   blocklen,
                                                                   count,
       s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
                                                                   blocklen,
                                                                   count,
@@ -309,7 +311,7 @@ int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_t
                            smpi_datatype_size(old_type),
                            0,
                            NULL,
                            smpi_datatype_size(old_type),
                            0,
                            NULL,
-                           DT_FLAG_VECTOR);
+                           DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
       retval=MPI_SUCCESS;
     }
   }
       retval=MPI_SUCCESS;
     }
   }
@@ -408,6 +410,8 @@ int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype
   if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
     retval = MPI_ERR_TYPE;
   } else {
   if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
     retval = MPI_ERR_TYPE;
   } else {
+if (old_type->has_subtype == 1)
+      XBT_WARN("hvector contains a complex type - not yet handled");
     if(stride != blocklen*smpi_datatype_size(old_type)){
       s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride,
                                                                     blocklen,
     if(stride != blocklen*smpi_datatype_size(old_type)){
       s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride,
                                                                     blocklen,
@@ -426,7 +430,7 @@ int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype
                                                smpi_datatype_size(old_type),
                                               0,
                                               NULL,
                                                smpi_datatype_size(old_type),
                                               0,
                                               NULL,
-                                              DT_FLAG_VECTOR);
+                                              DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
       retval=MPI_SUCCESS;
     }
   }
       retval=MPI_SUCCESS;
     }
   }
@@ -443,8 +447,8 @@ Indexed Implementation
  *  @param contiguous_indexed - output indexed
  *  @param noncontiguous_indexed - input indexed
  *  @param type - pointer contening :
  *  @param contiguous_indexed - output indexed
  *  @param noncontiguous_indexed - input indexed
  *  @param type - pointer contening :
- *      - stride - stride of between noncontiguous data
- *      - block_length - the width or height of blocked matrix
+ *      - block_lengths - the width or height of blocked matrix
+ *      - block_indices - indices of each data, in element
  *      - count - the number of rows of matrix
  */
 void serialize_indexed( const void *noncontiguous_indexed,
  *      - count - the number of rows of matrix
  */
 void serialize_indexed( const void *noncontiguous_indexed,
@@ -470,8 +474,8 @@ void serialize_indexed( const void *noncontiguous_indexed,
  *  @param noncontiguous_indexed - output indexed
  *  @param contiguous_indexed - input indexed
  *  @param type - pointer contening :
  *  @param noncontiguous_indexed - output indexed
  *  @param contiguous_indexed - input indexed
  *  @param type - pointer contening :
- *      - stride - stride of between noncontiguous data
- *      - block_length - the width or height of blocked matrix
+ *      - block_lengths - the width or height of blocked matrix
+ *      - block_indices - indices of each data, in element
  *      - count - the number of rows of matrix
  */
 void unserialize_indexed( const void *contiguous_indexed,
  *      - count - the number of rows of matrix
  */
 void unserialize_indexed( const void *contiguous_indexed,
@@ -522,22 +526,34 @@ int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype
   int i;
   int retval;
   int size = 0;
   int i;
   int retval;
   int size = 0;
+  int contiguous=1;
   for(i=0; i< count; i++){
     if   (blocklens[i]<=0)
       return MPI_ERR_ARG;
     size += blocklens[i];
   for(i=0; i< count; i++){
     if   (blocklens[i]<=0)
       return MPI_ERR_ARG;
     size += blocklens[i];
+
+    if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )contiguous=0;
   }
   if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
     retval = MPI_ERR_TYPE;
   } else {
   }
   if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
     retval = MPI_ERR_TYPE;
   } else {
-    s_smpi_mpi_indexed_t* subtype = smpi_datatype_indexed_create( blocklens,
-                                                                  indices,
-                                                                  count,
-                                                                  old_type,
-                                                                  smpi_datatype_size(old_type));
 
 
-    smpi_datatype_create(new_type,  size *
-                         smpi_datatype_size(old_type),1, subtype, DT_FLAG_DATA);
+    if (old_type->has_subtype == 1)
+      XBT_WARN("indexed contains a complex type - not yet handled");
+
+    if(!contiguous){
+      s_smpi_mpi_indexed_t* subtype = smpi_datatype_indexed_create( blocklens,
+                                                                    indices,
+                                                                    count,
+                                                                    old_type,
+                                                                    smpi_datatype_size(old_type));
+
+      smpi_datatype_create(new_type,  size *
+                           smpi_datatype_size(old_type),1, subtype, DT_FLAG_DATA);
+}else{
+      smpi_datatype_create(new_type,  size *
+                           smpi_datatype_size(old_type),0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
+}
     retval=MPI_SUCCESS;
   }
   return retval;
     retval=MPI_SUCCESS;
   }
   return retval;
@@ -553,8 +569,8 @@ Hindexed Implementation - Indexed with indices in bytes
  *  @param contiguous_hindexed - output hindexed
  *  @param noncontiguous_hindexed - input hindexed
  *  @param type - pointer contening :
  *  @param contiguous_hindexed - output hindexed
  *  @param noncontiguous_hindexed - input hindexed
  *  @param type - pointer contening :
- *      - stride - stride of between noncontiguous data
- *      - block_length - the width or height of blocked matrix
+ *      - block_lengths - the width or height of blocked matrix
+ *      - block_indices - indices of each data, in bytes
  *      - count - the number of rows of matrix
  */
 void serialize_hindexed( const void *noncontiguous_hindexed,
  *      - count - the number of rows of matrix
  */
 void serialize_hindexed( const void *noncontiguous_hindexed,
@@ -580,8 +596,8 @@ void serialize_hindexed( const void *noncontiguous_hindexed,
  *  @param noncontiguous_hindexed - output hindexed
  *  @param contiguous_hindexed - input hindexed
  *  @param type - pointer contening :
  *  @param noncontiguous_hindexed - output hindexed
  *  @param contiguous_hindexed - input hindexed
  *  @param type - pointer contening :
- *      - stride - stride of between noncontiguous data
- *      - block_length - the width or height of blocked matrix
+ *      - block_lengths - the width or height of blocked matrix
+ *      - block_indices - indices of each data, in bytes
  *      - count - the number of rows of matrix
  */
 void unserialize_hindexed( const void *contiguous_hindexed,
  *      - count - the number of rows of matrix
  */
 void unserialize_hindexed( const void *contiguous_hindexed,
@@ -632,22 +648,34 @@ int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Dat
   int i;
   int retval;
   int size = 0;
   int i;
   int retval;
   int size = 0;
+  int contiguous=1;
   for(i=0; i< count; i++){
     if   (blocklens[i]<=0)
       return MPI_ERR_ARG;
     size += blocklens[i];
   for(i=0; i< count; i++){
     if   (blocklens[i]<=0)
       return MPI_ERR_ARG;
     size += blocklens[i];
+
+
+    if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_type) != indices[i+1]) )contiguous=0;
   }
   if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
     retval = MPI_ERR_TYPE;
   } else {
   }
   if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
     retval = MPI_ERR_TYPE;
   } else {
-    s_smpi_mpi_hindexed_t* subtype = smpi_datatype_hindexed_create( blocklens,
-                                                                  indices,
-                                                                  count,
-                                                                  old_type,
-                                                                  smpi_datatype_size(old_type));
+    if (old_type->has_subtype == 1)
+      XBT_WARN("hindexed contains a complex type - not yet handled");
 
 
-    smpi_datatype_create(new_type,  size *
-                         smpi_datatype_size(old_type),1, subtype, DT_FLAG_DATA);
+    if(!contiguous){
+      s_smpi_mpi_hindexed_t* subtype = smpi_datatype_hindexed_create( blocklens,
+                                                                    indices,
+                                                                    count,
+                                                                    old_type,
+                                                                    smpi_datatype_size(old_type));
+
+      smpi_datatype_create(new_type,  size *
+                           smpi_datatype_size(old_type),1, subtype, DT_FLAG_DATA);
+    }else{
+      smpi_datatype_create(new_type,  size *
+                           smpi_datatype_size(old_type),0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
+    }
     retval=MPI_SUCCESS;
   }
   return retval;
     retval=MPI_SUCCESS;
   }
   return retval;
@@ -737,22 +765,30 @@ int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datat
 {
   int i;
   size_t size = 0;
 {
   int i;
   size_t size = 0;
+  int contiguous=1;
+  size = 0;
   for(i=0; i< count; i++){
     if (blocklens[i]<=0)
       return MPI_ERR_ARG;
     if ((old_types[i]->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED)
       return MPI_ERR_TYPE;
   for(i=0; i< count; i++){
     if (blocklens[i]<=0)
       return MPI_ERR_ARG;
     if ((old_types[i]->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED)
       return MPI_ERR_TYPE;
+    if (old_types[i]->has_subtype == 1)
+      XBT_WARN("Struct contains a complex type - not yet handled");
     size += blocklens[i]*smpi_datatype_size(old_types[i]);
     size += blocklens[i]*smpi_datatype_size(old_types[i]);
-  }
 
 
+    if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_types[i]) != indices[i+1]) )contiguous=0;
+  }
 
 
-  s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens,
+  if(!contiguous){
+    s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens,
                                                               indices,
                                                               count,
                                                               old_types);
 
                                                               indices,
                                                               count,
                                                               old_types);
 
-  smpi_datatype_create(new_type,  size ,1, subtype, DT_FLAG_DATA);
-
+    smpi_datatype_create(new_type,  size ,1, subtype, DT_FLAG_DATA);
+  }else{
+    smpi_datatype_create(new_type,  size,0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
+  }
   return MPI_SUCCESS;
 }
 
   return MPI_SUCCESS;
 }
 
index 07f5101..e3abcd2 100644 (file)
@@ -914,10 +914,16 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
   } else if (src == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
   } else if (src == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
+  } else if (src >= smpi_group_size(smpi_comm_group(comm)) || src <0){
+    retval = MPI_ERR_COMM;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
+  } else if (buf==NULL && count > 0) {
+    retval = MPI_ERR_COUNT;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
+  } else if(tag<0 && tag !=  MPI_ANY_TAG){
+    retval = MPI_ERR_TAG;
   } else {
 
 #ifdef HAVE_TRACING
   } else {
 
 #ifdef HAVE_TRACING
@@ -953,10 +959,16 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
   } else if (dst == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
   } else if (dst == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
+  } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+    retval = MPI_ERR_COMM;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
+  } else if (buf==NULL && count > 0) {
+    retval = MPI_ERR_COUNT;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
+  } else if(tag<0 && tag !=  MPI_ANY_TAG){
+    retval = MPI_ERR_TAG;
   } else {
 
 #ifdef HAVE_TRACING
   } else {
 
 #ifdef HAVE_TRACING
@@ -996,10 +1008,16 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
     smpi_empty_status(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval = MPI_SUCCESS;
     smpi_empty_status(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval = MPI_SUCCESS;
+  }else if(src >= smpi_group_size(smpi_comm_group(comm)) || src <0){
+    retval = MPI_ERR_COMM;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
+  } else if (buf==NULL && count > 0) {
+    retval = MPI_ERR_COUNT;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
+  } else if(tag<0 && tag !=  MPI_ANY_TAG){
+    retval = MPI_ERR_TAG;
   } else {
 #ifdef HAVE_TRACING
   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
   } else {
 #ifdef HAVE_TRACING
   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
@@ -1036,10 +1054,16 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
     retval = MPI_ERR_COMM;
   } else if (dst == MPI_PROC_NULL) {
     retval = MPI_SUCCESS;
     retval = MPI_ERR_COMM;
   } else if (dst == MPI_PROC_NULL) {
     retval = MPI_SUCCESS;
+  } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+    retval = MPI_ERR_COMM;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
   } else if (count < 0) {
     retval = MPI_ERR_COUNT;
+  } else if (buf==NULL && count > 0) {
+    retval = MPI_ERR_COUNT;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
   } else if (datatype == MPI_DATATYPE_NULL){
     retval = MPI_ERR_TYPE;
+  } else if(tag<0 && tag !=  MPI_ANY_TAG){
+    retval = MPI_ERR_TAG;
   } else {
 
 #ifdef HAVE_TRACING
   } else {
 
 #ifdef HAVE_TRACING
@@ -1081,8 +1105,14 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
       smpi_empty_status(status);
       status->MPI_SOURCE = MPI_PROC_NULL;
       retval = MPI_SUCCESS;
       smpi_empty_status(status);
       status->MPI_SOURCE = MPI_PROC_NULL;
       retval = MPI_SUCCESS;
+  }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 || src >= smpi_group_size(smpi_comm_group(comm)) || src <0){
+    retval = MPI_ERR_COMM;
   } else if (sendcount < 0 || recvcount<0) {
       retval = MPI_ERR_COUNT;
   } else if (sendcount < 0 || recvcount<0) {
       retval = MPI_ERR_COUNT;
+  } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
+    retval = MPI_ERR_COUNT;
+  } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
+    retval = MPI_ERR_TAG;
   } else {
 
 #ifdef HAVE_TRACING
   } else {
 
 #ifdef HAVE_TRACING