1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smpi_comm.hpp"
8 #include "smpi_datatype.hpp"
9 #include "smpi_request.hpp"
10 #include "src/smpi/include/smpi_actor.hpp"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
14 static int getPid(MPI_Comm, int);
15 static int getPid(MPI_Comm comm, int id)
17 simgrid::s4u::ActorPtr actor = comm->group()->actor(id);
18 return (actor == nullptr) ? MPI_UNDEFINED : actor->get_pid();
21 #define CHECK_SEND_INPUTS\
22 CHECK_BUFFER(1, buf, count)\
23 CHECK_COUNT(2, count)\
24 CHECK_TYPE(3, datatype)\
26 CHECK_RANK(4, dst, comm)\
30 #define CHECK_ISEND_INPUTS\
32 *request = MPI_REQUEST_NULL;\
35 #define CHECK_IRECV_INPUTS\
37 *request = MPI_REQUEST_NULL;\
38 CHECK_BUFFER(1, buf, count)\
39 CHECK_COUNT(2, count)\
40 CHECK_TYPE(3, datatype)\
42 if(src!=MPI_ANY_SOURCE)\
43 CHECK_RANK(4, src, comm)\
46 /* PMPI User level calls */
48 int PMPI_Send_init(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
53 *request = simgrid::smpi::Request::send_init(buf, count, datatype, dst, tag, comm);
59 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
64 *request = simgrid::smpi::Request::recv_init(buf, count, datatype, src, tag, comm);
69 int PMPI_Rsend_init(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm,
72 return PMPI_Send_init(buf, count, datatype, dst, tag, comm, request);
75 int PMPI_Ssend_init(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
81 *request = simgrid::smpi::Request::ssend_init(buf, count, datatype, dst, tag, comm);
89 * This function starts a request returned by init functions such as
90 * MPI_Send_init(), MPI_Ssend_init (see above), and friends.
91 * They should already have performed sanity checks.
93 int PMPI_Start(MPI_Request * request)
99 if ( *request == MPI_REQUEST_NULL) {
100 retval = MPI_ERR_REQUEST;
102 MPI_Request req = *request;
103 int my_proc_id = (req->comm() != MPI_COMM_NULL) ? simgrid::s4u::this_actor::get_pid() : -1;
104 TRACE_smpi_comm_in(my_proc_id, __func__,
105 new simgrid::instr::Pt2PtTIData("Start", req->dst(),
108 simgrid::smpi::Datatype::encode(req->type())));
109 if (not TRACE_smpi_view_internals() && req->flags() & MPI_REQ_SEND)
110 TRACE_smpi_send(my_proc_id, my_proc_id, getPid(req->comm(), req->dst()), req->tag(), req->size());
114 if (not TRACE_smpi_view_internals() && req->flags() & MPI_REQ_RECV)
115 TRACE_smpi_recv(getPid(req->comm(), req->src()), my_proc_id, req->tag());
116 retval = MPI_SUCCESS;
117 TRACE_smpi_comm_out(my_proc_id);
123 int PMPI_Startall(int count, MPI_Request * requests)
127 if (requests == nullptr) {
128 retval = MPI_ERR_ARG;
130 retval = MPI_SUCCESS;
131 for (int i = 0; i < count; i++) {
132 if(requests[i] == MPI_REQUEST_NULL) {
133 retval = MPI_ERR_REQUEST;
136 if(retval != MPI_ERR_REQUEST) {
137 int my_proc_id = simgrid::s4u::this_actor::get_pid();
138 TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Startall"));
139 if (not TRACE_smpi_view_internals())
140 for (int i = 0; i < count; i++) {
141 MPI_Request req = requests[i];
142 if (req->flags() & MPI_REQ_SEND)
143 TRACE_smpi_send(my_proc_id, my_proc_id, getPid(req->comm(), req->dst()), req->tag(), req->size());
146 simgrid::smpi::Request::startall(count, requests);
148 if (not TRACE_smpi_view_internals())
149 for (int i = 0; i < count; i++) {
150 MPI_Request req = requests[i];
151 if (req->flags() & MPI_REQ_RECV)
152 TRACE_smpi_recv(getPid(req->comm(), req->src()), my_proc_id, req->tag());
154 TRACE_smpi_comm_out(my_proc_id);
161 int PMPI_Request_free(MPI_Request * request)
166 if (*request != MPI_REQUEST_NULL) {
167 simgrid::smpi::Request::unref(request);
168 *request = MPI_REQUEST_NULL;
169 retval = MPI_SUCCESS;
175 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
180 int my_proc_id = simgrid::s4u::this_actor::get_pid();
181 TRACE_smpi_comm_in(my_proc_id, __func__,
182 new simgrid::instr::Pt2PtTIData("irecv", src,
183 datatype->is_replayable() ? count : count * datatype->size(),
184 tag, simgrid::smpi::Datatype::encode(datatype)));
185 *request = simgrid::smpi::Request::irecv(buf, count, datatype, src, tag, comm);
186 TRACE_smpi_comm_out(my_proc_id);
192 int PMPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
198 int my_proc_id = simgrid::s4u::this_actor::get_pid();
199 int trace_dst = getPid(comm, dst);
200 TRACE_smpi_comm_in(my_proc_id, __func__,
201 new simgrid::instr::Pt2PtTIData("isend", dst,
202 datatype->is_replayable() ? count : count * datatype->size(),
203 tag, simgrid::smpi::Datatype::encode(datatype)));
204 TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size());
205 *request = simgrid::smpi::Request::isend(buf, count, datatype, dst, tag, comm);
206 retval = MPI_SUCCESS;
207 TRACE_smpi_comm_out(my_proc_id);
213 int PMPI_Irsend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm,
214 MPI_Request* request)
216 return PMPI_Isend(buf, count, datatype, dst, tag, comm, request);
219 int PMPI_Issend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
224 int my_proc_id = simgrid::s4u::this_actor::get_pid();
225 int trace_dst = getPid(comm, dst);
226 TRACE_smpi_comm_in(my_proc_id, __func__,
227 new simgrid::instr::Pt2PtTIData("ISsend", dst,
228 datatype->is_replayable() ? count : count * datatype->size(),
229 tag, simgrid::smpi::Datatype::encode(datatype)));
230 TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size());
231 *request = simgrid::smpi::Request::issend(buf, count, datatype, dst, tag, comm);
232 TRACE_smpi_comm_out(my_proc_id);
237 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
241 CHECK_BUFFER(1, buf, count)
242 CHECK_COUNT(2, count)
243 CHECK_TYPE(3, datatype)
248 if (src == MPI_PROC_NULL) {
249 if(status != MPI_STATUS_IGNORE){
250 simgrid::smpi::Status::empty(status);
251 status->MPI_SOURCE = MPI_PROC_NULL;
253 retval = MPI_SUCCESS;
254 } else if (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0)){
255 retval = MPI_ERR_RANK;
257 int my_proc_id = simgrid::s4u::this_actor::get_pid();
258 TRACE_smpi_comm_in(my_proc_id, __func__,
259 new simgrid::instr::Pt2PtTIData("recv", src,
260 datatype->is_replayable() ? count : count * datatype->size(),
261 tag, simgrid::smpi::Datatype::encode(datatype)));
263 simgrid::smpi::Request::recv(buf, count, datatype, src, tag, comm, status);
264 retval = MPI_SUCCESS;
266 // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
268 if (status != MPI_STATUS_IGNORE)
269 src_traced = getPid(comm, status->MPI_SOURCE);
271 src_traced = getPid(comm, src);
272 if (not TRACE_smpi_view_internals()) {
273 TRACE_smpi_recv(src_traced, my_proc_id, tag);
276 TRACE_smpi_comm_out(my_proc_id);
283 int PMPI_Send(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
288 int my_proc_id = simgrid::s4u::this_actor::get_pid();
289 int dst_traced = getPid(comm, dst);
290 TRACE_smpi_comm_in(my_proc_id, __func__,
291 new simgrid::instr::Pt2PtTIData("send", dst,
292 datatype->is_replayable() ? count : count * datatype->size(),
293 tag, simgrid::smpi::Datatype::encode(datatype)));
294 if (not TRACE_smpi_view_internals()) {
295 TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size());
297 simgrid::smpi::Request::send(buf, count, datatype, dst, tag, comm);
298 TRACE_smpi_comm_out(my_proc_id);
303 int PMPI_Rsend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
305 return PMPI_Send(buf, count, datatype, dst, tag, comm);
308 int PMPI_Bsend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
313 int my_proc_id = simgrid::s4u::this_actor::get_pid();
314 int dst_traced = getPid(comm, dst);
315 int bsend_buf_size = 0;
316 void* bsend_buf = nullptr;
317 smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
318 int size = datatype->get_extent() * count;
319 if(bsend_buf==nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD )
320 return MPI_ERR_BUFFER;
321 TRACE_smpi_comm_in(my_proc_id, __func__,
322 new simgrid::instr::Pt2PtTIData("bsend", dst,
323 datatype->is_replayable() ? count : count * datatype->size(),
324 tag, simgrid::smpi::Datatype::encode(datatype)));
325 if (not TRACE_smpi_view_internals()) {
326 TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size());
328 simgrid::smpi::Request::bsend(buf, count, datatype, dst, tag, comm);
329 TRACE_smpi_comm_out(my_proc_id);
334 int PMPI_Ibsend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
339 int my_proc_id = simgrid::s4u::this_actor::get_pid();
340 int trace_dst = getPid(comm, dst);
341 int bsend_buf_size = 0;
342 void* bsend_buf = nullptr;
343 smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
344 int size = datatype->get_extent() * count;
345 if(bsend_buf==nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD )
346 return MPI_ERR_BUFFER;
347 TRACE_smpi_comm_in(my_proc_id, __func__,
348 new simgrid::instr::Pt2PtTIData("ibsend", dst,
349 datatype->is_replayable() ? count : count * datatype->size(),
350 tag, simgrid::smpi::Datatype::encode(datatype)));
351 TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size());
352 *request = simgrid::smpi::Request::ibsend(buf, count, datatype, dst, tag, comm);
353 TRACE_smpi_comm_out(my_proc_id);
358 int PMPI_Bsend_init(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
364 int bsend_buf_size = 0;
365 void* bsend_buf = nullptr;
366 smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
367 if( bsend_buf==nullptr || bsend_buf_size < datatype->get_extent() * count + MPI_BSEND_OVERHEAD ) {
368 retval = MPI_ERR_BUFFER;
370 *request = simgrid::smpi::Request::bsend_init(buf, count, datatype, dst, tag, comm);
371 retval = MPI_SUCCESS;
377 int PMPI_Ssend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
382 int my_proc_id = simgrid::s4u::this_actor::get_pid();
383 int dst_traced = getPid(comm, dst);
384 TRACE_smpi_comm_in(my_proc_id, __func__,
385 new simgrid::instr::Pt2PtTIData("Ssend", dst,
386 datatype->is_replayable() ? count : count * datatype->size(),
387 tag, simgrid::smpi::Datatype::encode(datatype)));
388 TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size());
389 simgrid::smpi::Request::ssend(buf, count, datatype, dst, tag, comm);
390 TRACE_smpi_comm_out(my_proc_id);
395 int PMPI_Sendrecv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf,
396 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status)
399 CHECK_BUFFER(1, sendbuf, sendcount)
400 CHECK_COUNT(2, sendcount)
401 CHECK_TYPE(3, sendtype)
402 CHECK_TAG(5, sendtag)
403 CHECK_BUFFER(6, recvbuf, recvcount)
404 CHECK_COUNT(7, recvcount)
405 CHECK_TYPE(8, recvtype)
406 CHECK_TAG(10, recvtag)
410 if (src == MPI_PROC_NULL) {
411 if(status!=MPI_STATUS_IGNORE){
412 simgrid::smpi::Status::empty(status);
413 status->MPI_SOURCE = MPI_PROC_NULL;
415 if(dst != MPI_PROC_NULL)
416 simgrid::smpi::Request::send(sendbuf, sendcount, sendtype, dst, sendtag, comm);
417 retval = MPI_SUCCESS;
418 } else if (dst == MPI_PROC_NULL){
419 simgrid::smpi::Request::recv(recvbuf, recvcount, recvtype, src, recvtag, comm, status);
420 retval = MPI_SUCCESS;
421 } else if (dst >= comm->group()->size() || dst <0 ||
422 (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0))){
423 retval = MPI_ERR_RANK;
425 int my_proc_id = simgrid::s4u::this_actor::get_pid();
426 int dst_traced = getPid(comm, dst);
427 int src_traced = getPid(comm, src);
429 // FIXME: Hack the way to trace this one
430 std::vector<int>* dst_hack = new std::vector<int>;
431 std::vector<int>* src_hack = new std::vector<int>;
432 dst_hack->push_back(dst_traced);
433 src_hack->push_back(src_traced);
434 TRACE_smpi_comm_in(my_proc_id, __func__,
435 new simgrid::instr::VarCollTIData(
436 "sendRecv", -1, sendtype->is_replayable() ? sendcount : sendcount * sendtype->size(),
437 dst_hack, recvtype->is_replayable() ? recvcount : recvcount * recvtype->size(), src_hack,
438 simgrid::smpi::Datatype::encode(sendtype), simgrid::smpi::Datatype::encode(recvtype)));
440 TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, sendtag, sendcount * sendtype->size());
442 simgrid::smpi::Request::sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src,
443 recvtag, comm, status);
444 retval = MPI_SUCCESS;
446 TRACE_smpi_recv(src_traced, my_proc_id, recvtag);
447 TRACE_smpi_comm_out(my_proc_id);
454 int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
455 MPI_Comm comm, MPI_Status* status)
458 CHECK_BUFFER(1, buf, count)
459 CHECK_COUNT(2, count)
460 CHECK_TYPE(3, datatype)
462 int size = datatype->get_extent() * count;
463 xbt_assert(size > 0);
464 void* recvbuf = xbt_new0(char, size);
465 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
466 if(retval==MPI_SUCCESS){
467 simgrid::smpi::Datatype::copy(recvbuf, count, datatype, buf, count, datatype);
473 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
477 if (request == nullptr || flag == nullptr) {
478 retval = MPI_ERR_ARG;
479 } else if (*request == MPI_REQUEST_NULL) {
480 if (status != MPI_STATUS_IGNORE){
482 simgrid::smpi::Status::empty(status);
484 retval = MPI_SUCCESS;
486 int my_proc_id = ((*request)->comm() != MPI_COMM_NULL) ? simgrid::s4u::this_actor::get_pid() : -1;
488 TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("test"));
489 retval = simgrid::smpi::Request::test(request,status, flag);
491 TRACE_smpi_comm_out(my_proc_id);
497 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
500 CHECK_COUNT(1, count)
502 if (index == nullptr || flag == nullptr) {
503 retval = MPI_ERR_ARG;
505 int my_proc_id = simgrid::s4u::this_actor::get_pid();
506 TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("testany"));
507 retval = simgrid::smpi::Request::testany(count, requests, index, flag, status);
508 TRACE_smpi_comm_out(my_proc_id);
514 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
517 CHECK_COUNT(1, count)
519 if (flag == nullptr) {
520 retval = MPI_ERR_ARG;
522 int my_proc_id = simgrid::s4u::this_actor::get_pid();
523 TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("testall"));
524 retval = simgrid::smpi::Request::testall(count, requests, flag, statuses);
525 TRACE_smpi_comm_out(my_proc_id);
531 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
534 CHECK_COUNT(1, incount)
536 if (outcount == nullptr) {
537 retval = MPI_ERR_ARG;
539 int my_proc_id = simgrid::s4u::this_actor::get_pid();
540 TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("testsome"));
541 retval = simgrid::smpi::Request::testsome(incount, requests, outcount, indices, status);
542 TRACE_smpi_comm_out(my_proc_id);
548 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
554 if (source == MPI_PROC_NULL) {
555 if (status != MPI_STATUS_IGNORE){
556 simgrid::smpi::Status::empty(status);
557 status->MPI_SOURCE = MPI_PROC_NULL;
559 retval = MPI_SUCCESS;
561 simgrid::smpi::Request::probe(source, tag, comm, status);
562 retval = MPI_SUCCESS;
568 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
573 if (flag == nullptr) {
574 retval = MPI_ERR_ARG;
575 } else if (source == MPI_PROC_NULL) {
577 if (status != MPI_STATUS_IGNORE){
578 simgrid::smpi::Status::empty(status);
579 status->MPI_SOURCE = MPI_PROC_NULL;
581 retval = MPI_SUCCESS;
583 simgrid::smpi::Request::iprobe(source, tag, comm, flag, status);
584 retval = MPI_SUCCESS;
590 // TODO: cheinrich: Move declaration to other file? Rename this function - it's used for PMPI_Wait*?
591 static void trace_smpi_recv_helper(MPI_Request* request, MPI_Status* status);
592 static void trace_smpi_recv_helper(MPI_Request* request, MPI_Status* status)
594 MPI_Request req = *request;
595 if (req != MPI_REQUEST_NULL) { // Received requests become null
596 int src_traced = req->src();
597 // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
598 int dst_traced = req->dst();
599 if (req->flags() & MPI_REQ_RECV) { // Is this request a wait for RECV?
600 if (src_traced == MPI_ANY_SOURCE)
601 src_traced = (status != MPI_STATUS_IGNORE) ? req->comm()->group()->rank(status->MPI_SOURCE) : req->src();
602 TRACE_smpi_recv(src_traced, dst_traced, req->tag());
607 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
613 simgrid::smpi::Status::empty(status);
615 CHECK_NULL(1, MPI_ERR_ARG, request)
616 if (*request == MPI_REQUEST_NULL) {
617 retval = MPI_SUCCESS;
619 // for tracing, save the handle which might get overridden before we can use the helper on it
620 MPI_Request savedreq = *request;
621 if (savedreq != MPI_REQUEST_NULL && not(savedreq->flags() & MPI_REQ_FINISHED)
622 && not(savedreq->flags() & MPI_REQ_GENERALIZED))
623 savedreq->ref();//don't erase te handle in Request::wait, we'll need it later
625 savedreq = MPI_REQUEST_NULL;
627 int my_proc_id = (*request)->comm() != MPI_COMM_NULL
628 ? simgrid::s4u::this_actor::get_pid()
629 : -1; // TODO: cheinrich: Check if this correct or if it should be MPI_UNDEFINED
630 TRACE_smpi_comm_in(my_proc_id, __func__,
631 new simgrid::instr::WaitTIData((*request)->src(), (*request)->dst(), (*request)->tag()));
633 retval = simgrid::smpi::Request::wait(request, status);
635 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
636 TRACE_smpi_comm_out(my_proc_id);
637 trace_smpi_recv_helper(&savedreq, status);
638 if (savedreq != MPI_REQUEST_NULL)
639 simgrid::smpi::Request::unref(&savedreq);
646 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
648 if (index == nullptr)
655 // for tracing, save the handles which might get overridden before we can use the helper on it
656 std::vector<MPI_Request> savedreqs(requests, requests + count);
657 for (MPI_Request& req : savedreqs) {
658 if (req != MPI_REQUEST_NULL && not(req->flags() & MPI_REQ_FINISHED))
661 req = MPI_REQUEST_NULL;
664 int rank_traced = simgrid::s4u::this_actor::get_pid(); // FIXME: In PMPI_Wait, we check if the comm is null?
665 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("waitAny", count));
667 *index = simgrid::smpi::Request::waitany(count, requests, status);
669 if(*index!=MPI_UNDEFINED){
670 trace_smpi_recv_helper(&savedreqs[*index], status);
671 TRACE_smpi_comm_out(rank_traced);
674 for (MPI_Request& req : savedreqs)
675 if (req != MPI_REQUEST_NULL)
676 simgrid::smpi::Request::unref(&req);
682 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
685 CHECK_COUNT(1, count)
686 // for tracing, save the handles which might get overridden before we can use the helper on it
687 std::vector<MPI_Request> savedreqs(requests, requests + count);
688 for (MPI_Request& req : savedreqs) {
689 if (req != MPI_REQUEST_NULL && not(req->flags() & MPI_REQ_FINISHED))
692 req = MPI_REQUEST_NULL;
695 int rank_traced = simgrid::s4u::this_actor::get_pid(); // FIXME: In PMPI_Wait, we check if the comm is null?
696 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("waitall", count));
698 int retval = simgrid::smpi::Request::waitall(count, requests, status);
700 for (int i = 0; i < count; i++) {
701 trace_smpi_recv_helper(&savedreqs[i], status!=MPI_STATUSES_IGNORE ? &status[i]: MPI_STATUS_IGNORE);
703 TRACE_smpi_comm_out(rank_traced);
705 for (MPI_Request& req : savedreqs)
706 if (req != MPI_REQUEST_NULL)
707 simgrid::smpi::Request::unref(&req);
713 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
716 CHECK_COUNT(1, incount)
718 if (outcount == nullptr) {
719 retval = MPI_ERR_ARG;
721 *outcount = simgrid::smpi::Request::waitsome(incount, requests, indices, status);
722 retval = MPI_SUCCESS;
728 int PMPI_Cancel(MPI_Request* request)
734 if (*request == MPI_REQUEST_NULL) {
735 retval = MPI_ERR_REQUEST;
737 (*request)->cancel();
738 retval = MPI_SUCCESS;
744 int PMPI_Test_cancelled(const MPI_Status* status, int* flag){
745 if(status==MPI_STATUS_IGNORE){
749 *flag=simgrid::smpi::Status::cancelled(status);
753 int PMPI_Status_set_cancelled(MPI_Status* status, int flag){
754 if(status==MPI_STATUS_IGNORE){
757 simgrid::smpi::Status::set_cancelled(status,flag);
761 int PMPI_Status_set_elements(MPI_Status* status, MPI_Datatype datatype, int count){
762 if(status==MPI_STATUS_IGNORE){
765 simgrid::smpi::Status::set_elements(status,datatype, count);
769 int PMPI_Grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request){
770 return simgrid::smpi::Request::grequest_start(query_fn, free_fn,cancel_fn, extra_state, request);
773 int PMPI_Grequest_complete( MPI_Request request){
774 return simgrid::smpi::Request::grequest_complete(request);
777 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
778 if(request==MPI_REQUEST_NULL){
780 simgrid::smpi::Status::empty(status);
782 } else if (flag==NULL || status ==NULL){
785 return simgrid::smpi::Request::get_status(request,flag,status);
788 MPI_Request PMPI_Request_f2c(MPI_Fint request){
790 return MPI_REQUEST_NULL;
791 return static_cast<MPI_Request>(simgrid::smpi::Request::f2c(request));
794 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
795 if(request==MPI_REQUEST_NULL)
797 return request->c2f();