+int Win::get_accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr,
+ int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count,
+ MPI_Datatype target_datatype, MPI_Op op, MPI_Request* request){
+
+ //get sender pointer
+ MPI_Win send_win = connected_wins_[target_rank];
+
+ if(opened_==0){//check that post/start has been done
+ // no fence or start .. lock ok ?
+ int locked=0;
+ for(auto it : send_win->lockers_)
+ if (it == comm_->rank())
+ locked = 1;
+ if(locked != 1)
+ return MPI_ERR_WIN;
+ }
+
+ if(target_count*target_datatype->get_extent()>send_win->size_)
+ return MPI_ERR_ARG;
+
+ XBT_DEBUG("Entering MPI_Get_accumulate from %d", target_rank);
+ //need to be sure ops are correctly ordered, so finish request here ? slow.
+ MPI_Request req;
+ xbt_mutex_acquire(send_win->atomic_mut_);
+ get(result_addr, result_count, result_datatype, target_rank,
+ target_disp, target_count, target_datatype, &req);
+ if (req != MPI_REQUEST_NULL)
+ Request::wait(&req, MPI_STATUS_IGNORE);
+ if(op!=MPI_NO_OP)
+ accumulate(origin_addr, origin_count, origin_datatype, target_rank,
+ target_disp, target_count, target_datatype, op, &req);
+ if (req != MPI_REQUEST_NULL)
+ Request::wait(&req, MPI_STATUS_IGNORE);
+ xbt_mutex_release(send_win->atomic_mut_);
+ return MPI_SUCCESS;
+
+}
+
+int Win::compare_and_swap(void *origin_addr, void *compare_addr,
+ void *result_addr, MPI_Datatype datatype, int target_rank,
+ MPI_Aint target_disp){
+ //get sender pointer
+ MPI_Win send_win = connected_wins_[target_rank];
+
+ if(opened_==0){//check that post/start has been done
+ // no fence or start .. lock ok ?
+ int locked=0;
+ for(auto it : send_win->lockers_)
+ if (it == comm_->rank())
+ locked = 1;
+ if(locked != 1)
+ return MPI_ERR_WIN;
+ }
+
+ XBT_DEBUG("Entering MPI_Compare_and_swap with %d", target_rank);
+ MPI_Request req;
+ xbt_mutex_acquire(send_win->atomic_mut_);
+ get(result_addr, 1, datatype, target_rank,
+ target_disp, 1, datatype, &req);
+ if (req != MPI_REQUEST_NULL)
+ Request::wait(&req, MPI_STATUS_IGNORE);
+ if(! memcmp (result_addr, compare_addr, datatype->get_extent() )){
+ put(origin_addr, 1, datatype, target_rank,
+ target_disp, 1, datatype);
+ }
+ xbt_mutex_release(send_win->atomic_mut_);
+ return MPI_SUCCESS;
+}
+