diff --git a/dune/common/parallel/communicator.hh b/dune/common/parallel/communicator.hh index a7da24e50f1bd7f05af4eae6cf8b2205be4390d5..2ebea3b753ba4d9cd653713a873b5caf488531b3 100644 --- a/dune/common/parallel/communicator.hh +++ b/dune/common/parallel/communicator.hh @@ -1420,6 +1420,8 @@ namespace Dune MPI_Request* sendRequests = new MPI_Request[messageInformation_.size()]; MPI_Request* recvRequests = new MPI_Request[messageInformation_.size()]; + /* Number of recvRequests that are not MPI_REQUEST_NULL */ + size_t numberOfRealRecvRequests = 0; // Setup receive first typedef typename InformationMap::const_iterator const_iterator; @@ -1433,23 +1435,27 @@ namespace Dune if(FORWARD) { assert(info->second.second.start_*sizeof(typename CommPolicy<Data>::IndexedType)+info->second.second.size_ <= recvBufferSize ); Dune::dvverb<<rank<<": receiving "<<info->second.second.size_<<" from "<<info->first<<std::endl; - if(info->second.second.size_) + if(info->second.second.size_) { MPI_Irecv(recvBuffer+info->second.second.start_, info->second.second.size_, MPI_BYTE, info->first, commTag_, communicator_, recvRequests+i); - else + numberOfRealRecvRequests += 1; + } else { // Nothing to receive -> set request to inactive recvRequests[i]=MPI_REQUEST_NULL; + } }else{ assert(info->second.first.start_*sizeof(typename CommPolicy<Data>::IndexedType)+info->second.first.size_ <= recvBufferSize ); Dune::dvverb<<rank<<": receiving "<<info->second.first.size_<<" to "<<info->first<<std::endl; - if(info->second.first.size_) + if(info->second.first.size_) { MPI_Irecv(recvBuffer+info->second.first.start_, info->second.first.size_, MPI_BYTE, info->first, commTag_, communicator_, recvRequests+i); - else + numberOfRealRecvRequests += 1; + } else { // Nothing to receive -> set request to inactive recvRequests[i]=MPI_REQUEST_NULL; + } } } @@ -1486,7 +1492,7 @@ namespace Dune MPI_Status status; //[messageInformation_.size()]; //MPI_Waitall(messageInformation_.size(), recvRequests, status); - for(i=0; i< messageInformation_.size(); i++) { + for(i=0; i< numberOfRealRecvRequests; i++) { status.MPI_ERROR=MPI_SUCCESS; MPI_Waitany(messageInformation_.size(), recvRequests, &finished, &status); assert(finished != MPI_UNDEFINED);