Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpi io: restore position after calls which should not modify it (add seek calls...
authorAugustin Degomme <adegomme@users.noreply.github.com>
Tue, 9 Aug 2022 14:10:42 +0000 (16:10 +0200)
committerAugustin Degomme <adegomme@users.noreply.github.com>
Tue, 9 Aug 2022 14:29:43 +0000 (16:29 +0200)
src/smpi/bindings/smpi_pmpi_file.cpp
src/smpi/mpi/smpi_file.cpp

index 1faed5f..2fa04be 100644 (file)
@@ -200,9 +200,12 @@ int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_D
   const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
+  MPI_Offset prev;
+  fh->get_position(&prev);
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if (ret == MPI_SUCCESS)
     ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
+  fh->seek(prev,MPI_SEEK_SET);
   TRACE_smpi_comm_out(rank_traced);
   return ret;
 }
@@ -215,9 +218,12 @@ int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,M
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - read_at_all", count * datatype->size()));
+  MPI_Offset prev;
+  fh->get_position(&prev);
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if (ret == MPI_SUCCESS)
     ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
+  fh->seek(prev,MPI_SEEK_SET);
   TRACE_smpi_comm_out(rank_traced);
   return ret;
 }
@@ -229,9 +235,12 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int coun
   const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
+  MPI_Offset prev;
+  fh->get_position(&prev);
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if (ret == MPI_SUCCESS)
     ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
+  fh->seek(prev,MPI_SEEK_SET);
   TRACE_smpi_comm_out(rank_traced);
   return ret;
 }
@@ -244,9 +253,12 @@ int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - write_at_all", count * datatype->size()));
+  MPI_Offset prev;
+  fh->get_position(&prev);
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if (ret == MPI_SUCCESS)
     ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
+  fh->seek(prev,MPI_SEEK_SET);
   TRACE_smpi_comm_out(rank_traced);
   return ret;
 }
index 9eac544..4c1a6cb 100644 (file)
@@ -204,6 +204,8 @@ int File::read_ordered(MPI_File fh, void* buf, int count, const Datatype* dataty
 
   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::read>(buf, count, datatype, status);
   if (fh->comm_->rank() == fh->comm_->size() - 1) {
@@ -213,6 +215,7 @@ int File::read_ordered(MPI_File fh, void* buf, int count, const Datatype* dataty
   }
   char c;
   simgrid::smpi::colls::bcast(&c, 1, MPI_BYTE, fh->comm_->size() - 1, fh->comm_);
+  fh->seek(prev, MPI_SEEK_SET);
   return ret;
 }
 
@@ -239,11 +242,14 @@ int File::write_shared(MPI_File fh, const void* buf, int count, const Datatype*
 {
   fh->shared_mutex_->lock();
   XBT_DEBUG("Write shared on %s - Shared ptr before : %lld", fh->file_->get_path(), *(fh->shared_file_pointer_));
+  MPI_Offset prev;
+  fh->get_position(&prev);
   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->shared_mutex_->unlock();
+  fh->seek(prev, MPI_SEEK_SET);
   return MPI_SUCCESS;
 }
 
@@ -258,6 +264,8 @@ int File::write_ordered(MPI_File fh, const void* buf, int count, const Datatype*
   }
   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) {
@@ -267,6 +275,7 @@ int File::write_ordered(MPI_File fh, const void* buf, int count, const Datatype*
   }
   char c;
   simgrid::smpi::colls::bcast(&c, 1, MPI_BYTE, fh->comm_->size() - 1, fh->comm_);
+  fh->seek(prev, MPI_SEEK_SET);
   return ret;
 }