-/**
- *i multiply two vectors element-wise
- *
- * @param a the first vectors
- * @param b the second vectors
- * @return the second vector is modified and contains the element-wise products
- **/
-void smpi_mpi_prod_func(void *a, void *b, int *length,
- MPI_Datatype * datatype);
-
-void smpi_mpi_prod_func(void *a, void *b, int *length, MPI_Datatype * datatype)
-{
- int i;
- if ((*datatype == smpi_mpi_global->mpi_byte) || (*datatype == smpi_mpi_global->mpi_char)) {
- char *x = a, *y = b;
- for (i = 0; i < *length; i++) {
- y[i] = x[i] * y[i];
- }
- } else if (*datatype == smpi_mpi_global->mpi_int) {
- int *x = a, *y = b;
- for (i = 0; i < *length; i++) {
- y[i] = x[i] * y[i];
- }
- } else if (*datatype == smpi_mpi_global->mpi_float) {
- float *x = a, *y = b;
- for (i = 0; i < *length; i++) {
- y[i] = x[i] * y[i];
- }
- } else if (*datatype == smpi_mpi_global->mpi_double) {
- double *x = a, *y = b;
- for (i = 0; i < *length; i++) {
- y[i] = x[i] * y[i];
- }
+
+/* MPI Low level calls */
+MPI_Request smpi_mpi_isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
+ MPI_Request request;
+
+ request = xbt_new(s_smpi_mpi_request_t, 1);
+ request->comm = comm;
+ request->src = smpi_comm_rank(comm);
+ request->dst = dst;
+ request->tag = tag;
+ request->size = smpi_datatype_size(datatype) * count;
+ request->complete = 0;
+ request->data = request;
+ smpi_process_post_send(comm, request);
+ request->pair = SIMIX_network_isend(request->rdv, request->size, -1.0, buf, request->size, NULL);
+ return request;
+}
+
+MPI_Request smpi_mpi_irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) {
+ MPI_Request request;
+
+ request = xbt_new(s_smpi_mpi_request_t, 1);
+ request->comm = comm;
+ request->src = src;
+ request->dst = smpi_comm_rank(comm);
+ request->tag = tag;
+ request->size = smpi_datatype_size(datatype) * count;
+ request->complete = 0;
+ request->data = MPI_REQUEST_NULL;
+ smpi_process_post_recv(request);
+ request->pair = SIMIX_network_irecv(request->rdv, buf, &request->size);
+ return request;
+}
+
+void smpi_mpi_recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status) {
+ MPI_Request request;
+
+ request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
+ smpi_mpi_wait(&request, status);
+}
+
+void smpi_mpi_send(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) {
+ MPI_Request request;
+
+ request = smpi_mpi_isend(buf, count, datatype, src, tag, comm);
+ smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
+}
+
+void smpi_mpi_sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status) {
+ MPI_Request requests[2];
+ MPI_Status stats[2];
+
+ requests[0] = smpi_mpi_isend(sendbuf, sendcount, sendtype, dst, sendtag, comm);
+ requests[1] = smpi_mpi_irecv(recvbuf, recvcount, recvtype, src, recvtag, comm);
+ smpi_mpi_waitall(2, requests, stats);
+ if(status != MPI_STATUS_IGNORE) {
+ // Copy receive status
+ memcpy(status, &stats[1], sizeof(MPI_Status));