10 static QIO_Layout layout;
11 static int lattice_size[4];
14 std::ostream &
operator<<(std::ostream &out,
const QIO_Layout &layout)
16 out <<
"node_number = " << layout.node_number << std::endl;
17 out <<
"node_index = " << layout.node_index << std::endl;
18 out <<
"get_coords = " << layout.get_coords << std::endl;
19 out <<
"num_sites = " << layout.num_sites << std::endl;
20 out <<
"latdim = " << layout.latdim << std::endl;
22 for (
int d = 0; d < layout.latdim; d++) out << layout.latsize[d] << (d < layout.latdim - 1 ?
", " :
"}");
24 out <<
"volume = " << layout.volume << std::endl;
25 out <<
"sites_on_node = " << layout.sites_on_node << std::endl;
26 out <<
"this_node = " << layout.this_node << std::endl;
27 out <<
"number_of_nodes = " << layout.number_of_nodes << std::endl;
34 template <
typename oFloat,
typename iFloat,
int len>
void vput(
char *s1,
size_t index,
int count,
void *s2)
36 oFloat **field = (oFloat **)s2;
37 iFloat *src = (iFloat *)s1;
42 for (
int i = 0; i < count; i++) {
43 oFloat *dest = field[i] + len * index;
44 for (
int j = 0; j < len; j++) dest[j] = src[i * len + j];
50 template <
typename oFloat,
typename iFloat,
int len>
void vget(
char *s1,
size_t index,
int count,
void *s2)
52 iFloat **field = (iFloat **)s2;
53 oFloat *dest = (oFloat *)s1;
57 for (
int i = 0; i < count; i++, dest += len) {
58 iFloat *src = field[i] + len * index;
59 for (
int j = 0; j < len; j++) dest[j] = src[j];
67 iflag.serpar = serpar;
68 iflag.volfmt = volfmt;
71 QIO_String *xml_file_in = QIO_string_create();
74 QIO_Reader *infile = QIO_open_read(xml_file_in, filename, &layout, NULL, &iflag);
78 QIO_string_destroy(xml_file_in);
82 printfQuda(
"%s: QIO_open_read done.\n",__func__);
83 printfQuda(
"%s: User file info is \"%s\"\n", __func__, QIO_string_ptr(xml_file_in));
85 QIO_string_destroy(xml_file_in);
89 QIO_Writer *
open_test_output(
const char *filename,
int volfmt,
int serpar,
int ildgstyle)
91 char xml_write_file[] =
"Dummy user file XML";
92 QIO_Filesystem filesys;
95 oflag.serpar = serpar;
96 oflag.ildgstyle = ildgstyle;
97 oflag.ildgLFN = QIO_string_create();
98 QIO_string_set(oflag.ildgLFN,
"monkey");
99 oflag.mode = QIO_TRUNC;
101 filesys.my_io_node = 0;
102 filesys.master_io_node = 0;
105 QIO_String *xml_file_out = QIO_string_create();
106 QIO_string_set(xml_file_out,xml_write_file);
109 QIO_Writer *outfile = QIO_open_write(xml_file_out, filename, volfmt, &layout, &filesys, &oflag);
111 QIO_string_destroy(oflag.ildgLFN);
112 if (outfile == NULL) {
114 QIO_string_destroy(xml_file_out);
118 printfQuda(
"%s: QIO_open_write done.\n",__func__);
119 printfQuda(
"%s: User file info is \"%s\"\n", __func__, QIO_string_ptr(xml_file_out));
121 QIO_string_destroy(xml_file_out);
130 char dummy[100] =
"";
131 QIO_RecordInfo *rec_info = QIO_create_record_info(0, NULL, NULL, 0, dummy, dummy, 0, 0, 0, 0);
132 QIO_String *xml_record_in = QIO_string_create();
134 int status = QIO_read_record_info(infile, rec_info, xml_record_in);
135 int prec = *QIO_get_precision(rec_info);
138 printfQuda(
"%s: QIO_read_record_data returns status %d\n", __func__, status);
139 if (status != QIO_SUCCESS) {
errorQuda(
"get_prec failed\n"); }
142 int in_nSpin = QIO_get_spins(rec_info);
143 int in_nColor = QIO_get_colors(rec_info);
144 int in_count = QIO_get_datacount(rec_info);
145 int in_typesize = QIO_get_typesize(rec_info);
154 if (in_nSpin != nSpin)
warningQuda(
"QIO_get_spins %d does not match expected number of colors %d", in_nSpin, nSpin);
157 warningQuda(
"QIO_get_colors %d does not match expected number of spins %d", in_nColor,
nColor);
160 if (in_count != count)
errorQuda(
"QIO_get_datacount %d does not match expected number of fields %d", in_count, count);
162 if (in_typesize != file_prec * len)
163 errorQuda(
"QIO_get_typesize %d does not match expected datasize %d", in_typesize, file_prec * len);
168 if (len != 18 && QIO_string_length(xml_record_in) > 0)
printfQuda(
"QIO string: %s\n", QIO_string_ptr(xml_record_in));
171 size_t rec_size = file_prec * count * len;
176 status = QIO_read(infile, rec_info, xml_record_in, vput<double, double, len>, rec_size,
QUDA_DOUBLE_PRECISION,
180 = QIO_read(infile, rec_info, xml_record_in, vput<double, float, len>, rec_size,
QUDA_SINGLE_PRECISION, field_in);
185 = QIO_read(infile, rec_info, xml_record_in, vput<float, double, len>, rec_size,
QUDA_DOUBLE_PRECISION, field_in);
188 = QIO_read(infile, rec_info, xml_record_in, vput<float, float, len>, rec_size,
QUDA_SINGLE_PRECISION, field_in);
192 QIO_string_destroy(xml_record_in);
193 QIO_destroy_record_info(rec_info);
194 printfQuda(
"%s: QIO_read_record_data returns status %d\n", __func__, status);
195 if (status != QIO_SUCCESS)
return 1;
207 size_t lattice_dim = 4;
208 size_t lattice_volume = 1;
209 for (
int d=0; d<4; d++) {
211 lattice_volume *= (size_t)lattice_size[d];
218 printfQuda(
"%s layout set for %d nodes\n", __func__, QMP_get_number_of_nodes());
221 #ifdef QIO_HAS_EXTENDED_LAYOUT
223 layout.node_number = NULL;
224 layout.node_index = NULL;
225 layout.get_coords = NULL;
226 layout.num_sites = NULL;
228 layout.node_number_ext = quda_node_number_ext;
229 layout.node_index_ext = quda_node_index_ext;
230 layout.get_coords_ext = quda_get_coords_ext;
231 layout.num_sites_ext = quda_num_sites_ext;
233 layout.sites_on_node = quda_num_sites_ext(
quda_this_node,
nullptr);
242 layout.latsize = lattice_size;
243 layout.latdim = lattice_dim;
244 layout.volume = lattice_volume;
246 layout.number_of_nodes = QMP_get_number_of_nodes();
256 QIO_Reader *infile =
open_test_input(filename, QIO_UNKNOWN, QIO_PARALLEL);
257 if (infile == NULL) {
errorQuda(
"Open file failed\n"); }
260 printfQuda(
"%s: reading su3 field\n",__func__); fflush(stdout);
262 if (status) {
errorQuda(
"read_su3_field failed %d\n", status); }
265 QIO_close_read(infile);
266 printfQuda(
"%s: Closed file for reading\n",__func__);
276 case 6: status = read_field<6>(infile, count, field_in,
cpu_prec, subset,
parity, nSpin,
nColor);
break;
277 case 24: status = read_field<24>(infile, count, field_in,
cpu_prec, subset,
parity, nSpin,
nColor);
break;
278 case 96: status = read_field<96>(infile, count, field_in,
cpu_prec, subset,
parity, nSpin,
nColor);
break;
279 case 128: status = read_field<128>(infile, count, field_in,
cpu_prec, subset,
parity, nSpin,
nColor);
break;
280 case 256: status = read_field<256>(infile, count, field_in,
cpu_prec, subset,
parity, nSpin,
nColor);
break;
281 case 384: status = read_field<384>(infile, count, field_in,
cpu_prec, subset,
parity, nSpin,
nColor);
break;
296 QIO_Reader *infile =
open_test_input(filename, QIO_UNKNOWN, QIO_PARALLEL);
297 if (infile == NULL) {
errorQuda(
"Open file failed\n"); }
300 printfQuda(
"%s: reading %d vector fields\n", __func__, Nvec); fflush(stdout);
302 if (status) {
errorQuda(
"read_spinor_fields failed %d\n", status); }
305 QIO_close_read(infile);
306 printfQuda(
"%s: Closed file for reading\n",__func__);
314 std::string xml_record =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><quda";
316 case 6: xml_record +=
"StaggeredColorSpinorField>";
break;
317 case 18: xml_record +=
"GaugeFieldFile>";
break;
318 case 24: xml_record +=
"WilsonColorSpinorField>";
break;
322 case 384: xml_record +=
"MGColorSpinorField>";
break;
323 default:
errorQuda(
"Invalid element length for QIO writing.");
break;
325 xml_record +=
"<version>BETA</version>";
326 xml_record +=
"<type>" +
std::string(type) +
"</type><info>";
335 xml_record +=
"<subset>parity</subset>";
337 xml_record +=
"<subset>full</subset>";
340 xml_record +=
"<parity>even</parity>";
342 xml_record +=
"<parity>odd</parity>";
344 xml_record +=
"<parity>full</parity>";
348 xml_record +=
"<nColor>" + std::to_string(
nColor) +
"</nColor>";
349 xml_record +=
"<nSpin>" + std::to_string(nSpin) +
"</nSpin>";
350 xml_record +=
"</info></quda";
352 case 6: xml_record +=
"StaggeredColorSpinorField>";
break;
353 case 18: xml_record +=
"GaugeFieldFile>";
break;
354 case 24: xml_record +=
"WilsonColorSpinorField>";
break;
358 case 384: xml_record +=
"MGColorSpinorField>";
break;
359 default:
errorQuda(
"Invalid element length for QIO writing.");
break;
366 errorQuda(
"Error, file_prec=%d not supported", file_prec);
372 int lower[nDim] = {0, 0, 0, 0};
373 int upper[nDim] = {lattice_size[0], lattice_size[1], lattice_size[2], lattice_size[3]};
375 QIO_RecordInfo *rec_info = QIO_create_record_info(QIO_FIELD, lower, upper, nDim,
const_cast<char *
>(type),
376 const_cast<char *
>(precision),
nColor, nSpin, file_prec * len, count);
379 QIO_String *xml_record_out = QIO_string_create();
380 QIO_string_set(xml_record_out, xml_record.c_str());
383 size_t rec_size = file_prec*count*len;
386 status = QIO_write(outfile, rec_info, xml_record_out, vget<double, double, len>, rec_size,
QUDA_DOUBLE_PRECISION,
389 status = QIO_write(outfile, rec_info, xml_record_out, vget<double, float, len>, rec_size,
QUDA_SINGLE_PRECISION,
394 status = QIO_write(outfile, rec_info, xml_record_out, vget<float, double, len>, rec_size,
QUDA_DOUBLE_PRECISION,
397 status = QIO_write(outfile, rec_info, xml_record_out, vget<float, float, len>, rec_size,
QUDA_SINGLE_PRECISION,
402 printfQuda(
"%s: QIO_write_record_data returns status %d\n", __func__, status);
403 QIO_destroy_record_info(rec_info);
404 QIO_string_destroy(xml_record_out);
406 if (status != QIO_SUCCESS)
return 1;
429 QIO_Writer *outfile =
open_test_output(filename, QIO_SINGLEFILE, QIO_PARALLEL, QIO_ILDGNO);
430 if (outfile == NULL) {
errorQuda(
"Open file failed\n"); }
433 printfQuda(
"%s: writing the gauge field\n", __func__); fflush(stdout);
434 int status =
write_su3_field(outfile, 4, gauge, precision, precision, type);
435 if (status) {
errorQuda(
"write_gauge_field failed %d\n", status); }
438 QIO_close_write(outfile);
439 printfQuda(
"%s: Closed file for writing\n", __func__);
450 status = write_field<6>(outfile, count, field_out, file_prec,
cpu_prec, subset,
parity, nSpin,
nColor, type);
453 status = write_field<24>(outfile, count, field_out, file_prec,
cpu_prec, subset,
parity, nSpin,
nColor, type);
456 status = write_field<96>(outfile, count, field_out, file_prec,
cpu_prec, subset,
parity, nSpin,
nColor, type);
459 status = write_field<128>(outfile, count, field_out, file_prec,
cpu_prec, subset,
parity, nSpin,
nColor, type);
462 status = write_field<256>(outfile, count, field_out, file_prec,
cpu_prec, subset,
parity, nSpin,
nColor, type);
465 status = write_field<384>(outfile, count, field_out, file_prec,
cpu_prec, subset,
parity, nSpin,
nColor, type);
486 QIO_Writer *outfile =
open_test_output(filename, QIO_SINGLEFILE, QIO_PARALLEL, QIO_ILDGNO);
487 if (outfile == NULL) {
errorQuda(
"Open file failed\n"); }
490 printfQuda(
"%s: writing %d vector fields\n", __func__, Nvec); fflush(stdout);
492 =
write_field(outfile, 2 * nSpin *
nColor, Nvec,
V, precision, precision, subset,
parity, nSpin,
nColor, type);
493 if (status) {
errorQuda(
"write_spinor_fields failed %d\n", status); }
496 QIO_close_write(outfile);
497 printfQuda(
"%s: Closed file for writing\n",__func__);
enum QudaPrecision_s QudaPrecision
@ QUDA_PARITY_SITE_SUBSET
enum QudaSiteSubset_s QudaSiteSubset
enum QudaParity_s QudaParity
void quda_get_coords(int x[], int node, int index)
int quda_node_index(const int x[])
int quda_num_sites(int node)
int quda_setup_layout(int len[], int nd, int numnodes, int single_parity)
int quda_node_number(const int x[])
int read_su3_field(QIO_Reader *infile, int count, void *field_in[], QudaPrecision cpu_prec)
QIO_Reader * open_test_input(const char *filename, int volfmt, int serpar)
void set_layout(const int *X, QudaSiteSubset subset=QUDA_FULL_SITE_SUBSET)
void read_gauge_field(const char *filename, void *gauge[], QudaPrecision precision, const int *X, int argc, char *argv[])
std::ostream & operator<<(std::ostream &out, const QIO_Layout &layout)
void write_gauge_field(const char *filename, void *gauge[], QudaPrecision precision, const int *X, int argc, char *argv[])
int write_su3_field(QIO_Writer *outfile, int count, void *field_out[], QudaPrecision file_prec, QudaPrecision cpu_prec, const char *type)
int read_field(QIO_Reader *infile, int count, void *field_in[], QudaPrecision cpu_prec, QudaSiteSubset subset, QudaParity parity, int nSpin, int nColor)
void read_spinor_field(const char *filename, void *V[], QudaPrecision precision, const int *X, QudaSiteSubset subset, QudaParity parity, int nColor, int nSpin, int Nvec, int argc, char *argv[])
void vget(char *s1, size_t index, int count, void *s2)
void vput(char *s1, size_t index, int count, void *s2)
int write_field(QIO_Writer *outfile, int count, void *field_out[], QudaPrecision file_prec, QudaPrecision cpu_prec, QudaSiteSubset subset, QudaParity parity, int nSpin, int nColor, const char *type)
void write_spinor_field(const char *filename, void *V[], QudaPrecision precision, const int *X, QudaSiteSubset subset, QudaParity parity, int nColor, int nSpin, int Nvec, int argc, char *argv[])
QIO_Writer * open_test_output(const char *filename, int volfmt, int serpar, int ildgstyle)
Main header file for the QUDA library.