From 381959205c50d615e514a291f2a8cdd35d8a5af7 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Mon, 15 Apr 2019 01:53:02 +0200 Subject: [PATCH] Skeleton for MPI_IO --- include/smpi/forward.hpp | 3 ++ include/smpi/smpi.h | 5 +-- src/smpi/bindings/smpi_mpi.cpp | 6 ++-- src/smpi/bindings/smpi_pmpi_file.cpp | 51 ++++++++++++++++++++++++++ src/smpi/include/smpi_file.hpp | 30 ++++++++++++++++ src/smpi/mpi/smpi_file.cpp | 53 ++++++++++++++++++++++++++++ tools/cmake/DefinePackages.cmake | 3 ++ 7 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 src/smpi/bindings/smpi_pmpi_file.cpp create mode 100644 src/smpi/include/smpi_file.hpp create mode 100644 src/smpi/mpi/smpi_file.cpp diff --git a/include/smpi/forward.hpp b/include/smpi/forward.hpp index b23b1856af..e3039c42a8 100644 --- a/include/smpi/forward.hpp +++ b/include/smpi/forward.hpp @@ -17,6 +17,7 @@ class Coll; class Colls; class Comm; class Datatype; +class File; class Group; class Info; class Keyval; @@ -35,6 +36,7 @@ class Win; typedef simgrid::smpi::Comm SMPI_Comm; typedef simgrid::smpi::Datatype SMPI_Datatype; +typedef simgrid::smpi::File SMPI_File; typedef simgrid::smpi::Group SMPI_Group; typedef simgrid::smpi::Info SMPI_Info; typedef simgrid::smpi::Op SMPI_Op; @@ -49,6 +51,7 @@ typedef simgrid::smpi::Win SMPI_Win; typedef struct SMPI_Comm SMPI_Comm; typedef struct SMPI_Datatype SMPI_Datatype; +typedef struct SMPI_File SMPI_File; typedef struct SMPI_Group SMPI_Group; typedef struct SMPI_Info SMPI_Info; typedef struct SMPI_Op SMPI_Op; diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 1f19913b04..4bd628459b 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -214,10 +214,7 @@ typedef ptrdiff_t MPI_Aint; typedef long long MPI_Offset; typedef long long MPI_Count; -struct s_MPI_File; -typedef struct s_MPI_File *MPI_File; - - +typedef SMPI_File *MPI_File; typedef SMPI_Datatype *MPI_Datatype; typedef struct { diff --git a/src/smpi/bindings/smpi_mpi.cpp b/src/smpi/bindings/smpi_mpi.cpp index 3a354e0fc8..0305b3958e 100644 --- a/src/smpi/bindings/smpi_mpi.cpp +++ b/src/smpi/bindings/smpi_mpi.cpp @@ -346,9 +346,9 @@ UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_call_errhandler,(MPI_File fh, int UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_create_errhandler,(MPI_File_errhandler_function *function, MPI_Errhandler *errhandler),(function, errhandler)) UNIMPLEMENTED_WRAPPED_PMPI_CALL_NOFAIL(int, MPI_File_set_errhandler,( MPI_File file, MPI_Errhandler errhandler), (file, errhandler)) UNIMPLEMENTED_WRAPPED_PMPI_CALL_NOFAIL(int, MPI_File_get_errhandler,( MPI_File file, MPI_Errhandler *errhandler), (file, errhandler)) -UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_open,(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh),(comm, filename, amode, info, fh)) -UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_close,(MPI_File *fh), (fh)) -UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_delete,(char *filename, MPI_Info info), (filename, info)) +WRAPPED_PMPI_CALL(int, MPI_File_open,(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh),(comm, filename, amode, info, fh)) +WRAPPED_PMPI_CALL(int, MPI_File_close,(MPI_File *fh), (fh)) +WRAPPED_PMPI_CALL(int, MPI_File_delete,(char *filename, MPI_Info info), (filename, info)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_set_size,(MPI_File fh, MPI_Offset size), (fh, size)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_preallocate,(MPI_File fh, MPI_Offset size), (fh, size)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_File_get_size,(MPI_File fh, MPI_Offset *size), (fh, size)) diff --git a/src/smpi/bindings/smpi_pmpi_file.cpp b/src/smpi/bindings/smpi_pmpi_file.cpp new file mode 100644 index 0000000000..8af99f1d3b --- /dev/null +++ b/src/smpi/bindings/smpi_pmpi_file.cpp @@ -0,0 +1,51 @@ +/* Copyright (c) 2007-2019. 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. */ + +#include "private.hpp" +#include "smpi_file.hpp" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); + +int PMPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh){ + if (comm == MPI_COMM_NULL) { + return MPI_ERR_COMM; + } else if (filename == nullptr) { + return MPI_ERR_FILE; + } else if (amode < 0) { + return MPI_ERR_AMODE; + } else { + smpi_bench_end(); + *fh = new simgrid::smpi::File(comm, filename, amode, info); + smpi_bench_begin(); + if((*fh)->size()==0 && not amode & MPI_MODE_CREATE){ + delete fh; + return MPI_ERR_AMODE; + } + return MPI_SUCCESS; + } +} + +int PMPI_File_close(MPI_File *fh){ + if (fh==nullptr){ + return MPI_ERR_ARG; + } else { + smpi_bench_end(); + int ret = simgrid::smpi::File::close(fh); + *fh = MPI_FILE_NULL; + smpi_bench_begin(); + return ret; + } +} + +int PMPI_File_delete(char *filename, MPI_Info info){ + if (filename == nullptr) { + return MPI_ERR_FILE; + } else { + smpi_bench_end(); + int ret = simgrid::smpi::File::del(filename, info); + smpi_bench_begin(); + return ret; + } +} \ No newline at end of file diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp new file mode 100644 index 0000000000..923674705f --- /dev/null +++ b/src/smpi/include/smpi_file.hpp @@ -0,0 +1,30 @@ +/* Copyright (c) 2010-2019. 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. */ + +#ifndef SMPI_FILE_HPP_INCLUDED +#define SMPI_FILE_HPP_INCLUDED +#include "simgrid/plugins/file_system.h" + + +namespace simgrid{ +namespace smpi{ +class File{ + MPI_Comm comm_; + int flags_; + simgrid::s4u::File* file_; + MPI_Info info_; + public: + File(MPI_Comm comm, char *filename, int amode, MPI_Info info); + ~File(); + int size(); + int flags(); + int sync(); + static int close(MPI_File *fh); + static int del(char *filename, MPI_Info info); +}; +} +} +#endif \ No newline at end of file diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp new file mode 100644 index 0000000000..4cfbe05a87 --- /dev/null +++ b/src/smpi/mpi/smpi_file.cpp @@ -0,0 +1,53 @@ +/* Copyright (c) 2007-2019. 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. */ +#include "private.hpp" + +#include "smpi_comm.hpp" +#include "smpi_coll.hpp" +#include "smpi_info.hpp" +#include "smpi_file.hpp" +#include "simgrid/plugins/file_system.h" + + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_io, smpi, "Logging specific to SMPI (RMA operations)"); + + +namespace simgrid{ +namespace smpi{ + File::File(MPI_Comm comm, char *filename, int amode, MPI_Info info): comm_(comm), flags_(amode), info_(info){ + file_= new simgrid::s4u::File(filename, nullptr); + } + + File::~File(){ + delete file_; + } + + int File::close(MPI_File *fh){ + (*fh)->sync(); + if((*fh)->flags() & MPI_MODE_DELETE_ON_CLOSE) + (*fh)->file_->unlink(); + delete fh; + return MPI_SUCCESS; + } + + int File::del(char *filename, MPI_Info info){ + File* f = new File(MPI_COMM_SELF,filename,MPI_MODE_DELETE_ON_CLOSE|MPI_MODE_RDWR, nullptr); + close(&f); + return MPI_SUCCESS; + } + + int File::size(){ + return file_->size(); + } + + int File::flags(){ + return flags_; + } + int File::sync(){ + //no idea + return simgrid::smpi::Colls::barrier(comm_); + } +} +} \ No newline at end of file diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 3e7a0a114b..b856d198b7 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -92,6 +92,7 @@ set(SMPI_SRC src/smpi/bindings/smpi_pmpi.cpp src/smpi/bindings/smpi_pmpi_coll.cpp src/smpi/bindings/smpi_pmpi_comm.cpp + src/smpi/bindings/smpi_pmpi_file.cpp src/smpi/bindings/smpi_pmpi_group.cpp src/smpi/bindings/smpi_pmpi_info.cpp src/smpi/bindings/smpi_pmpi_op.cpp @@ -226,6 +227,7 @@ set(SMPI_SRC src/smpi/mpi/smpi_datatype.cpp src/smpi/mpi/smpi_datatype_derived.cpp src/smpi/mpi/smpi_f2c.cpp + src/smpi/mpi/smpi_file.cpp src/smpi/mpi/smpi_group.cpp src/smpi/mpi/smpi_info.cpp src/smpi/mpi/smpi_keyvals.cpp @@ -240,6 +242,7 @@ set(SMPI_SRC src/smpi/include/smpi_datatype_derived.hpp src/smpi/include/smpi_datatype.hpp src/smpi/include/smpi_f2c.hpp + src/smpi/include/smpi_file.hpp src/smpi/include/smpi_group.hpp src/smpi/include/smpi_host.hpp src/smpi/include/smpi_info.hpp -- 2.20.1