From: Augustin Degomme Date: Wed, 17 Apr 2019 11:44:47 +0000 (+0200) Subject: Test using macros for arguments checking, saves some duplicated lines. X-Git-Tag: v3.22.2~101^2~14 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3bac1010bd3a0a8a1760e89c40869e4954ab6cf2 Test using macros for arguments checking, saves some duplicated lines. --- diff --git a/src/smpi/bindings/smpi_pmpi_file.cpp b/src/smpi/bindings/smpi_pmpi_file.cpp index 5c14cdf5cb..fe35968136 100644 --- a/src/smpi/bindings/smpi_pmpi_file.cpp +++ b/src/smpi/bindings/smpi_pmpi_file.cpp @@ -42,11 +42,18 @@ int PMPI_File_close(MPI_File *fh){ return ret; } } +#define CHECK_FILE(fh) if(fh==MPI_FILE_NULL) return MPI_ERR_FILE +#define CHECK_BUFFER(buf, count) else if (buf==nullptr && count > 0) return MPI_ERR_BUFFER +#define CHECK_COUNT(count) else if ( count < 0) return MPI_ERR_COUNT +#define CHECK_OFFSET(offset) else if ( offset < 0) return MPI_ERR_DISP +#define PASS_ZEROCOUNT(count) else if ( count == 0) return MPI_SUCCESS +#define CHECK_DATATYPE(datatype, count) else if ( datatype == MPI_DATATYPE_NULL && count > 0) return MPI_ERR_TYPE +#define CHECK_STATUS(status) else if (status == nullptr) return MPI_ERR_ARG +#define CHECK_FLAGS(fh) else if (fh->flags() & MPI_MODE_SEQUENTIAL) return MPI_ERR_AMODE int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){ - if (fh==MPI_FILE_NULL){ - return MPI_ERR_FILE; - } else { + CHECK_FILE(fh); + else { smpi_bench_end(); int ret = fh->seek(offset,whence); smpi_bench_begin(); @@ -55,19 +62,23 @@ int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){ } int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - if (fh==MPI_FILE_NULL){ - return MPI_ERR_FILE; - } else if (buf==nullptr && count > 0){ - return MPI_ERR_BUFFER; - } else if ( count < 0){ - return MPI_ERR_COUNT; - } else if ( datatype == MPI_DATATYPE_NULL && count > 0){ - return MPI_ERR_TYPE; - } else if (status == nullptr){ - return MPI_ERR_ARG; - } else if (fh->flags() & MPI_MODE_SEQUENTIAL){ - return MPI_ERR_AMODE; - } else { + CHECK_FILE(fh); + CHECK_BUFFER(buf, count); + CHECK_COUNT(count); + PASS_ZEROCOUNT(count); + CHECK_DATATYPE(datatype, count); + CHECK_STATUS(status); + CHECK_FLAGS(fh); + else { + 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(count*datatype->size()))); + int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status); + TRACE_smpi_comm_out(rank_traced); + smpi_bench_begin(); + return ret; + } +} 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(count*datatype->size()))); diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp index 917207130f..43ecdd5b74 100644 --- a/src/smpi/include/smpi_file.hpp +++ b/src/smpi/include/smpi_file.hpp @@ -23,7 +23,7 @@ class File{ int flags(); int sync(); int seek(MPI_Offset offset, int whence); - int read(void *buf, int count,MPI_Datatype datatype, MPI_Status *status); + static int read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status); static int close(MPI_File *fh); static int del(char *filename, MPI_Info info); }; diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp index 35e36d4e4c..1beffe98af 100644 --- a/src/smpi/mpi/smpi_file.cpp +++ b/src/smpi/mpi/smpi_file.cpp @@ -61,16 +61,20 @@ namespace smpi{ return MPI_SUCCESS; } - int File::read(void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ + int File::read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ //get position first as we may be doing non contiguous reads and it will probably be updated badly - MPI_Offset position = file_->tell(); + MPI_Offset position = fh->file_->tell(); MPI_Offset movesize = datatype->get_extent()*count; MPI_Offset readsize = datatype->size()*count; - XBT_DEBUG("Position before read in MPI_File %s : %llu",file_->get_path(),file_->tell()); - MPI_Offset read = file_->read(readsize); - XBT_DEBUG("Read in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", file_->get_path(), read, readsize, movesize); + XBT_DEBUG("Position before read in MPI_File %s : %llu",fh->file_->get_path(),fh->file_->tell()); + MPI_Offset read = fh->file_->read(readsize); + XBT_DEBUG("Read in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", fh->file_->get_path(), read, readsize, movesize); if(readsize!=movesize){ - file_->seek(position+movesize, SEEK_SET); + fh->file_->seek(position+movesize, SEEK_SET); + } + XBT_DEBUG("Position after read in MPI_File %s : %llu",fh->file_->get_path(), fh->file_->tell()); + return MPI_SUCCESS; + } } XBT_DEBUG("Position after read in MPI_File %s : %llu",file_->get_path(), file_->tell()); return MPI_SUCCESS;