- int File::write_shared(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status){
- fh->shared_mutex_->lock();
- fh->seek(*(fh->shared_file_pointer_),MPI_SEEK_SET);
- write(fh, const_cast<void*>(buf), count, datatype, status);
+int File::write_shared(MPI_File fh, const void* buf, int count, const Datatype* datatype, MPI_Status* status)
+{
+ const std::scoped_lock lock(*fh->shared_mutex_);
+ XBT_DEBUG("Write shared on %s - Shared ptr before : %lld", fh->file_->get_path(), *(fh->shared_file_pointer_));
+ fh->seek(*(fh->shared_file_pointer_), MPI_SEEK_SET);
+ write(fh, const_cast<void*>(buf), count, datatype, status);
+ *(fh->shared_file_pointer_) = fh->file_->tell();
+ XBT_DEBUG("Write shared on %s - Shared ptr after : %lld", fh->file_->get_path(), *(fh->shared_file_pointer_));
+ fh->seek(*(fh->shared_file_pointer_), MPI_SEEK_SET);
+ return MPI_SUCCESS;
+}
+
+int File::write_ordered(MPI_File fh, const void* buf, int count, const Datatype* datatype, MPI_Status* status)
+{
+ // 0 needs to get the shared pointer value
+ MPI_Offset val;
+ if (fh->comm_->rank() == 0) {
+ val = *(fh->shared_file_pointer_);
+ } else {
+ val = count * datatype->size();
+ }
+ MPI_Offset result;
+ simgrid::smpi::colls::scan(&val, &result, 1, MPI_OFFSET, MPI_SUM, fh->comm_);
+ MPI_Offset prev;
+ fh->get_position(&prev);
+ fh->seek(result, MPI_SEEK_SET);
+ int ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
+ if (fh->comm_->rank() == fh->comm_->size() - 1) {
+ const std::scoped_lock lock(*fh->shared_mutex_);