Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
read, seek + init
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
index 8af99f1..5c14cdf 100644 (file)
@@ -5,6 +5,7 @@
 \r
 #include "private.hpp"\r
 #include "smpi_file.hpp"\r
+#include "smpi_datatype.hpp"\r
 \r
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);\r
 \r
@@ -19,10 +20,13 @@ int PMPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_
     smpi_bench_end();\r
     *fh =  new simgrid::smpi::File(comm, filename, amode, info);\r
     smpi_bench_begin();\r
-    if((*fh)->size()==0 && not amode & MPI_MODE_CREATE){\r
+    if (((*fh)->size() == 0 && (not amode & MPI_MODE_CREATE)) ||\r
+       ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL))){\r
       delete fh;\r
       return MPI_ERR_AMODE;\r
     }\r
+    if(amode & MPI_MODE_APPEND)\r
+      (*fh)->seek(0,MPI_SEEK_END);\r
     return MPI_SUCCESS;\r
   }\r
 }\r
@@ -39,6 +43,42 @@ int PMPI_File_close(MPI_File *fh){
   }\r
 }\r
 \r
+int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){\r
+  if (fh==MPI_FILE_NULL){\r
+    return MPI_ERR_FILE;\r
+  } else {\r
+    smpi_bench_end();\r
+    int ret = fh->seek(offset,whence);\r
+    smpi_bench_begin();\r
+    return ret;\r
+  }\r
+}\r
+\r
+int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){\r
+  if (fh==MPI_FILE_NULL){\r
+    return MPI_ERR_FILE;\r
+  } else if (buf==nullptr && count > 0){\r
+    return MPI_ERR_BUFFER;\r
+  } else if ( count < 0){\r
+    return MPI_ERR_COUNT;\r
+  } else if ( datatype == MPI_DATATYPE_NULL && count > 0){\r
+    return MPI_ERR_TYPE;\r
+  } else if (status == nullptr){\r
+    return MPI_ERR_ARG;\r
+  } else if (fh->flags() & MPI_MODE_SEQUENTIAL){\r
+    return MPI_ERR_AMODE;\r
+  } else {\r
+    smpi_bench_end();\r
+    int rank_traced = simgrid::s4u::this_actor::get_pid();\r
+    TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));\r
+    int ret = fh->read(buf, count, datatype, status);\r
+    TRACE_smpi_comm_out(rank_traced);\r
+    smpi_bench_begin();\r
+    return ret;\r
+  }\r
+}\r
+\r
+\r
 int PMPI_File_delete(char *filename, MPI_Info info){\r
   if (filename == nullptr) {\r
     return MPI_ERR_FILE;\r
@@ -48,4 +88,5 @@ int PMPI_File_delete(char *filename, MPI_Info info){
     smpi_bench_begin();\r
     return ret;\r
   }\r
-}
\ No newline at end of file
+}\r
+\r