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
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_io, smpi, "Logging specific to SMPI (RMA operations)");
\r
19 File::File(MPI_Comm comm, char *filename, int amode, MPI_Info info): comm_(comm), flags_(amode), info_(info){
\r
20 file_= new simgrid::s4u::File(filename, nullptr);
\r
27 int File::close(MPI_File *fh){
\r
28 XBT_DEBUG("Closing MPI_File %s", (*fh)->file_->get_path());
\r
30 if((*fh)->flags() & MPI_MODE_DELETE_ON_CLOSE)
\r
31 (*fh)->file_->unlink();
\r
36 int File::del(char *filename, MPI_Info info){
\r
37 //get the file with MPI_MODE_DELETE_ON_CLOSE and then close it
\r
38 File* f = new File(MPI_COMM_SELF,filename,MPI_MODE_DELETE_ON_CLOSE|MPI_MODE_RDWR, nullptr);
\r
43 int File::seek(MPI_Offset offset, int whence){
\r
46 XBT_DEBUG("Seeking in MPI_File %s, setting offset %lld", file_->get_path(), offset);
\r
47 file_->seek(offset,SEEK_SET);
\r
50 XBT_DEBUG("Seeking in MPI_File %s, current offset + %lld", file_->get_path(), offset);
\r
51 file_->seek(offset,SEEK_CUR);
\r
54 XBT_DEBUG("Seeking in MPI_File %s, end offset + %lld", file_->get_path(), offset);
\r
55 file_->seek(offset,SEEK_END);
\r
58 return MPI_ERR_FILE;
\r
63 int File::read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status){
\r
64 //get position first as we may be doing non contiguous reads and it will probably be updated badly
\r
65 MPI_Offset position = fh->file_->tell();
\r
66 MPI_Offset movesize = datatype->get_extent()*count;
\r
67 MPI_Offset readsize = datatype->size()*count;
\r
68 XBT_DEBUG("Position before read in MPI_File %s : %llu",fh->file_->get_path(),fh->file_->tell());
\r
69 MPI_Offset read = fh->file_->read(readsize);
\r
70 XBT_DEBUG("Read in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", fh->file_->get_path(), read, readsize, movesize);
\r
71 if(readsize!=movesize){
\r
72 fh->file_->seek(position+movesize, SEEK_SET);
\r
74 XBT_DEBUG("Position after read in MPI_File %s : %llu",fh->file_->get_path(), fh->file_->tell());
\r
79 int File::write(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status){
\r
80 //get position first as we may be doing non contiguous reads and it will probably be updated badly
\r
81 MPI_Offset position = fh->file_->tell();
\r
82 MPI_Offset movesize = datatype->get_extent()*count;
\r
83 MPI_Offset writesize = datatype->size()*count;
\r
84 XBT_DEBUG("Position before write in MPI_File %s : %llu",fh->file_->get_path(),fh->file_->tell());
\r
85 MPI_Offset write = fh->file_->write(writesize);
\r
86 XBT_DEBUG("Write in MPI_File %s, %lld bytes read, readsize %lld bytes, movesize %lld", fh->file_->get_path(), write, writesize, movesize);
\r
87 if(writesize!=movesize){
\r
88 fh->file_->seek(position+movesize, SEEK_SET);
\r
90 XBT_DEBUG("Position after write in MPI_File %s : %llu",fh->file_->get_path(), fh->file_->tell());
\r
95 return file_->size();
\r
104 return simgrid::smpi::Colls::barrier(comm_);
\r