Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Read_at, Write, Write_at
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
index 8af99f1..5844463 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
@@ -38,6 +42,109 @@ int PMPI_File_close(MPI_File *fh){
     return ret;\r
   }\r
 }\r
+#define CHECK_FILE(fh) if(fh==MPI_FILE_NULL) return MPI_ERR_FILE\r
+#define CHECK_BUFFER(buf, count)  else if (buf==nullptr && count > 0) return MPI_ERR_BUFFER\r
+#define CHECK_COUNT(count)  else if ( count < 0) return MPI_ERR_COUNT\r
+#define CHECK_OFFSET(offset)  else if ( offset < 0) return MPI_ERR_DISP\r
+#define PASS_ZEROCOUNT(count)  else if ( count == 0) return MPI_SUCCESS\r
+#define CHECK_DATATYPE(datatype, count) else if ( datatype == MPI_DATATYPE_NULL && count > 0) return MPI_ERR_TYPE\r
+#define CHECK_STATUS(status) else if (status == nullptr) return MPI_ERR_ARG\r
+#define CHECK_FLAGS(fh) else if (fh->flags() & MPI_MODE_SEQUENTIAL) return MPI_ERR_AMODE\r
+\r
+int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){\r
+  CHECK_FILE(fh);
+  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
+  CHECK_FILE(fh);
+  CHECK_BUFFER(buf, count);\r
+  CHECK_COUNT(count);\r
+  PASS_ZEROCOUNT(count);\r
+  CHECK_DATATYPE(datatype, count);\r
+  CHECK_STATUS(status);\r
+  CHECK_FLAGS(fh);\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 = simgrid::smpi::File::read(fh, buf, count, datatype, status);\r
+    TRACE_smpi_comm_out(rank_traced);\r
+    smpi_bench_begin();\r
+    return ret;\r
+  }\r
+}\r
+\r
+int PMPI_File_write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){\r
+  CHECK_FILE(fh);
+  CHECK_BUFFER(buf, count);\r
+  CHECK_COUNT(count);\r
+  PASS_ZEROCOUNT(count);\r
+  CHECK_DATATYPE(datatype, count);\r
+  CHECK_STATUS(status);\r
+  CHECK_FLAGS(fh);\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 - write", static_cast<double>(count*datatype->size())));\r
+    int ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);\r
+    TRACE_smpi_comm_out(rank_traced);\r
+    smpi_bench_begin();\r
+    return ret;\r
+  }\r
+}\r
+\r
+int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){\r
+  CHECK_FILE(fh);
+  CHECK_BUFFER(buf, count);\r
+  CHECK_OFFSET(offset);\r
+  CHECK_COUNT(count);\r
+  PASS_ZEROCOUNT(count);\r
+  CHECK_DATATYPE(datatype, count);\r
+  CHECK_STATUS(status);\r
+  CHECK_FLAGS(fh);\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->seek(offset,SEEK_SET);\r
+    if(ret!=MPI_SUCCESS)\r
+      return ret;\r
+    ret = simgrid::smpi::File::read(fh, 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_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){\r
+  CHECK_FILE(fh);
+  CHECK_BUFFER(buf, count);\r
+  CHECK_OFFSET(offset);\r
+  CHECK_COUNT(count);\r
+  PASS_ZEROCOUNT(count);\r
+  CHECK_DATATYPE(datatype, count);\r
+  CHECK_STATUS(status);\r
+  CHECK_FLAGS(fh);\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 - write", static_cast<double>(count*datatype->size())));\r
+    int ret = fh->seek(offset,SEEK_SET);\r
+    if(ret!=MPI_SUCCESS)\r
+      return ret;\r
+    ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);\r
+    TRACE_smpi_comm_out(rank_traced);\r
+    smpi_bench_begin();\r
+    return ret;\r
+  }\r
+}\r
 \r
 int PMPI_File_delete(char *filename, MPI_Info info){\r
   if (filename == nullptr) {\r
@@ -48,4 +155,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