if(request->flags & PREPARED)request->flags &= ~PREPARED;
if(request->flags & RECV) {
print_request("New recv", request);
+ //FIXME: if receive is posted with a large size, but send is smaller, mailboxes may not match !
if (request->size < sg_cfg_get_int("smpi/async_small_thres"))
mailbox = smpi_process_mailbox_small();
else
#ifdef HAVE_TRACING
int rank = smpi_process_index();
if (TRACE_smpi_view_internals()) {
- TRACE_smpi_send(rank, rank, receiver);
+ TRACE_smpi_send(rank, rank, receiver,request->size);
}
#endif
/* if(receiver == MPI_UNDEFINED) {*/
void smpi_mpi_request_free(MPI_Request * request)
{
-
if((*request) != MPI_REQUEST_NULL){
(*request)->refcount--;
if((*request)->refcount<0) xbt_die("wrong refcount");
{
MPI_Request request =
build_request(buf==MPI_BOTTOM ? (void*)0 : buf , count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
- comm, NON_PERSISTENT | SEND | PREPARED);
+ comm, NON_PERSISTENT | ISEND | SEND | PREPARED);
return request;
}
if(requests[i]!= MPI_REQUEST_NULL){
if (smpi_mpi_test(&requests[i], pstat)!=1){
flag=0;
+ }else{
+ requests[i]=MPI_REQUEST_NULL;
}
}else{
smpi_empty_status(pstat);
simcall_comm_wait((*request)->action, -1.0);
}
finish_wait(request, status);
-
+ request=MPI_REQUEST_NULL;
// FIXME for a detached send, finish_wait is not called:
}
for(i = 0; i < incount; i++) {
if((requests[i] != MPI_REQUEST_NULL)) {
if(smpi_mpi_test(&requests[i], pstat)) {
- indices[count] = i;
+ indices[i] = 1;
count++;
if(status != MPI_STATUSES_IGNORE) {
status[i] = *pstat;
// FIXME: check for errors
smpi_datatype_extent(sendtype, &lb, &sendext);
// Local copy from root
- smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
- sendcount, sendtype, recvbuf, recvcount, recvtype);
+ if(recvbuf!=MPI_IN_PLACE){
+ smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
+ sendcount, sendtype, recvbuf, recvcount, recvtype);
+ }
// Send buffers to receivers
requests = xbt_new(MPI_Request, size - 1);
index = 0;
// FIXME: check for errors
smpi_datatype_extent(sendtype, &lb, &sendext);
// Local copy from root
- smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
+ if(recvbuf!=MPI_IN_PLACE){
+ smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
sendtype, recvbuf, recvcount, recvtype);
+ }
// Send buffers to receivers
requests = xbt_new(MPI_Request, size - 1);
index = 0;
MPI_Request *requests;
void **tmpbufs;
+
char* sendtmpbuf = (char*) sendbuf;
if( sendbuf == MPI_IN_PLACE ) {
- sendtmpbuf = (char *)recvbuf;
+ sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
+ smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
}
rank = smpi_comm_rank(comm);
}
xbt_free(tmpbufs);
xbt_free(requests);
+
+ if( sendbuf == MPI_IN_PLACE ) {
+ xbt_free(sendtmpbuf);
+ }
}
}
void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
{
- int system_tag = 888;
+ int system_tag = -888;
int rank, size, other, index;
MPI_Aint lb = 0, dataext = 0;
MPI_Request *requests;
}
// Wait for completion of all comms.
smpi_mpi_startall(size - 1, requests);
- for(other = 0; other < size - 1; other++) {
- index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
- if(index == MPI_UNDEFINED) {
- break;
+
+ if(smpi_op_is_commute(op)){
+ for(other = 0; other < size - 1; other++) {
+ index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
+ if(index == MPI_UNDEFINED) {
+ break;
+ }
+ if(index < rank) {
+ // #Request is below rank: it's a irecv
+ smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
+ }
+ }
+ }else{
+ //non commutative case, wait in order
+ for(other = 0; other < size - 1; other++) {
+ smpi_mpi_wait(&(requests[other]), MPI_STATUS_IGNORE);
+ if(index < rank) {
+ smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
+ }
+ }
+ }
+ for(index = 0; index < rank; index++) {
+ xbt_free(tmpbufs[index]);
+ }
+ xbt_free(tmpbufs);
+ xbt_free(requests);
+}
+
+void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count,
+ MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+{
+ int system_tag = -888;
+ int rank, size, other, index;
+ MPI_Aint lb = 0, dataext = 0;
+ MPI_Request *requests;
+ void **tmpbufs;
+ int recvbuf_is_empty=1;
+ rank = smpi_comm_rank(comm);
+ size = smpi_comm_size(comm);
+
+ // FIXME: check for errors
+ smpi_datatype_extent(datatype, &lb, &dataext);
+
+ // Send/Recv buffers to/from others;
+ requests = xbt_new(MPI_Request, size - 1);
+ tmpbufs = xbt_new(void *, rank);
+ index = 0;
+ for(other = 0; other < rank; other++) {
+ // FIXME: possibly overkill we we have contiguous/noncontiguous data
+ // mapping...
+ tmpbufs[index] = xbt_malloc(count * dataext);
+ requests[index] =
+ smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag,
+ comm);
+ index++;
+ }
+ for(other = rank + 1; other < size; other++) {
+ requests[index] =
+ smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm);
+ index++;
+ }
+ // Wait for completion of all comms.
+ smpi_mpi_startall(size - 1, requests);
+ if(smpi_op_is_commute(op)){
+ for(other = 0; other < size - 1; other++) {
+ index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
+ if(index == MPI_UNDEFINED) {
+ break;
+ }
+ if(index < rank) {
+ if(recvbuf_is_empty){
+ smpi_datatype_copy(tmpbufs[index], count, datatype, recvbuf, count, datatype);
+ recvbuf_is_empty=0;
+ }else
+ // #Request is below rank: it's a irecv
+ smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
+ }
}
- if(index < rank) {
- // #Request is below rank: it's a irecv
- smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
+ }else{
+ //non commutative case, wait in order
+ for(other = 0; other < size - 1; other++) {
+ smpi_mpi_wait(&(requests[other]), MPI_STATUS_IGNORE);
+ if(index < rank) {
+ if(recvbuf_is_empty){
+ smpi_datatype_copy(tmpbufs[other], count, datatype, recvbuf, count, datatype);
+ recvbuf_is_empty=0;
+ }else smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
+ }
}
}
for(index = 0; index < rank; index++) {