24namespace shamalgs::collective {
39 auto dtype = get_mpi_type<T>();
42 shamcomm::mpi::Type_size(dtype, &sz);
46 u64 disp = file_head_ptr + view.head_offset;
48 shamcomm::mpi::File_set_view(fh, disp, dtype, dtype,
"native", MPI_INFO_NULL);
50 shamcomm::mpi::File_write_all(fh, ptr_data, data_cnt, dtype, MPI_STATUS_IGNORE);
52 file_head_ptr = view.total_byte_count + file_head_ptr;
69 MPI_File fh, T *ptr_data,
u64 data_cnt,
u64 total_cnt,
u64 &file_head_ptr) {
70 auto dtype = get_mpi_type<T>();
73 shamcomm::mpi::Type_size(dtype, &sz);
75 ViewInfo view = fetch_view_known_total(
u64(sz) * data_cnt,
u64(sz) * total_cnt);
77 u64 disp = file_head_ptr + view.head_offset;
79 shamcomm::mpi::File_set_view(fh, disp, dtype, dtype,
"native", MPI_INFO_NULL);
81 shamcomm::mpi::File_write_all(fh, ptr_data, data_cnt, dtype, MPI_STATUS_IGNORE);
83 file_head_ptr = view.total_byte_count + file_head_ptr;
97 shamcomm::mpi::File_set_view(
98 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
101 shamcomm::mpi::File_write(fh, s.c_str(), s.size(), MPI_CHAR, MPI_STATUS_IGNORE);
104 file_head_ptr = file_head_ptr + s.size();
117 shamcomm::mpi::File_set_view(
118 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
122 shamcomm::mpi::File_read(fh, s.data(), s.size(), MPI_CHAR, MPI_STATUS_IGNORE);
124 file_head_ptr = file_head_ptr + s.size();
138 shamcomm::mpi::File_set_view(
139 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
142 shamcomm::mpi::File_write(fh, &val, 1, get_mpi_type<size_t>(), MPI_STATUS_IGNORE);
145 file_head_ptr = file_head_ptr +
sizeof(size_t);
157 inline void write_at(MPI_File fh,
const void *buf,
size_t len,
u64 file_head_ptr) {
159 shamcomm::mpi::File_write_at(
160 fh, file_head_ptr, buf, len, get_mpi_type<T>(), MPI_STATUS_IGNORE);
172 inline void read_at(MPI_File fh,
void *buf,
size_t len,
u64 file_head_ptr) {
174 shamcomm::mpi::File_read_at(
175 fh, file_head_ptr, buf, len, get_mpi_type<T>(), MPI_STATUS_IGNORE);
188 shamcomm::mpi::File_set_view(
189 fh, file_head_ptr, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL);
191 shamcomm::mpi::File_read(fh, &val, 1, get_mpi_type<size_t>(), MPI_STATUS_IGNORE);
193 file_head_ptr = file_head_ptr +
sizeof(size_t);
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.
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 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 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.