Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix lua platform script
[simgrid.git] / src / smpi / smpi_pmpi.c
index f10a36f..1e4dc07 100644 (file)
@@ -182,7 +182,6 @@ int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent
 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
 {
   int retval;
-  MPI_Aint dummy;
 
   smpi_bench_end();
   if (datatype == MPI_DATATYPE_NULL) {
@@ -190,7 +189,8 @@ int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
   } else if (extent == NULL) {
     retval = MPI_ERR_ARG;
   } else {
-    retval = smpi_datatype_extent(datatype, &dummy, extent);
+    *extent = smpi_datatype_get_extent(datatype);
+    retval = MPI_SUCCESS;
   }
   smpi_bench_begin();
   return retval;
@@ -394,7 +394,7 @@ int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
                            MPI_Group * newgroup)
 {
-  int retval, i, proc1, proc2, size, size2;
+  int retval, i, proc1, proc2, size;
 
   smpi_bench_end();
   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
@@ -402,9 +402,8 @@ int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
   } else if (newgroup == NULL) {
     retval = MPI_ERR_ARG;
   } else {
-    size = smpi_group_size(group1);
-    size2 = smpi_group_size(group2);
-    for (i = 0; i < size2; i++) {
+    size = smpi_group_size(group2);
+    for (i = 0; i < size; i++) {
       proc2 = smpi_group_index(group2, i);
       proc1 = smpi_group_rank(group1, proc2);
       if (proc1 == MPI_UNDEFINED) {
@@ -415,12 +414,13 @@ int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
       *newgroup = MPI_GROUP_EMPTY;
     } else {
       *newgroup = smpi_group_new(size);
-      size2 = smpi_group_size(group1);
-      for (i = 0; i < size2; i++) {
-        proc1 = smpi_group_index(group1, i);
-        proc2 = smpi_group_rank(group2, proc1);
-        if (proc2 != MPI_UNDEFINED) {
-          smpi_group_set_mapping(*newgroup, proc1, i);
+      int j=0;
+      for (i = 0; i < smpi_group_size(group2); i++) {
+        proc2 = smpi_group_index(group2, i);
+        proc1 = smpi_group_rank(group1, proc2);
+        if (proc1 != MPI_UNDEFINED) {
+          smpi_group_set_mapping(*newgroup, proc2, j);
+          j++;
         }
       }
     }
@@ -498,7 +498,7 @@ int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
 
 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
 {
-  int retval, i, size, rank, index;
+  int retval, i, j, newsize, oldsize, index;
 
   smpi_bench_end();
   if (group == MPI_GROUP_NULL) {
@@ -511,22 +511,26 @@ int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
     } else if (n == smpi_group_size(group)) {
       *newgroup = MPI_GROUP_EMPTY;
     } else {
-      size = smpi_group_size(group) - n;
-      *newgroup = smpi_group_new(size);
-      rank = 0;
-      while (rank < size) {
-        for (i = 0; i < n; i++) {
-          if (ranks[i] == rank) {
-            break;
-          }
-        }
-        if (i >= n) {
-          index = smpi_group_index(group, rank);
-          smpi_group_set_mapping(*newgroup, index, rank);
-          
+      oldsize=smpi_group_size(group);
+      newsize = oldsize - n;
+      *newgroup = smpi_group_new(newsize);
+
+      int* to_exclude=xbt_new(int, smpi_group_size(group));
+      for(i=0; i<oldsize; i++)
+        to_exclude[i]=0;
+      for(i=0; i<n; i++)
+        to_exclude[ranks[i]]=1;
+
+      j=0;
+      for(i=0; i<oldsize; i++){
+        if(to_exclude[i]==0){
+          index = smpi_group_index(group, i);
+          smpi_group_set_mapping(*newgroup, index, j);
+          j++;
         }
-        rank++;
       }
+
+      xbt_free(to_exclude);
     }
     smpi_group_use(*newgroup);
     retval = MPI_SUCCESS;
@@ -893,9 +897,10 @@ int PMPI_Request_free(MPI_Request * request)
   int retval;
 
   smpi_bench_end();
-  if (request == MPI_REQUEST_NULL) {
+  if (*request == MPI_REQUEST_NULL) {
     retval = MPI_ERR_ARG;
   } else {
+    if((*request)->flags & PERSISTENT)(*request)->refcount--;
     smpi_mpi_request_free(request);
     retval = MPI_SUCCESS;
   }
@@ -1004,7 +1009,6 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
   int retval;
 
   smpi_bench_end();
-
   if (comm == MPI_COMM_NULL) {
     retval = MPI_ERR_COMM;
   } else if (src == MPI_PROC_NULL) {
@@ -1152,16 +1156,24 @@ int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
                          MPI_Comm comm, MPI_Status * status)
 {
   //TODO: suboptimal implementation
// void *recvbuf;
+  void *recvbuf;
   int retval;
+  if ((datatype == MPI_DATATYPE_NULL)||(datatype->has_subtype==1)) {
+      retval = MPI_ERR_TYPE;
+  } else if (count < 0) {
+      retval = MPI_ERR_COUNT;
+  } else {
+    int size = smpi_datatype_size(datatype) * count;
+    recvbuf = xbt_new(char, size);
+    retval =
+        MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
+                     datatype, src, recvtag, comm, status);
+    if(retval==MPI_SUCCESS){
+        memcpy(buf, recvbuf, size * sizeof(char));
+    }
+    xbt_free(recvbuf);
 
-//  size = smpi_datatype_size(datatype) * count;
-//  recvbuf = xbt_new(char, size);
-  retval =
-      MPI_Sendrecv(buf, count, datatype, dst, sendtag, buf, count,
-                   datatype, src, recvtag, comm, status);
-/*memcpy(buf, recvbuf, size * sizeof(char));
-  xbt_free(recvbuf);*/
+  }
   return retval;
 }
 
@@ -1361,8 +1373,6 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
     xbt_dynar_free(&recvs);
   }
   TRACE_smpi_computing_in(rank_traced);
-
-
 #endif
   smpi_bench_begin();
   return retval;
@@ -2061,6 +2071,12 @@ int PMPI_Error_class(int errorcode, int* errorclass) {
   return MPI_SUCCESS;
 }
 
+
+int PMPI_Initialized(int* flag) {
+   *flag=(smpi_process_data()!=NULL);
+   return MPI_SUCCESS;
+}
+
 /* The following calls are not yet implemented and will fail at runtime. */
 /* Once implemented, please move them above this notice. */
 
@@ -2273,6 +2289,4 @@ int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
    return not_yet_implemented();
 }
 
-int PMPI_Initialized(int* flag) {
-   return not_yet_implemented();
-}
+