Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
index 1f6e472f1503512234a45f6fd59b83a552b6c0ca..97dbb67317827978130cc613fc8b3d2931147461 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -9,12 +9,12 @@
 #include "smpi_datatype.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
-#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 CHECK_WRONLY(fh)                                                                                               \
+  if ((fh)->flags() & MPI_MODE_WRONLY)                                                                                 \
+    return MPI_ERR_AMODE;
 #define PASS_ZEROCOUNT(count)                                                                                          \
   if ((count) == 0) {                                                                                                  \
     status->count = 0;                                                                                                 \
@@ -26,7 +26,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
   CHECK_BUFFER(2, buf, count)                                                                                          \
   CHECK_COUNT(3, count)                                                                                                \
   CHECK_TYPE(4, datatype)                                                                                              \
-  CHECK_NULL(5, MPI_ERR_ARG, status)
 
 #define CHECK_FILE_INPUT_OFFSET                                                                                        \
   CHECK_FILE(1, fh)                                                                                                    \
@@ -34,7 +33,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
   CHECK_OFFSET(3, offset)                                                                                                 \
   CHECK_COUNT(4, count)                                                                                                \
   CHECK_TYPE(5, datatype)                                                                                              \
-  CHECK_NULL(6, MPI_ERR_ARG, status)
 
 extern MPI_Errhandler SMPI_default_File_Errhandler;
 
@@ -99,8 +97,8 @@ int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){
 }
 
 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
-
-  CHECK_FLAGS(fh)
+  CHECK_FILE_INPUTS
+  CHECK_WRONLY(fh)
   PASS_ZEROCOUNT(count)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -113,7 +111,7 @@ int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_
 
 int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
+  CHECK_WRONLY(fh)
   PASS_ZEROCOUNT(count)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -127,7 +125,6 @@ int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatyp
 
 int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
   CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
   smpi_bench_end();
@@ -141,7 +138,6 @@ int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatyp
 
 int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
   CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
   smpi_bench_end();
@@ -156,7 +152,7 @@ int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype
 
 int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
+  CHECK_WRONLY(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", count * datatype->size()));
@@ -168,7 +164,7 @@ int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype,
 
 int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
+  CHECK_WRONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
@@ -181,7 +177,6 @@ int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype dataty
 
 int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
   CHECK_RDONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -194,7 +189,6 @@ int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype dat
 
 int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
   CHECK_RDONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -208,8 +202,8 @@ int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype
 
 int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
-  CHECK_FLAGS(fh)
-  PASS_ZEROCOUNT(count);
+  CHECK_WRONLY(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 - read", count * datatype->size()));
@@ -224,7 +218,7 @@ int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_D
 
 int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUT_OFFSET
-  CHECK_FLAGS(fh)
+  CHECK_WRONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
@@ -240,9 +234,8 @@ int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,M
 
 int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUT_OFFSET
-  CHECK_FLAGS(fh)
   CHECK_RDONLY(fh)
-  PASS_ZEROCOUNT(count);
+  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", count * datatype->size()));
@@ -257,7 +250,6 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int coun
 
 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_INPUT_OFFSET
-  CHECK_FLAGS(fh)
   CHECK_RDONLY(fh)
   smpi_bench_end();
   int rank_traced = simgrid::s4u::this_actor::get_pid();
@@ -281,6 +273,29 @@ int PMPI_File_delete(const char *filename, MPI_Info info){
   return ret;
 }
 
+int PMPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, const char *datarep, MPI_Info info){
+  CHECK_FILE(1, fh)
+  if(not ((fh->flags() & MPI_MODE_SEQUENTIAL) && (disp == MPI_DISPLACEMENT_CURRENT)))
+    CHECK_OFFSET(2, disp)
+  CHECK_TYPE(3, etype)
+  CHECK_TYPE(4, filetype)
+  smpi_bench_end();
+  int ret = fh->set_view(disp, etype, filetype, datarep, info);
+  smpi_bench_begin();
+  return ret;
+}
+
+int PMPI_File_get_view(MPI_File fh, MPI_Offset *disp, MPI_Datatype *etype, MPI_Datatype *filetype, char *datarep){
+  CHECK_FILE(1, fh)
+  CHECK_NULL(2, MPI_ERR_ARG, disp)
+  CHECK_NULL(3, MPI_ERR_ARG, etype)
+  CHECK_NULL(4, MPI_ERR_ARG, filetype)
+  smpi_bench_end();
+  int ret = fh->get_view(disp, etype, filetype, datarep);
+  smpi_bench_begin();
+  return ret;
+}
+
 int PMPI_File_get_info(MPI_File  fh, MPI_Info* info)
 {
   CHECK_FILE(1, fh)
@@ -354,6 +369,8 @@ int PMPI_File_call_errhandler(MPI_File file,int errorcode){
   if (file == nullptr) {
     return MPI_ERR_WIN;
   }
-  file->errhandler()->call(file, errorcode);
+  MPI_Errhandler err = file->errhandler();
+  err->call(file, errorcode);
+  simgrid::smpi::Errhandler::unref(err);
   return MPI_SUCCESS;
 }