Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
index cdb35bd..df39eae 100644 (file)
@@ -4,13 +4,11 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "private.hpp"
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
 
 #include "smpi_file.hpp"
 #include "smpi_datatype.hpp"
 
-
-int PMPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh){
+int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh){
   if (comm == MPI_COMM_NULL)
     return MPI_ERR_COMM;
   if (filename == nullptr)
@@ -20,8 +18,7 @@ int PMPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_
   smpi_bench_end();
   *fh =  new simgrid::smpi::File(comm, filename, amode, info);
   smpi_bench_begin();
-  if (((*fh)->size() == 0 && not (amode & MPI_MODE_CREATE)) ||
-     ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL))){
+  if ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL)){
     delete fh;
     return MPI_ERR_AMODE;
   }
@@ -46,6 +43,7 @@ int PMPI_File_close(MPI_File *fh){
 #define CHECK_DATATYPE(datatype, count) if (datatype == MPI_DATATYPE_NULL && count > 0) return MPI_ERR_TYPE;
 #define CHECK_STATUS(status) if (status == nullptr) return MPI_ERR_ARG;
 #define CHECK_FLAGS(fh) if (fh->flags() & MPI_MODE_SEQUENTIAL) return MPI_ERR_AMODE;
+#define CHECK_RDONLY(fh) if (fh->flags() & MPI_MODE_RDONLY ) return MPI_ERR_AMODE;
 
 #define PASS_ZEROCOUNT(count) if (count == 0) {\
 status->count=0;\
@@ -123,30 +121,32 @@ int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatyp
   return ret;
 }
 
-int PMPI_File_write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
+int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE(fh)
   CHECK_BUFFER(buf, count)
   CHECK_COUNT(count)
   CHECK_DATATYPE(datatype, count)
   CHECK_STATUS(status)
   CHECK_FLAGS(fh)
+  CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
-  int ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
+  int ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
   return ret;
 }
 
-int PMPI_File_write_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
+int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE(fh)
   CHECK_BUFFER(buf, count)
   CHECK_COUNT(count)
   CHECK_DATATYPE(datatype, count)
   CHECK_STATUS(status)
   CHECK_FLAGS(fh)
+  CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -189,29 +189,31 @@ int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype dataty
   return ret;
 }
 
-int PMPI_File_write_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
+int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE(fh)
   CHECK_BUFFER(buf, count)
   CHECK_COUNT(count)
   CHECK_DATATYPE(datatype, count)
   CHECK_STATUS(status)
   CHECK_FLAGS(fh)
+  CHECK_RDONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", static_cast<double>(count*datatype->size())));
-  int ret = fh->op_all<simgrid::smpi::File::write>(buf, count, datatype, status);
+  int ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
   return ret;
 }
 
-int PMPI_File_write_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
+int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE(fh)
   CHECK_BUFFER(buf, count)
   CHECK_COUNT(count)
   CHECK_DATATYPE(datatype, count)
   CHECK_STATUS(status)
   CHECK_FLAGS(fh)
+  CHECK_RDONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_ordered", static_cast<double>(count*datatype->size())));
@@ -262,7 +264,7 @@ int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,M
   return ret;
 }
 
-int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
+int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE(fh)
   CHECK_BUFFER(buf, count)
   CHECK_OFFSET(offset)
@@ -270,6 +272,7 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_
   CHECK_DATATYPE(datatype, count)
   CHECK_STATUS(status)
   CHECK_FLAGS(fh)
+  CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count);
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -277,13 +280,13 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if(ret!=MPI_SUCCESS)
     return ret;
-  ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
+  ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
   return ret;
 }
 
-int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
+int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE(fh)
   CHECK_BUFFER(buf, count)
   CHECK_OFFSET(offset)
@@ -291,19 +294,20 @@ int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,
   CHECK_DATATYPE(datatype, count)
   CHECK_STATUS(status)
   CHECK_FLAGS(fh)
+  CHECK_RDONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_at_all", static_cast<double>(count*datatype->size())));
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if(ret!=MPI_SUCCESS)
     return ret;
-  ret = fh->op_all<simgrid::smpi::File::write>(buf, count, datatype, status);
+  ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
   return ret;
 }
 
-int PMPI_File_delete(char *filename, MPI_Info info){
+int PMPI_File_delete(const char *filename, MPI_Info info){
   if (filename == nullptr)
     return MPI_ERR_FILE;
   smpi_bench_end();
@@ -324,4 +328,32 @@ int PMPI_File_set_info(MPI_File  fh, MPI_Info info)
   CHECK_FILE(fh)
   fh->set_info(info);
   return MPI_SUCCESS;
-}
\ No newline at end of file
+}
+
+int PMPI_File_get_size(MPI_File  fh, MPI_Offset* size)
+{
+  CHECK_FILE(fh)
+  *size = fh->size();
+  return MPI_SUCCESS;
+}
+
+int PMPI_File_get_amode(MPI_File  fh, int* amode)
+{
+  CHECK_FILE(fh)
+  *amode = fh->flags();
+  return MPI_SUCCESS;
+}
+
+int PMPI_File_get_group(MPI_File  fh, MPI_Group* group)
+{
+  CHECK_FILE(fh)
+  *group = fh->comm()->group();
+  return MPI_SUCCESS;
+}
+
+int PMPI_File_sync(MPI_File  fh)
+{
+  CHECK_FILE(fh)
+  fh->sync();
+  return MPI_SUCCESS;
+}