-/* Copyright (c) 2007-2015. The SimGrid Team.
+/* Copyright (c) 2007-2017. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
std::unordered_map<int, smpi_key_elem> Win::keyvals_;
int Win::keyval_id_=0;
-Win::Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm): base_(base), size_(size), disp_unit_(disp_unit), assert_(0), info_(info), comm_(comm){
+Win::Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, int allocated, int dynamic): base_(base), size_(size), disp_unit_(disp_unit), assert_(0), info_(info), comm_(comm), allocated_(allocated), dynamic_(dynamic){
int comm_size = comm->size();
rank_ = comm->rank();
XBT_DEBUG("Creating window");
if(rank_==0){
bar_ = MSG_barrier_init(comm_size);
}
+ mode_=0;
comm->add_rma_win(this);
xbt_mutex_destroy(mut_);
xbt_mutex_destroy(lock_mut_);
+ if(allocated_ !=0)
+ xbt_free(base_);
+
cleanup_attr<Win>();
}
+int Win::attach (void *base, MPI_Aint size){
+ if (!(base_ == MPI_BOTTOM || base_ == 0))
+ return MPI_ERR_ARG;
+ base_=0;//actually the address will be given in the RMA calls, as being the disp.
+ size_+=size;
+ return MPI_SUCCESS;
+}
+
+int Win::detach (void *base){
+ base_=MPI_BOTTOM;
+ size_=-1;
+ return MPI_SUCCESS;
+}
+
void Win::get_name(char* name, int* length){
if(name_==nullptr){
*length=0;
}
}
+MPI_Info Win::info(){
+ if(info_== MPI_INFO_NULL)
+ info_ = new Info();
+ info_->ref();
+ return info_;
+}
+
int Win::rank(){
return rank_;
}
return disp_unit_;
}
+int Win::dynamic(){
+ return dynamic_;
+}
+
+void Win::set_info(MPI_Info info){
+ if(info_!= MPI_INFO_NULL)
+ info->ref();
+ info_=info;
+}
void Win::set_name(char* name){
name_ = xbt_strdup(name);
int size = static_cast<int>(reqs->size());
// start all requests that have been prepared by another process
if (size > 0) {
- for (const auto& req : *reqs) {
- if (req && (req->flags() & PREPARED))
- req->start();
- }
-
MPI_Request* treqs = &(*reqs)[0];
-
Request::waitall(size, treqs, MPI_STATUSES_IGNORE);
}
count_=0;
xbt_mutex_release(mut_);
}
+
+ if(assert==MPI_MODE_NOSUCCEED)//there should be no ops after this one, tell we are closed.
+ opened_=0;
assert_ = assert;
MSG_barrier_wait(bar_);
xbt_mutex_release(recv_win->mut_);
//start send
sreq->start();
-
+ rreq->start();
//push request to sender's win
xbt_mutex_acquire(mut_);
requests_->push_back(sreq);
xbt_mutex_release(recv_win->mut_);
//start send
sreq->start();
-
+ rreq->start();
//push request to sender's win
xbt_mutex_acquire(mut_);
requests_->push_back(sreq);
return MPI_SUCCESS;
}
+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){
+
+ //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);
+
+ get(result_addr, result_count, result_datatype, target_rank,
+ target_disp, target_count, target_datatype);
+ accumulate(origin_addr, origin_count, origin_datatype, target_rank,
+ target_disp, target_count, target_datatype, op);
+
+ return MPI_SUCCESS;
+
+}
+
int Win::start(MPI_Group group, int assert){
/* From MPI forum advices
The call to MPI_WIN_COMPLETE does not return until the put call has completed at the origin; and the target window
int Win::wait(){
//naive, blocking implementation.
XBT_DEBUG("Entering MPI_Win_Wait");
- int i=0,j=0;
- int size = group_->size();
+ int i = 0;
+ int j = 0;
+ int size = group_->size();
MPI_Request* reqs = xbt_new0(MPI_Request, size);
while(j!=size){
}
int Win::lock(int lock_type, int rank, int assert){
+ if(opened_!=0)
+ return MPI_ERR_WIN;
+
MPI_Win target_win = connected_wins_[rank];
- //window already locked, we have to wait
- if (lock_type == MPI_LOCK_EXCLUSIVE){
- XBT_DEBUG("Win_lock - Entering lock %d", rank);
+ if ((lock_type == MPI_LOCK_EXCLUSIVE && target_win->mode_ != MPI_LOCK_SHARED)|| target_win->mode_ == MPI_LOCK_EXCLUSIVE){
xbt_mutex_acquire(target_win->lock_mut_);
- XBT_DEBUG("Win_lock - Released from lock %d", rank);
-}
+ target_win->mode_+= lock_type;//add the lock_type to differentiate case when we are switching from EXCLUSIVE to SHARED (no release needed in the unlock)
+ if(lock_type == MPI_LOCK_SHARED){//the window used to be exclusive, it's now shared.
+ xbt_mutex_release(target_win->lock_mut_);
+ }
+ } else if(!(target_win->mode_==MPI_LOCK_SHARED && lock_type == MPI_LOCK_EXCLUSIVE))
+ target_win->mode_+= lock_type; // don't set to exclusive if it's already shared
- xbt_mutex_acquire(target_win->mut_);
target_win->lockers_.push_back(comm_->rank());
- xbt_mutex_release(target_win->mut_);
int finished = finish_comms();
- XBT_DEBUG("Win_lock - Finished %d RMA calls", finished);
+ XBT_DEBUG("Win_lock %d - Finished %d RMA calls", rank, finished);
return MPI_SUCCESS;
}
int Win::unlock(int rank){
- MPI_Win target_win = connected_wins_[rank];
+ if(opened_!=0)
+ return MPI_ERR_WIN;
- xbt_mutex_acquire(target_win->mut_);
- int size=target_win->lockers_.size();
+ MPI_Win target_win = connected_wins_[rank];
+ int target_mode = target_win->mode_;
+ target_win->mode_= 0;
target_win->lockers_.remove(comm_->rank());
-
-
- if (size<=1){//0 or 1 lockers -> exclusive assumed
- xbt_mutex_try_acquire(target_win->lock_mut_);
+ if (target_mode==MPI_LOCK_EXCLUSIVE){
xbt_mutex_release(target_win->lock_mut_);
}
- xbt_mutex_release(target_win->mut_);
+
int finished = finish_comms();
- XBT_DEBUG("Win_unlock - Finished %d RMA calls", finished);
+ XBT_DEBUG("Win_unlock %d - Finished %d RMA calls", rank, finished);
return MPI_SUCCESS;
}
std::vector<MPI_Request> *reqqs = requests_;
int size = static_cast<int>(reqqs->size());
if (size > 0) {
- // start all requests that have been prepared by another process
- for (const auto& req : *reqqs) {
- if (req && (req->flags() & PREPARED))
- req->start();
- }
-
MPI_Request* treqs = &(*reqqs)[0];
Request::waitall(size, treqs, MPI_STATUSES_IGNORE);
reqqs->clear();