-
- if (comm == MPI_COMM_NULL) {
- retval = MPI_ERR_COMM;
- } else if ((sendbuf != MPI_IN_PLACE && sendtypes == nullptr) || recvtypes == nullptr) {
- retval = MPI_ERR_TYPE;
- } else if ((sendbuf != MPI_IN_PLACE && (sendcounts == nullptr || senddisps == nullptr)) || recvcounts == nullptr ||
- recvdisps == nullptr) {
- retval = MPI_ERR_ARG;
- } else if (request == nullptr){
- retval = MPI_ERR_ARG;
- } else {
- int rank = simgrid::s4u::this_actor::get_pid();
- int size = comm->size();
- int send_size = 0;
- int recv_size = 0;
- std::vector<int>* trace_sendcounts = new std::vector<int>;
- std::vector<int>* trace_recvcounts = new std::vector<int>;
-
- void* sendtmpbuf = static_cast<char*>(sendbuf);
- int* sendtmpcounts = sendcounts;
- int* sendtmpdisps = senddisps;
- MPI_Datatype* sendtmptypes = sendtypes;
- unsigned long maxsize = 0;
- for (int i = 0; i < size; i++) { // copy data to avoid bad free
- if(recvtypes[i]==MPI_DATATYPE_NULL){
- delete trace_recvcounts;
- delete trace_sendcounts;
- return MPI_ERR_TYPE;
- }
- recv_size += recvcounts[i] * recvtypes[i]->size();
- trace_recvcounts->push_back(recvcounts[i] * recvtypes[i]->size());
- if ((recvdisps[i] + (recvcounts[i] * recvtypes[i]->size())) > maxsize)
- maxsize = recvdisps[i] + (recvcounts[i] * recvtypes[i]->size());
- }
-
- if (sendbuf == MPI_IN_PLACE) {
- sendtmpbuf = static_cast<void*>(xbt_malloc(maxsize));
- memcpy(sendtmpbuf, recvbuf, maxsize);
- sendtmpcounts = static_cast<int*>(xbt_malloc(size * sizeof(int)));
- memcpy(sendtmpcounts, recvcounts, size * sizeof(int));
- sendtmpdisps = static_cast<int*>(xbt_malloc(size * sizeof(int)));
- memcpy(sendtmpdisps, recvdisps, size * sizeof(int));
- sendtmptypes = static_cast<MPI_Datatype*>(xbt_malloc(size * sizeof(MPI_Datatype)));
- memcpy(sendtmptypes, recvtypes, size * sizeof(MPI_Datatype));
- }
-
- for (int i = 0; i < size; i++) { // copy data to avoid bad free
- send_size += sendtmpcounts[i] * sendtmptypes[i]->size();
- trace_sendcounts->push_back(sendtmpcounts[i] * sendtmptypes[i]->size());
+ int rank = simgrid::s4u::this_actor::get_pid();
+ int size = comm->size();
+ for (int i = 0; i < size; i++) {
+ if (recvcounts[i] < 0 || (sendbuf != MPI_IN_PLACE && sendcounts[i] < 0))
+ return MPI_ERR_COUNT;
+ }
+ int send_size = 0;
+ int recv_size = 0;
+ std::vector<int>* trace_sendcounts = new std::vector<int>;
+ std::vector<int>* trace_recvcounts = new std::vector<int>;
+
+ const void* real_sendbuf = sendbuf;
+ const int* real_sendcounts = sendcounts;
+ const int* real_senddisps = senddisps;
+ const MPI_Datatype* real_sendtypes = sendtypes;
+ unsigned long maxsize = 0;
+ for (int i = 0; i < size; i++) { // copy data to avoid bad free
+ if (recvtypes[i] == MPI_DATATYPE_NULL) {
+ delete trace_recvcounts;
+ delete trace_sendcounts;
+ return MPI_ERR_TYPE;