1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
\r
3 /* This program is free software; you can redistribute it and/or modify it
\r
4 * under the terms of the license (GNU LGPL) which comes with this package. */
\r
5 #include "private.hpp"
\r
7 #include "smpi_comm.hpp"
\r
8 #include "smpi_coll.hpp"
\r
9 #include "smpi_datatype.hpp"
\r
10 #include "smpi_info.hpp"
\r
11 #include "smpi_file.hpp"
\r
12 #include "simgrid/plugins/file_system.h"
\r
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_io, smpi, "Logging specific to SMPI (RMA operations)");
\r
20 File::File(MPI_Comm comm, char *filename, int amode, MPI_Info info): comm_(comm), flags_(amode), info_(info){
\r
21 file_= new simgrid::s4u::File(filename, nullptr);
\r
28 int File::close(MPI_File *fh){
\r
29 XBT_DEBUG("Closing MPI_File %s", (*fh)->file_->get_path());
\r
31 if((*fh)->flags() & MPI_MODE_DELETE_ON_CLOSE)
\r
32 (*fh)->file_->unlink();
\r
37 int File::del(char *filename, MPI_Info info){
\r
38 //get the file with MPI_MODE_DELETE_ON_CLOSE and then close it
\r
39 File* f = new File(MPI_COMM_SELF,filename,MPI_MODE_DELETE_ON_CLOSE|MPI_MODE_RDWR, nullptr);
\r
44 int File::seek(MPI_Offset offset, int whence){
\r
47 XBT_DEBUG("Seeking in MPI_File %s, setting offset %lld", file_->get_path(), offset);
\r
48 file_->seek(offset,SEEK_SET);
\r
51 XBT_DEBUG("Seeking in MPI_File %s, current offset + %lld", file_->get_path(), offset);
\r
52 file_->seek(offset,SEEK_CUR);
\r
55 XBT_DEBUG("Seeking in MPI_File %s, end offset + %lld", file_->get_path(), offset);
\r
56 file_->seek(offset,SEEK_END);
\r
59 return MPI_ERR_FILE;
\r
64 int File::read(void *buf, int count, MPI_Datatype datatype, MPI_Status *status){
\r
65 //get position first as we may be doing non contiguous reads and it will probably be updated badly
\r
66 MPI_Offset position = file_->tell();
\r
67 MPI_Offset movesize = datatype->get_extent()*count;
\r
68 MPI_Offset readsize = datatype->size()*count;
\r
69 XBT_DEBUG("Position before read in MPI_File %s : %llu",file_->get_path(),file_->tell());
\r
70 MPI_Offset read = file_->read(readsize);
\r
71 XBT_DEBUG("Read in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", file_->get_path(), read, readsize, movesize);
\r
72 if(readsize!=movesize){
\r
73 file_->seek(position+movesize, SEEK_SET);
\r
75 XBT_DEBUG("Position after read in MPI_File %s : %llu",file_->get_path(), file_->tell());
\r
80 return file_->size();
\r
89 return simgrid::smpi::Colls::barrier(comm_);
\r