Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Test using macros for arguments checking, saves some duplicated lines.
authorAugustin Degomme <adegomme@users.noreply.github.com>
Wed, 17 Apr 2019 11:44:47 +0000 (13:44 +0200)
committerAugustin Degomme <adegomme@users.noreply.github.com>
Wed, 17 Apr 2019 11:44:47 +0000 (13:44 +0200)
src/smpi/bindings/smpi_pmpi_file.cpp
src/smpi/include/smpi_file.hpp
src/smpi/mpi/smpi_file.cpp

index 5c14cdf..fe35968 100644 (file)
@@ -42,11 +42,18 @@ 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
-  if (fh==MPI_FILE_NULL){\r
-    return MPI_ERR_FILE;\r
-  } else {\r
+  CHECK_FILE(fh);
+  else {\r
     smpi_bench_end();\r
     int ret = fh->seek(offset,whence);\r
     smpi_bench_begin();\r
@@ -55,19 +62,23 @@ int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){
 }\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
+  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
     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
index 9172071..43ecdd5 100644 (file)
@@ -23,7 +23,7 @@ class File{
   int flags();\r
   int sync();\r
   int seek(MPI_Offset offset, int whence);\r
-  int read(void *buf, int count,MPI_Datatype datatype, MPI_Status *status);\r
+  static int read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status);\r
   static int close(MPI_File *fh);\r
   static int del(char *filename, MPI_Info info);\r
 };\r
index 35e36d4..1beffe9 100644 (file)
@@ -61,16 +61,20 @@ namespace smpi{
     return MPI_SUCCESS;\r
   }\r
   \r
-  int File::read(void *buf, int count, MPI_Datatype datatype, MPI_Status *status){\r
+  int File::read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status){\r
     //get position first as we may be doing non contiguous reads and it will probably be updated badly\r
-    MPI_Offset position = file_->tell();\r
+    MPI_Offset position = fh->file_->tell();\r
     MPI_Offset movesize = datatype->get_extent()*count;\r
     MPI_Offset readsize = datatype->size()*count;\r
-    XBT_DEBUG("Position before read in MPI_File %s : %llu",file_->get_path(),file_->tell());\r
-    MPI_Offset read = file_->read(readsize);\r
-    XBT_DEBUG("Read in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", file_->get_path(), read, readsize, movesize);\r
+    XBT_DEBUG("Position before read in MPI_File %s : %llu",fh->file_->get_path(),fh->file_->tell());\r
+    MPI_Offset read = fh->file_->read(readsize);\r
+    XBT_DEBUG("Read in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", fh->file_->get_path(), read, readsize, movesize);\r
     if(readsize!=movesize){\r
-      file_->seek(position+movesize, SEEK_SET);\r
+      fh->file_->seek(position+movesize, SEEK_SET);\r
+    }\r
+    XBT_DEBUG("Position after read in MPI_File %s : %llu",fh->file_->get_path(), fh->file_->tell());\r
+    return MPI_SUCCESS;\r
+  }\r
     }\r
     XBT_DEBUG("Position after read in MPI_File %s : %llu",file_->get_path(), file_->tell());\r
     return MPI_SUCCESS;\r