-found_request:
-#ifdef DEBUG_STEPH
- print_req( requests[cpt] );
-#endif
- requests[*index]->consumed = 1;
-#ifdef DEBUG_STEPH
- print_req( requests[cpt] );
-#endif
- DEBUG2("smpi_waitany() request %p unblocked ... mark *req[%d]->consumed",requests[*index],cpt);
- if (NULL != status) {
- status->MPI_SOURCE = requests[*index]->src;
- status->MPI_TAG = requests[*index]->tag;
- status->MPI_ERROR = MPI_SUCCESS;
+void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count,
+ MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+{
+ smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
+ smpi_mpi_bcast(recvbuf, count, datatype, 0, comm);
+
+/*
+FIXME: buggy implementation
+
+ int system_tag = 666;
+ int rank, size, other, index, datasize;
+ MPI_Request* requests;
+ void** tmpbufs;
+
+ rank = smpi_comm_rank(comm);
+ size = smpi_comm_size(comm);
+ datasize = smpi_datatype_size(datatype);
+ // Local copy from self
+ memcpy(recvbuf, sendbuf, count * datasize * sizeof(char));
+ // Send/Recv buffers to/from others;
+ //TODO: make a MPI_barrier here ?
+ requests = xbt_new(MPI_Request, 2 * (size - 1));
+ tmpbufs = xbt_new(void*, size - 1);
+ index = 0;
+ for(other = 0; other < size; other++) {
+ if(other != rank) {
+ tmpbufs[index / 2] = xbt_malloc(count * datasize);
+ requests[index] = smpi_mpi_isend(sendbuf, count, datatype, other, system_tag, comm);
+ requests[index + 1] = smpi_mpi_irecv(tmpbufs[index / 2], count, datatype, other, system_tag, comm);
+ index += 2;
+ }
+ }
+ // Wait for completion of all comms.
+ for(other = 0; other < 2 * (size - 1); other++) {
+ index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
+ if(index == MPI_UNDEFINED) {
+ break;
+ }
+ if((index & 1) == 1) {
+ // Request is odd: it's a irecv
+ smpi_op_apply(op, tmpbufs[index / 2], recvbuf, &count, &datatype);
+ }