-/* int size = comm->size;
- int i, k, line = -1;
- int sendto, recvfrom, distance, *displs=NULL, *blen=NULL;
- int maxpacksize, packsize, position;
- char * tmpbuf=NULL, *packbuf=NULL;
- ptrdiff_t lb, sext, rext;
- int err = 0;
- int weallocated = 0;
- MPI_Datatype iddt;
-
- rank = smpi_mpi_comm_rank(comm);
-*/
- INFO0("coll:tuned:alltoall_intra_bruck ** NOT IMPLEMENTED YET**");
-/*
- displs = xbt_malloc(size*sizeof(int));
- blen = xbt_malloc(size*sizeof(int));
-
- weallocated = 1;
-*/
- /* Prepare for packing data */
-/*
- err = MPI_Pack_size( scount*size, sdtype, comm, &maxpacksize );
- if (err != MPI_SUCCESS) { }
-*/
- /* pack buffer allocation */
-/* packbuf = (char*) malloc((unsigned) maxpacksize);
- if (packbuf == NULL) { }
-*/
- /* tmp buffer allocation for message data */
-/* tmpbuf = xbt_malloc(scount*size*sext);
- if (tmpbuf == NULL) { }
-*/
-
- /* Step 1 - local rotation - shift up by rank */
-/* err = ompi_ddt_copy_content_same_ddt (sdtype, (int32_t) ((size-rank)*scount),
- tmpbuf, ((char*)sbuf)+rank*scount*sext);
- if (err<0) {
- line = __LINE__; err = -1; goto err_hndl;
- }
-
- if (rank != 0) {
- err = ompi_ddt_copy_content_same_ddt (sdtype, (int32_t) (rank*scount),
- tmpbuf+(size-rank)*scount*sext, (char*)sbuf);
- if (err<0) {
- line = __LINE__; err = -1; goto err_hndl;
- }
- }
-*/
- /* perform communication step */
-/* for (distance = 1; distance < size; distance<<=1) {
-*/
- /* send data to "sendto" */
-/* sendto = (rank+distance)%size;
- recvfrom = (rank-distance+size)%size;
- packsize = 0;
- k = 0;
-*/
- /* create indexed datatype */
-// for (i = 1; i < size; i++) {
-// if ((i&distance) == distance) {
-// displs[k] = i*scount; blen[k] = scount;
-// k++;
-// }
-// }
- /* Set indexes and displacements */
-// err = MPI_Type_indexed(k, blen, displs, sdtype, &iddt);
-// if (err != MPI_SUCCESS) { line = __LINE__; goto err_hndl; }
-// /* Commit the new datatype */
-/// err = MPI_Type_commit(&iddt);
-// if (err != MPI_SUCCESS) { line = __LINE__; goto err_hndl; }
-
- /* have the new distribution ddt, pack and exchange data */
-// err = MPI_Pack(tmpbuf, 1, iddt, packbuf, maxpacksize, &packsize, comm);
-// if (err != MPI_SUCCESS) { line = __LINE__; goto err_hndl; }
-
- /* Sendreceive */
-// err = ompi_coll_tuned_sendrecv ( packbuf, packsize, MPI_PACKED, sendto,
-// MCA_COLL_BASE_TAG_ALLTOALL,
-// rbuf, packsize, MPI_PACKED, recvfrom,
-// MCA_COLL_BASE_TAG_ALLTOALL,
-// comm, MPI_STATUS_IGNORE, rank);
-// if (err != MPI_SUCCESS) { line = __LINE__; goto err_hndl; }
-
- /* Unpack data from rbuf to tmpbuf */
-// position = 0;
-// err = MPI_Unpack(rbuf, packsize, &position,
-// tmpbuf, 1, iddt, comm);
-// if (err != MPI_SUCCESS) { line = __LINE__; goto err_hndl; }
-
- /* free ddt */
-// err = MPI_Type_free(&iddt);
-// if (err != MPI_SUCCESS) { line = __LINE__; goto err_hndl; }
-// } /* end of for (distance = 1... */
-
- /* Step 3 - local rotation - */
-// for (i = 0; i < size; i++) {
-
-// err = ompi_ddt_copy_content_same_ddt (rdtype, (int32_t) rcount,
-// ((char*)rbuf)+(((rank-i+size)%size)*rcount*rext),
-// tmpbuf+i*rcount*rext);
-//
-// if (err<0) {
-// line = __LINE__; err = -1; goto err_hndl;
-// }
-// }
-
- /* Step 4 - clean up */
-/* if (tmpbuf != NULL) free(tmpbuf);
- if (packbuf != NULL) free(packbuf);
- if (weallocated) {
- if (displs != NULL) free(displs);
- if (blen != NULL) free(blen);
- }
- return OMPI_SUCCESS;
-
-err_hndl:
- OPAL_OUTPUT((ompi_coll_tuned_stream,"%s:%4d\tError occurred %d, rank %2d", __FILE__,line,err,rank));
- if (tmpbuf != NULL) free(tmpbuf);
- if (packbuf != NULL) free(packbuf);
- if (weallocated) {
- if (displs != NULL) free(displs);
- if (blen != NULL) free(blen);
- }
- return err;
- */
- return -1; /* FIXME: to be changed*/
+ int system_tag = 888;
+ int i, rank, size, err, count;
+ MPI_Aint lb = 0, sendext = 0, recvext = 0;
+ MPI_Request *requests;
+
+ /* Initialize. */
+ rank = smpi_comm_rank(comm);
+ size = smpi_comm_size(comm);
+ XBT_DEBUG("<%d> algorithm alltoall_basic_linear() called.", rank);
+ err = smpi_datatype_extent(sendtype, &lb, &sendext);
+ err = smpi_datatype_extent(recvtype, &lb, &recvext);
+ /* simple optimization */
+ err = smpi_datatype_copy((char *)sendbuf + rank * sendcount * sendext,
+ sendcount, sendtype,
+ (char *)recvbuf + rank * recvcount * recvext,
+ recvcount, recvtype);
+ if (err == MPI_SUCCESS && size > 1) {
+ /* Initiate all send/recv to/from others. */
+ requests = xbt_new(MPI_Request, 2 * (size - 1));
+ /* Post all receives first -- a simple optimization */
+ count = 0;
+ for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) {
+ requests[count] =
+ smpi_irecv_init((char *)recvbuf + i * recvcount * recvext, recvcount,
+ recvtype, i, system_tag, comm);
+ count++;
+ }
+ /* Now post all sends in reverse order
+ * - We would like to minimize the search time through message queue
+ * when messages actually arrive in the order in which they were posted.
+ * TODO: check the previous assertion
+ */
+ for (i = (rank + size - 1) % size; i != rank; i = (i + size - 1) % size) {
+ requests[count] =
+ smpi_isend_init((char *)sendbuf + i * sendcount * sendext, sendcount,
+ sendtype, i, system_tag, comm);
+ count++;
+ }
+ /* Wait for them all. */
+ smpi_mpi_startall(count, requests);
+ XBT_DEBUG("<%d> wait for %d requests", rank, count);
+ smpi_mpi_waitall(count, requests, MPI_STATUS_IGNORE);
+ xbt_free(requests);
+ }
+ return err;