24 m_is_initialized(false),
25 m_nvol(0), m_nin_file(0), m_nex_file(0)
29 FieldIO_Binary_Parallel::~FieldIO_Binary_Parallel()
38 static const char _function_name[] =
"FieldIO_Binary_Parallel::read_file";
46 double *buf =
new double [m_nin_file * m_nvol * m_nex_file];
48 vout.
crucial(
m_vl,
"Error at %s: allocate buffer failed.\n", _function_name);
52 ret = MPI_File_open(Communicator_impl::world(),
const_cast<char *
>(filename.c_str()), MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);
54 vout.
crucial(
m_vl,
"Error at %s: MPI_File_open failed.\n", _function_name);
58 ret = MPI_File_set_view(fh, 0, m_type_vector, m_type_tiled,
const_cast<char *
>(
"native"), MPI_INFO_NULL);
60 vout.
crucial(
m_vl,
"Error at %s: MPI_File_set_view failed.\n", _function_name);
64 ret = MPI_File_read_all(fh, (
void *)buf, m_nvol * m_nex_file, m_type_vector, MPI_STATUS_IGNORE);
66 vout.
crucial(
m_vl,
"Error at %s: MPI_File_read_all failed.\n", _function_name);
70 ret = MPI_File_close(&fh);
72 vout.
crucial(
m_vl,
"Error at %s: MPI_File_close failed.\n", _function_name);
77 convert_endian(buf,
sizeof(
double), m_nvol * m_nin_file * m_nex_file);
83 for (
int j = 0; j < m_nex_file; ++j) {
84 for (
int isite = 0; isite < m_nvol; ++isite) {
85 for (
int i = 0; i < m_nin_file; ++i) {
89 u.
set(s, isite, t, *p++);
103 static const char _function_name[] =
"FieldIO_Binary_Parallel::write_file";
107 double *buf =
new double [m_nin_file * m_nvol * m_nex_file];
109 vout.
crucial(
m_vl,
"Error at %s: allocate buffer failed.\n", _function_name);
116 for (
int j = 0; j < m_nex_file; ++j) {
117 for (
int isite = 0; isite < m_nvol; ++isite) {
118 for (
int i = 0; i < m_nin_file; ++i) {
122 *p++ = u.
cmp(s, isite, t);
128 convert_endian(buf,
sizeof(
double), m_nin_file * m_nvol * m_nex_file);
134 ret = MPI_File_open(Communicator_impl::world(),
const_cast<char *
>(filename.c_str()), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);
136 vout.
crucial(
m_vl,
"Error at %s: MPI_File_open failed.\n", _function_name);
140 ret = MPI_File_set_view(fh, 0, m_type_vector, m_type_tiled,
const_cast<char *
>(
"native"), MPI_INFO_NULL);
142 vout.
crucial(
m_vl,
"Error at %s: MPI_File_set_view failed.\n", _function_name);
146 ret = MPI_File_write_all(fh, (
void *)buf, m_nvol * m_nex_file, m_type_vector, MPI_STATUS_IGNORE);
148 vout.
crucial(
m_vl,
"Error at %s: MPI_File_write_all failed.\n", _function_name);
152 ret = MPI_File_close(&fh);
154 vout.
crucial(
m_vl,
"Error at %s: MPI_File_close failed.\n", _function_name);
165 int FieldIO_Binary_Parallel::initialize(
const Field& v)
167 static const char _function_name[] =
"FieldIO_Binary_Parallel::initialize";
172 const int nvol = v.
nvol();
175 if (m_is_initialized &&
176 (nin_file == m_nin_file) &&
177 (nex_file == m_nex_file) &&
188 m_nin_file = nin_file;
189 m_nex_file = nex_file;
193 int *global_dims =
new int[ndim];
199 int *local_dims =
new int[ndim];
206 for (
int i = 0; i < ndim; ++i) {
207 m_nvol *= local_dims[i];
210 int *grid_pos =
new int[ndim];
211 for (
int i = 0; i < ndim; ++i) {
215 int *starts =
new int[ndim];
216 for (
int i = 0; i < ndim; ++i) {
217 starts[i] = local_dims[i] * grid_pos[i];
223 ret = MPI_Type_contiguous(
sizeof(
double) * m_nin_file, MPI_BYTE, &m_type_vector);
225 vout.
crucial(
m_vl,
"%s: MPI_Type_Contiguous failed.\n", _function_name);
229 ret = MPI_Type_commit(&m_type_vector);
236 ret = MPI_Type_create_subarray(ndim, global_dims, local_dims, starts, MPI_ORDER_FORTRAN, m_type_vector, &m_type_tiled);
238 vout.
crucial(
m_vl,
"%s: MPI_Type_create_subarray failed.\n", _function_name);
242 ret = MPI_Type_commit(&m_type_tiled);
250 delete [] local_dims;
251 delete [] global_dims;
254 m_is_initialized =
true;
263 int FieldIO_Binary_Parallel::clear_layout()
265 const char _function_name[] =
"FieldIO_Binary_Parallel::clear_layout";
267 if (m_is_initialized) {
274 ret = MPI_Type_free(&m_type_vector);
276 vout.
crucial(
m_vl,
"%s: MPI_Type_free for type_vector failed.\n", _function_name);
280 ret = MPI_Type_free(&m_type_tiled);
282 vout.
crucial(
m_vl,
"%s: MPI_Type_free for type_tiled failed.\n", _function_name);
286 m_is_initialized =
false;
294 int FieldIO_Binary_Parallel::finalize()
296 static const char _function_name[] =
"FieldIO_Binary_Parallel::finalize";