13 typedef MPI_Offset offset;
21 rdonly = MPI_MODE_RDONLY,
23 wronly = MPI_MODE_WRONLY,
24 create = MPI_MODE_CREATE,
25 exclusive = MPI_MODE_EXCL,
26 delete_on_close = MPI_MODE_DELETE_ON_CLOSE,
27 unique_open = MPI_MODE_UNIQUE_OPEN,
28 sequential = MPI_MODE_SEQUENTIAL,
29 append = MPI_MODE_APPEND
34 const std::string& filename,
36 comm_(comm) { MPI_File_open(comm, const_cast<char*>(filename.c_str()), mode, MPI_INFO_NULL, &fh); }
38 void close() {
if (fh != MPI_FILE_NULL) MPI_File_close(&fh); }
40 offset size()
const { offset sz; MPI_File_get_size(fh, &sz);
return sz; }
41 void resize(offset size) { MPI_File_set_size(fh, size); }
43 inline void read_at(offset o,
char* buffer,
size_t size);
44 inline void read_at_all(offset o,
char* buffer,
size_t size);
45 inline void write_at(offset o,
const char* buffer,
size_t size);
46 inline void write_at_all(offset o,
const char* buffer,
size_t size);
49 inline void read_at(offset o, std::vector<T>& data);
52 inline void read_at_all(offset o, std::vector<T>& data);
55 inline void write_at(offset o,
const std::vector<T>& data);
58 inline void write_at_all(offset o,
const std::vector<T>& data);
61 comm()
const {
return comm_; }
63 MPI_File& handle() {
return fh; }
75 read_at(offset o,
char* buffer,
size_t size)
78 MPI_File_read_at(fh, o, buffer, size, detail::get_mpi_datatype<char>(), &s.s);
84 read_at(offset o, std::vector<T>& data)
86 read_at(o, &data[0], data.size()*
sizeof(T));
91 read_at_all(offset o,
char* buffer,
size_t size)
94 MPI_File_read_at_all(fh, o, buffer, size, detail::get_mpi_datatype<char>(), &s.s);
100 read_at_all(offset o, std::vector<T>& data)
102 read_at_all(o, (
char*) &data[0], data.size()*
sizeof(T));
107 write_at(offset o,
const char* buffer,
size_t size)
110 MPI_File_write_at(fh, o, (
void *)buffer, size, detail::get_mpi_datatype<char>(), &s.s);
116 write_at(offset o,
const std::vector<T>& data)
118 write_at(o, (
const char*) &data[0], data.size()*
sizeof(T));
123 write_at_all(offset o,
const char* buffer,
size_t size)
126 MPI_File_write_at_all(fh, o, (
void *)buffer, size, detail::get_mpi_datatype<char>(), &s.s);
132 write_at_all(offset o,
const std::vector<T>& data)
134 write_at_all(o, &data[0], data.size()*
sizeof(T));
Wraps MPI file IO.
Definition: io.hpp:16
Simple wrapper around MPI_Comm.
Definition: communicator.hpp:8