return retval;
}
+/**
+ * MPI_Sendrecv
+ **/
+int SMPI_MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
+ void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag,
+ MPI_Comm comm, MPI_Status *status)
+{
+int rank;
+int retval = MPI_SUCCESS;
+smpi_mpi_request_t srequest;
+smpi_mpi_request_t rrequest;
+
+ rank = smpi_mpi_comm_rank(comm);
+
+ /* send */
+ /* -------------*/
+ retval = smpi_create_request(sendbuf, sendcount, sendtype,
+ rank,dest,sendtag,
+ comm, &srequest);
+ printf("[%d] isend request src=%d -> dst=%d (retval=%d)\n",rank,rank,dest,retval);
+ smpi_mpi_isend(srequest);
+
+
+ //retval = MPI_Isend( sendbuf, sendcount, sendtype, dest, sendtag, MPI_COMM_WORLD, &srequest);
+
+
+ /* recv */
+ retval = smpi_create_request(recvbuf, recvcount, recvtype,
+ source, rank,recvtag,
+ comm, &rrequest);
+ printf("[%d] irecv request src=%d -> dst=%d (retval=%d)\n",rank,source,rank,retval);
+ smpi_mpi_irecv(rrequest);
+
+ //retval = MPI_Irecv( recvbuf, recvcount, recvtype, source, recvtag, MPI_COMM_WORLD, &rrequest);
+
+
+ smpi_mpi_wait(srequest, MPI_STATUS_IGNORE);
+ printf("[%d] isend request src=%d dst=%d tag=%d COMPLETED (retval=%d) \n",rank,rank,dest,sendtag,retval);
+
+ smpi_mpi_wait(rrequest, MPI_STATUS_IGNORE);
+ printf("[%d] irecv request src=%d -> dst=%d tag=%d COMPLETED (retval=%d)\n",rank,source,rank,recvtag,retval);
+
+ return(retval);
+}
+
+
/**
* MPI_Wait and friends
**/
-#ifdef DEBUG_REDUCE
+//#ifdef DEBUG_REDUCE
/**
* debugging helper function
**/
-static void print_buffer_int(void *buf, int len, const char *msg, int rank)
+static void print_buffer_int(void *buf, int len, char *msg, int rank)
{
int tmp, *v;
printf("**[%d] %s: ", rank, msg);
printf("\n");
free(msg);
}
-#endif
+static void print_buffer_double(void *buf, int len, char *msg, int rank)
+{
+ int tmp;
+ double *v;
+ printf("**[%d] %s: ", rank, msg);
+ for (tmp = 0; tmp < len; tmp++) {
+ v = buf;
+ printf("[%lf]", v[tmp]);
+ }
+ printf("\n");
+ free(msg);
+}
+
+//#endif
/**
* MPI_Reduce
**/
}
+/**
+ * MPI_Scatter user entry point
+ **/
+//int SMPI_MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype datatype,
+// void *recvbuf, int recvcount, MPI_Datatype recvtype,int root,
+// MPI_Comm comm);
+int SMPI_MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype datatype,
+ void *recvbuf, int recvcount, MPI_Datatype recvtype,
+ int root, MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ int i;
+ int cnt=0;
+ int rank;
+ int tag=0;
+ char *cptr; // to manipulate the void * buffers
+ smpi_mpi_request_t *requests;
+ smpi_mpi_request_t request;
+ smpi_mpi_status_t status;
+
+
+ smpi_bench_end();
+
+ rank = smpi_mpi_comm_rank(comm);
+
+ requests = xbt_malloc((comm->size-1) * sizeof(smpi_mpi_request_t));
+ if (rank == root) {
+ // i am the root: distribute my sendbuf
+ //print_buffer_int(sendbuf, comm->size, xbt_strdup("rcvbuf"), rank);
+ cptr = sendbuf;
+ for (i=0; i < comm->size; i++) {
+ if ( i!=root ) { // send to processes ...
+
+ retval = smpi_create_request((void *)cptr, sendcount,
+ datatype, root, i, tag, comm, &(requests[cnt]));
+ if (NULL != requests[cnt] && MPI_SUCCESS == retval) {
+ if (MPI_SUCCESS == retval) {
+ smpi_mpi_isend(requests[cnt]);
+ }
+ }
+ cnt++;
+ }
+ else { // ... except if it's me.
+ memcpy(recvbuf, (void *)cptr, recvcount*recvtype->size*sizeof(char));
+ }
+ cptr += sendcount*datatype->size;
+ }
+ for(i=0; i<cnt; i++) { // wait for send to complete
+ /* FIXME: waitall() should be slightly better */
+ smpi_mpi_wait(requests[i], &status);
+ xbt_mallocator_release(smpi_global->request_mallocator, requests[i]);
+
+ }
+ }
+ else { // i am a non-root process: wait data from the root
+ retval = smpi_create_request(recvbuf,recvcount,
+ recvtype, root, rank, tag, comm, &request);
+ if (NULL != request && MPI_SUCCESS == retval) {
+ if (MPI_SUCCESS == retval) {
+ smpi_mpi_irecv(request);
+ }
+ }
+ smpi_mpi_wait(request, &status);
+ xbt_mallocator_release(smpi_global->request_mallocator, request);
+ }
+ xbt_free(requests);
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+
+/**
+ * MPI_Alltoall user entry point
+ *
+ * Uses the logic of OpenMPI (upto 1.2.7 or greater) for the optimizations
+ * ompi/mca/coll/tuned/coll_tuned_module.c
+ **/
+int SMPI_MPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype datatype,
+ void *recvbuf, int recvcount, MPI_Datatype recvtype,
+ MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ int block_dsize;
+ int rank;
+
+ smpi_bench_end();
+
+ rank = smpi_mpi_comm_rank(comm);
+ block_dsize = datatype->size * sendcount;
+
+ if ((block_dsize < 200) && (comm->size > 12)) {
+ retval = smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, datatype,
+ recvbuf, recvcount, recvtype, comm);
+
+ } else if (block_dsize < 3000) {
+/* use this one !! retval = smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount, datatype,
+ recvbuf, recvcount, recvtype, comm);
+ */
+ retval = smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, datatype,
+ recvbuf, recvcount, recvtype, comm);
+ } else {
+
+ retval = smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, datatype,
+ recvbuf, recvcount, recvtype, comm);
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+