8 #include "../types.hpp"
19 typedef std::vector<int> Shape;
27 mpi::io::offset offset = 0):
28 f_(f), offset_(offset) { set_shape(shape); }
30 void set_offset(mpi::io::offset offset) { offset_ = offset; }
33 void set_shape(
const S& shape)
37 for (
unsigned i = 0; i < shape.size(); ++i)
39 shape_.push_back(shape[i]);
42 for (
int i = shape_.size() - 2; i >= 0; --i)
43 stride_[i] = stride_[i+1] * shape_[i+1];
46 const Shape& shape()
const {
return shape_; }
49 void read(
const DiscreteBounds& bounds, T* buffer,
bool collective =
false,
int chunk = 1)
const;
52 void write(
const DiscreteBounds& bounds,
const T* buffer,
bool collective =
false,
int chunk = 1);
63 std::vector<size_t> stride_;
72 read(
const DiscreteBounds& bounds, T* buffer,
bool collective,
int chunk)
const
75 int dim = shape_.size();
77 std::vector<int> subsizes;
78 for (
int i = 0; i < dim; ++i)
80 subsizes.push_back(bounds.max[i] - bounds.min[i] + 1);
81 total *= subsizes.back();
86 T_type = mpi::detail::get_mpi_datatype<T>();
92 int array_of_blocklengths[] = { chunk };
93 MPI_Aint array_of_displacements[] = { 0 };
94 MPI_Datatype array_of_types[] = { mpi::detail::get_mpi_datatype<T>() };
95 MPI_Type_create_struct(1, array_of_blocklengths, array_of_displacements, array_of_types, &T_type);
96 MPI_Type_commit(&T_type);
100 MPI_Type_create_subarray(dim, (
int*) &shape_[0], &subsizes[0], (
int*) &bounds.min[0], MPI_ORDER_C, T_type, &fileblk);
101 MPI_Type_commit(&fileblk);
103 MPI_File_set_view(f_.handle(), offset_, T_type, fileblk, (
char*)
"native", MPI_INFO_NULL);
107 MPI_File_read(f_.handle(), buffer, total, T_type, &s.s);
109 MPI_File_read_all(f_.handle(), buffer, total, T_type, &s.s);
112 MPI_Type_free(&T_type);
113 MPI_Type_free(&fileblk);
115 (void) bounds; (void) buffer; (void) collective; (void)chunk;
116 DIY_UNSUPPORTED_MPI_CALL(diy::io::BOV::read);
123 write(
const DiscreteBounds& bounds,
const T* buffer,
bool collective,
int chunk)
125 write(bounds, buffer, bounds, collective, chunk);
131 write(
const DiscreteBounds& bounds,
const T* buffer,
const DiscreteBounds& core,
bool collective,
int chunk)
134 int dim = shape_.size();
135 std::vector<int> subsizes;
136 std::vector<int> buffer_shape, buffer_start;
137 for (
int i = 0; i < dim; ++i)
139 buffer_shape.push_back(bounds.max[i] - bounds.min[i] + 1);
140 buffer_start.push_back(core.min[i] - bounds.min[i]);
141 subsizes.push_back(core.max[i] - core.min[i] + 1);
146 T_type = mpi::detail::get_mpi_datatype<T>();
150 int array_of_blocklengths[] = { chunk };
151 MPI_Aint array_of_displacements[] = { 0 };
152 MPI_Datatype array_of_types[] = { mpi::detail::get_mpi_datatype<T>() };
153 MPI_Type_create_struct(1, array_of_blocklengths, array_of_displacements, array_of_types, &T_type);
154 MPI_Type_commit(&T_type);
157 MPI_Datatype fileblk, subbuffer;
158 MPI_Type_create_subarray(dim, (
int*) &shape_[0], &subsizes[0], (
int*) &bounds.min[0], MPI_ORDER_C, T_type, &fileblk);
159 MPI_Type_create_subarray(dim, (
int*) &buffer_shape[0], &subsizes[0], (
int*) &buffer_start[0], MPI_ORDER_C, T_type, &subbuffer);
160 MPI_Type_commit(&fileblk);
161 MPI_Type_commit(&subbuffer);
163 MPI_File_set_view(f_.handle(), offset_, T_type, fileblk, (
char*)
"native", MPI_INFO_NULL);
167 MPI_File_write(f_.handle(), (
void*)buffer, 1, subbuffer, &s.s);
169 MPI_File_write_all(f_.handle(), (
void*)buffer, 1, subbuffer, &s.s);
172 MPI_Type_free(&T_type);
173 MPI_Type_free(&fileblk);
174 MPI_Type_free(&subbuffer);
176 (void) bounds; (void) buffer;(void) core; (void) collective; (void) chunk;
177 DIY_UNSUPPORTED_MPI_CALL(diy::io::bov::write);
Wraps MPI file IO.
Definition: io.hpp:18