Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixed buggy implementation of MPI_Waitsome
[simgrid.git] / src / smpi / smpi_base.c
index 96028af..0143935 100644 (file)
@@ -22,12 +22,13 @@ void smpi_process_init(int* argc, char*** argv) {
   index = atoi((*argv)[1]);
   data = smpi_process_remote_data(index);
   SIMIX_process_set_data(proc, data);
-  DEBUG2("<%d> New process in the game: %p", index, proc);
   if (*argc > 2) {
+    free((*argv)[1]);
     memmove(&(*argv)[1], &(*argv)[2], sizeof(char *) * (*argc - 2));
     (*argv)[(*argc) - 1] = NULL;
   }
   (*argc)--;
+  DEBUG2("<%d> New process in the game: %p", index, proc);
 }
 
 void smpi_process_destroy(void) {
@@ -129,6 +130,7 @@ int smpi_mpi_test(MPI_Request* request, MPI_Status* status) {
   int flag = data && data->complete == 1;
 
   if(flag) {
+    SIMIX_communication_destroy((*request)->pair);
     finish_wait(request, status);
   }
   return flag;
@@ -144,6 +146,7 @@ int smpi_mpi_testany(int count, MPI_Request requests[], int* index, MPI_Status*
     if(requests[i] != MPI_REQUEST_NULL) {
       data = (MPI_Request)SIMIX_communication_get_data(requests[i]->pair);
       if(data != MPI_REQUEST_NULL && data->complete == 1) {
+        SIMIX_communication_destroy(requests[i]->pair);
         finish_wait(&requests[i], status);
         *index = i;
         flag = 1;
@@ -162,6 +165,8 @@ void smpi_mpi_wait(MPI_Request* request, MPI_Status* status) {
   // data is null if receiver waits before sender enters the rdv
   if(data == MPI_REQUEST_NULL || data->complete == 0) {
     SIMIX_network_wait((*request)->pair, -1.0);
+  } else {
+    SIMIX_communication_destroy((*request)->pair);
   }
   finish_wait(request, status);
 }
@@ -180,6 +185,7 @@ int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status* status) {
         data = (MPI_Request)SIMIX_communication_get_data(requests[i]->pair);
         if(data != MPI_REQUEST_NULL && data->complete == 1) {
           index = i;
+          SIMIX_communication_destroy(requests[index]->pair); // always succeeds (but cleans the simix layer)
           break;
         }
       }
@@ -237,10 +243,11 @@ int smpi_mpi_waitsome(int incount, MPI_Request requests[], int* indices, MPI_Sta
   int i, count;
 
   count = 0;
-  for(i = 0; i < count; i++) {
+  for(i = 0; i < incount; i++) {
     if(requests[i] != MPI_REQUEST_NULL) {
       data = (MPI_Request)SIMIX_communication_get_data(requests[i]->pair);
       if(data != MPI_REQUEST_NULL && data->complete == 1) {
+        SIMIX_communication_destroy(requests[i]->pair);
         finish_wait(&requests[i], status != MPI_STATUS_IGNORE ? &status[i] : MPI_STATUS_IGNORE);
         indices[count] = i;
         count++;