26 const int nin_field = v->
nin();
27 const int nex_field = v->
nex();
32 if ((nin_file == 0) || (nex_file == 0)) {
38 const long_t size = nin_file * Lvol * nex_file;
45 vtmp.
reset(nin_field, Lvol, nex_field);
48 infile.open(filename.c_str(), std::ios::in | std::ios::binary);
54 bool do_byteswap =
false;
62 infile.read((
char *)&flen,
sizeof(uint32_t) * 1);
69 if (flen ==
sizeof(
double) * size) {
73 uint32_t flen_s = flen;
76 if (flen_s ==
sizeof(
double) * size) {
87 const int block_size = nin_file;
88 char buf[
sizeof(double) * block_size];
90 for (
int j = 0; j < nex_file; ++j) {
91 for (
long_t isite = 0; isite < Lvol; ++isite) {
93 infile.read(buf,
sizeof(
double) * block_size);
106 byte_swap(buf,
sizeof(
double), block_size);
109 double *ptr = (
double *)buf;
111 for (
int i = 0; i < nin_file; ++i) {
115 vtmp.
set(s, isite, t, ptr[i]);
122 infile.read((
char *)&ftail,
sizeof(uint32_t) * 1);
145 const int nin_field = v->
nin();
146 const int nex_field = v->
nex();
151 if ((nin_file == 0) || (nex_file == 0)) {
152 nin_file = nin_field;
153 nex_file = nex_field;
160 vtmp.
reset(nin_field, Lvol, nex_field);
163 const size_t count = nin_file * Lvol * nex_file;
170 std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary);
176 const uint32_t flen =
sizeof(double) * count;
179 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
182 vout.
crucial(
m_vl,
"Error at %s: io error. write record header failed.\n", __func__);
187 const int block_size = nin_file;
188 char buf[
sizeof(double) * block_size];
191 for (
int j = 0; j < nex_file; ++j) {
192 for (
long_t isite = 0; isite < Lvol; ++isite) {
193 double *ptr = (
double *)buf;
195 for (
int i = 0; i < nin_file; ++i) {
199 ptr[i] = vtmp.
cmp(s, isite, t);
202 outfile.write(buf,
sizeof(
double) * block_size);
212 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
215 vout.
crucial(
m_vl,
"Error at %s: write record footer failed.\n", __func__);
231 if ((vv.size() == 0) || (filename ==
""))
return;
233 const int nin_field = vv[0]->nin();
234 const int nex_field = vv[0]->nex();
239 if ((nin_file == 0) || (nex_file == 0)) {
240 nin_file = nin_field;
241 nex_file = nex_field;
245 const long_t size = nin_file * Lvol * nex_file;
252 vtmp.
reset(nin_field, Lvol, nex_field);
255 infile.open(filename.c_str(), std::ios::in | std::ios::binary);
261 bool do_byteswap =
false;
263 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
270 infile.read((
char *)&flen,
sizeof(uint32_t) * 1);
277 if (flen ==
sizeof(
double) * size) {
281 uint32_t flen_s = flen;
284 if (flen_s ==
sizeof(
double) * size) {
295 const int block_size = nin_file;
296 char buf[
sizeof(double) * block_size];
298 for (
int j = 0; j < nex_file; ++j) {
299 for (
long_t isite = 0; isite < Lvol; ++isite) {
301 infile.read(buf,
sizeof(
double) * block_size);
314 byte_swap(buf,
sizeof(
double), block_size);
317 double *ptr = (
double *)buf;
319 for (
int i = 0; i < nin_file; ++i) {
323 vtmp.
set(s, isite, t, ptr[i]);
330 infile.read((
char *)&ftail,
sizeof(uint32_t) * 1);
346 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
358 if ((vv.size() == 0) || (filename ==
""))
return;
360 const int nin_field = vv[0]->nin();
361 const int nex_field = vv[0]->nex();
366 if ((nin_file == 0) || (nex_file == 0)) {
367 nin_file = nin_field;
368 nex_file = nex_field;
372 const size_t count = nin_file * Lvol * nex_file;
377 vtmp.
reset(nin_field, Lvol, nex_field);
383 std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary);
389 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
392 const uint32_t flen =
sizeof(double) * count;
395 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
398 vout.
crucial(
m_vl,
"Error at %s: io error. write record header failed.\n", __func__);
403 const int block_size = nin_file;
404 char buf[
sizeof(double) * block_size];
406 for (
int j = 0; j < nex_file; ++j) {
407 for (
long_t isite = 0; isite < Lvol; ++isite) {
408 double *ptr = (
double *)buf;
410 for (
int i = 0; i < nin_file; ++i) {
414 ptr[i] = vtmp.
cmp(s, isite, t);
417 outfile.write(buf,
sizeof(
double) * block_size);
427 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
430 vout.
crucial(
m_vl,
"Error at %s: io error. write record footer failed.\n", __func__);
437 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
static void byte_swap(void *buf, size_t size, size_t nmemb)
< convert byte order. alternative interface.
void detailed(const char *format,...)
static void abort()
terminate communicator
void set(const int jin, const int site, const int jex, double v)
void deliver(Field *vlocal, Field *vglobal)
distribute data on primary node over parallel nodes.
Container of Field-type object.
double cmp(const int jin, const int site, const int jex) const
void read_file(Field *v, const std::string filename)
read data from file.
static const std::string class_name
void write_file(Field *v, const std::string filename)
write data to file.
const IO_Format::Format * m_format
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=Element_type::COMPLEX)
long long_t
definition of long for Bridge++
void crucial(const char *format,...)
static bool is_primary()
check if the present node is primary in small communicator.
void gather(Field *vglobal, Field *vlocal)
gather data on parallel nodes to primary node.
Bridge::VerboseLevel m_vl