25namespace shamalgs::collective {
40 auto dtype = get_mpi_type<T>();
47 u64 disp = file_head_ptr + view.head_offset;
53 file_head_ptr = view.total_byte_count + file_head_ptr;
70 MPI_File fh, T *ptr_data,
u64 data_cnt,
u64 total_cnt,
u64 &file_head_ptr) {
71 auto dtype = get_mpi_type<T>();
76 ViewInfo view = fetch_view_known_total(
u64(sz) * data_cnt,
u64(sz) * total_cnt);
78 u64 disp = file_head_ptr + view.head_offset;
84 file_head_ptr = view.total_byte_count + file_head_ptr;
99 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
105 file_head_ptr = file_head_ptr + s.size();
119 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
125 file_head_ptr = file_head_ptr + s.size();
140 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
146 file_head_ptr = file_head_ptr +
sizeof(size_t);
158 inline void write_at(MPI_File fh,
const void *buf,
size_t len,
u64 file_head_ptr) {
164 shambase::narrow_or_throw<int>(len),
183 size_t max_message = 1 << 30;
185 for (
size_t offset = 0; offset < len; offset += max_message) {
186 const u8 *buf_ptr = buf + offset;
187 size_t msg_len = std::min(max_message, len - offset);
188 write_at<u8>(fh, buf_ptr, msg_len, file_head_ptr + offset);
201 inline void read_at(MPI_File fh,
void *buf,
size_t len,
u64 file_head_ptr) {
207 shambase::narrow_or_throw<int>(len),
225 size_t max_message = 1 << 30;
227 for (
size_t offset = 0; offset < len; offset += max_message) {
228 u8 *buf_ptr = buf + offset;
229 size_t msg_len = std::min(max_message, len - offset);
230 read_at<u8>(fh, buf_ptr, msg_len, file_head_ptr + offset);
245 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
249 file_head_ptr = file_head_ptr +
sizeof(size_t);
std::uint8_t u8
8 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int32_t i32
32 bit integer
Utility functions for MPI error checking.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Utilities for safe type narrowing conversions.
std::string read_header(MPI_File fh, u64 &file_head_ptr)
Reads a string from a file using MPI and updates the file head pointer. The string is preceded by its...
void write_header_raw(MPI_File fh, std::string s, u64 &file_head_ptr)
Writes a string to a file using MPI and updates the file head pointer.
std::string read_header_raw(MPI_File fh, size_t len, u64 &file_head_ptr)
Reads a string of length len from a file using MPI and updates the file head pointer.
size_t read_header_val(MPI_File fh, u64 &file_head_ptr)
Reads a size_t from a file using MPI and updates the file head pointer.
void write_header(MPI_File fh, std::string s, u64 &file_head_ptr)
Writes a string to a file using MPI and updates the file head pointer. The string is preceded by its ...
void write_at(MPI_File fh, const void *buf, size_t len, u64 file_head_ptr)
Writes data at a given offset in a file using MPI.
void write_at_large(MPI_File fh, const u8 *buf, size_t len, u64 file_head_ptr)
Writes a large byte buffer at a given offset in a file using MPI.
void viewed_write_all_fetch(MPI_File fh, T *ptr_data, u64 data_cnt, u64 &file_head_ptr)
Writes data to an MPI file in a collective manner.
void read_at_large(MPI_File fh, u8 *buf, size_t len, u64 file_head_ptr)
Reads a large byte buffer at a given offset in a file using MPI.
void write_header_val(MPI_File fh, size_t val, u64 &file_head_ptr)
Writes a size_t to a file using MPI and updates the file head pointer.
void viewed_write_all_fetch_known_total_size(MPI_File fh, T *ptr_data, u64 data_cnt, u64 total_cnt, u64 &file_head_ptr)
Writes data to an MPI file in a collective manner and updates the file head pointer.
void read_at(MPI_File fh, void *buf, size_t len, u64 file_head_ptr)
Reads data at a given offset in a file using MPI.
void File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, const char *datarep, MPI_Info info)
MPI wrapper for MPI_File_set_view.
void File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_read.
void File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_write_at.
void Type_size(MPI_Datatype type, int *size)
MPI wrapper for MPI_Type_size.
void File_write(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_write.
void File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_read_at.
void File_write_all(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_write_all.