smpi_bench_end();
double now = SIMIX_get_clock();
- unsigned long long sec = (unsigned long long)now;
+ unsigned long long sec = static_cast<unsigned long long>(now);
unsigned long long pre = (now - sec) * smpi_rastro_resolution();
smpi_bench_begin();
return static_cast<unsigned long long>(sec) * smpi_rastro_resolution() + pre;
char* name = xbt_strdup("/tmp/simgrid-shmalloc-XXXXXX");
smpi_shared_malloc_bogusfile = mkstemp(name);
unlink(name);
- free(name);
+ xbt_free(name);
char* dumb = (char*)calloc(1, smpi_shared_malloc_blocksize);
ssize_t err = write(smpi_shared_malloc_bogusfile, dumb, smpi_shared_malloc_blocksize);
if(err<0)
xbt_die("Could not write bogus file for shared malloc");
- free(dumb);
+ xbt_free(dumb);
}
/* Map the bogus file in place of the anonymous memory */
if(rank_==0){
bar_ = MSG_barrier_init(comm_size);
}
+ mode_=0;
comm->add_rma_win(this);
}
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;
}