+/* MPI Low level calls */
+MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype,
+ int dst, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag,
+ comm, PERSISTENT | SEND);
+ request->refcount++;
+ return request;
+}
+
+MPI_Request smpi_mpi_ssend_init(void *buf, int count, MPI_Datatype datatype,
+ int dst, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag,
+ comm, PERSISTENT | SSEND | SEND);
+ request->refcount++;
+ return request;
+}
+
+MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype,
+ int src, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag,
+ comm, PERSISTENT | RECV);
+ request->refcount++;
+ return request;
+}
+
+void smpi_mpi_start(MPI_Request request)
+{
+ smx_rdv_t mailbox;
+
+ xbt_assert(!request->action,
+ "Cannot (re)start a non-finished communication");
+ if(request->flags & RECV) {
+ print_request("New recv", request);
+ if (request->size < sg_cfg_get_int("smpi/async_small_thres"))
+ mailbox = smpi_process_mailbox_small();
+ else
+ mailbox = smpi_process_mailbox();
+ // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
+ request->real_size=request->size;
+ smpi_datatype_use(request->old_type);
+ request->action = simcall_comm_irecv(mailbox, request->buf, &request->real_size, &match_recv, request);
+
+ //integrate pseudo-timing for buffering of small messages, do not bother to execute the simcall if 0
+ double sleeptime = request->detached ? smpi_or(request->size) : 0.0;
+ if(sleeptime!=0.0){
+ simcall_process_sleep(sleeptime);
+ XBT_DEBUG("receiving size of %zu : sleep %lf ", request->size, smpi_or(request->size));
+ }
+
+ } else {
+
+
+ int receiver = smpi_group_index(smpi_comm_group(request->comm), request->dst);
+
+ #ifdef HAVE_TRACING
+ int rank = smpi_process_index();
+ if (TRACE_smpi_view_internals()) {
+ TRACE_smpi_send(rank, rank, receiver);
+ }
+ #endif
+/* if(receiver == MPI_UNDEFINED) {*/
+/* XBT_WARN("Trying to send a message to a wrong rank");*/
+/* return;*/
+/* }*/
+ print_request("New send", request);
+ if (request->size < sg_cfg_get_int("smpi/async_small_thres")) { // eager mode
+ mailbox = smpi_process_remote_mailbox_small(receiver);
+ }else{
+ XBT_DEBUG("Send request %p is not in the permanent receive mailbox (buf: %p)",request,request->buf);
+ mailbox = smpi_process_remote_mailbox(receiver);
+ }
+ if ( (! (request->flags & SSEND)) && (request->size < sg_cfg_get_int("smpi/send_is_detached_thres"))) {
+ void *oldbuf = NULL;
+ request->detached = 1;
+ request->refcount++;
+ if(request->old_type->has_subtype == 0){
+ oldbuf = request->buf;
+ if (oldbuf){
+ request->buf = xbt_malloc(request->size);
+ memcpy(request->buf,oldbuf,request->size);
+ }
+ }
+ XBT_DEBUG("Send request %p is detached; buf %p copied into %p",request,oldbuf,request->buf);
+ }
+ // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
+ request->real_size=request->size;
+ smpi_datatype_use(request->old_type);
+
+ //if we are giving back the control to the user without waiting for completion, we have to inject timings
+ double sleeptime =0.0;
+ if(request->detached || (request->flags & (ISEND|SSEND))){// issend should be treated as isend
+ //isend and send timings may be different
+ sleeptime = (request->flags & ISEND)? smpi_ois(request->size) : smpi_os(request->size);
+ }
+
+ if(sleeptime!=0.0){
+ simcall_process_sleep(sleeptime);
+ XBT_DEBUG("sending size of %zu : sleep %lf ", request->size, smpi_os(request->size));
+ }
+
+ request->action =
+ simcall_comm_isend(mailbox, request->size, -1.0,
+ request->buf, request->real_size,
+ &match_send,
+ &smpi_mpi_request_free_voidp, // how to free the userdata if a detached send fails
+ request,
+ // detach if msg size < eager/rdv switch limit
+ request->detached);
+
+#ifdef HAVE_TRACING
+ /* FIXME: detached sends are not traceable (request->action == NULL) */
+ if (request->action)
+ simcall_set_category(request->action, TRACE_internal_smpi_get_category());
+
+#endif
+
+ }
+
+}
+
+void smpi_mpi_startall(int count, MPI_Request * requests)