Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
For File, we can change the default error handler by specifying MPI_FILE_NULL as...
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
index e03a4a6..41e1a38 100644 (file)
@@ -8,7 +8,9 @@
 #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){
+extern MPI_Errhandler SMPI_default_File_Errhandler;
+
+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)
@@ -97,7 +99,7 @@ int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_
   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 - read", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
   int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
@@ -114,14 +116,15 @@ int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatyp
   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 - read_shared", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__,
+                     new simgrid::instr::CpuTIData("IO - read_shared", count * datatype->size()));
   int ret = simgrid::smpi::File::read_shared(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
   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)
@@ -132,14 +135,14 @@ int PMPI_File_write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI
   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);
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
+  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)
@@ -150,7 +153,8 @@ int PMPI_File_write_shared(MPI_File fh, void *buf, int count,MPI_Datatype dataty
   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_shared", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__,
+                     new simgrid::instr::CpuTIData("IO - write_shared", count * datatype->size()));
   int ret = simgrid::smpi::File::write_shared(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
@@ -166,7 +170,7 @@ int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype,
   CHECK_FLAGS(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 - read_all", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_all", count * datatype->size()));
   int ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
@@ -182,14 +186,15 @@ int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype dataty
   CHECK_FLAGS(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 - read_ordered", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__,
+                     new simgrid::instr::CpuTIData("IO - read_ordered", count * datatype->size()));
   int ret = simgrid::smpi::File::read_ordered(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
   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)
@@ -199,14 +204,14 @@ int PMPI_File_write_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype,
   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);
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", count * datatype->size()));
+  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)
@@ -216,7 +221,8 @@ int PMPI_File_write_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datat
   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())));
+  TRACE_smpi_comm_in(rank_traced, __func__,
+                     new simgrid::instr::CpuTIData("IO - write_ordered", count * datatype->size()));
   int ret = simgrid::smpi::File::write_ordered(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
   smpi_bench_begin();
@@ -234,7 +240,7 @@ int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_D
   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 - read", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if(ret!=MPI_SUCCESS)
     return ret;
@@ -254,7 +260,8 @@ int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,M
   CHECK_FLAGS(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 - read_at_all", static_cast<double>(count*datatype->size())));
+  TRACE_smpi_comm_in(rank_traced, __func__,
+                     new simgrid::instr::CpuTIData("IO - read_at_all", count * datatype->size()));
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if(ret!=MPI_SUCCESS)
     return ret;
@@ -264,7 +271,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)
@@ -276,17 +283,17 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_
   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())));
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
   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)
@@ -297,17 +304,18 @@ int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,
   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())));
+  TRACE_smpi_comm_in(rank_traced, __func__,
+                     new simgrid::instr::CpuTIData("IO - write_at_all", 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();
@@ -357,3 +365,38 @@ int PMPI_File_sync(MPI_File  fh)
   fh->sync();
   return MPI_SUCCESS;
 }
+
+int PMPI_File_create_errhandler(MPI_File_errhandler_function* function, MPI_Errhandler* errhandler){
+  *errhandler=new simgrid::smpi::Errhandler(function);
+  return MPI_SUCCESS;
+}
+
+int PMPI_File_get_errhandler(MPI_File file, MPI_Errhandler* errhandler){
+  if (errhandler==nullptr){
+    return MPI_ERR_ARG;
+  } else if (file == MPI_FILE_NULL) {
+    *errhandler = SMPI_default_File_Errhandler;
+    return MPI_SUCCESS;
+  }
+  *errhandler=file->errhandler();
+  return MPI_SUCCESS;
+}
+
+int PMPI_File_set_errhandler(MPI_File file, MPI_Errhandler errhandler){
+  if (errhandler==nullptr){
+    return MPI_ERR_ARG;
+  } else if (file == MPI_FILE_NULL) {
+    SMPI_default_File_Errhandler = errhandler;
+    return MPI_SUCCESS;
+  }
+  file->set_errhandler(errhandler);
+  return MPI_SUCCESS;
+}
+
+int PMPI_File_call_errhandler(MPI_File file,int errorcode){
+  if (file == nullptr) {
+    return MPI_ERR_WIN;
+  }
+  file->errhandler()->call(file, errorcode);
+  return MPI_SUCCESS;
+}