38 #ifdef IPPL_PRINTDEBUG
53 int iomode,
const char *typestr) {
64 int iomode,
const char *typestr) {
73 const char *typestr,
int iomode) {
78 Ippl::abort(
"IO mode for DiscParticle must be INPUT, OUTPUT, or APPEND.");
127 unsigned int attrib)
const {
130 attrib <
RecordList[record]->disctypes.size())
131 return (
RecordList[record]->disctypes[attrib].c_str());
141 unsigned int retval = 0;
142 for (
unsigned int i=0; i <
RecordList[record]->localparticles.size(); ++i)
143 retval +=
RecordList[record]->localparticles[i];
155 FILE *f = fopen(fnm.c_str(), mode.c_str());
158 if (f == 0 && reporterr) {
159 ERRORMSG(
"DiscParticle: Could not open file '" << fnm.c_str());
186 ERRORMSG(
"Bad config file in DiscParticle::write_meta." <<
endl);
189 ERRORMSG(
"Trying to write a DiscParticle .meta file for a DiscParticle");
193 ERRORMSG(
"Only one fileset/SMP max allowed when writing" <<
endl);
203 FILE *outputMeta =
open_file(filename, std::string(
"w"));
209 fprintf(outputMeta,
"Type = %s\n",
TypeString.c_str());
211 fprintf(outputMeta,
"Records = %ld\n", rnum);
215 for (
unsigned int r=0; r <
RecordList.size(); ++r) {
217 fprintf(outputMeta,
"RecordAttribs = %u %d\n", r,
219 fprintf(outputMeta,
"RecordLocPtcl = %u %d\n", r,
221 fprintf(outputMeta,
"RecordGlobPtcl = %u %d\n", r,
225 fprintf(outputMeta,
"RecordElemByte = %u ", r);
228 for (b=0; b<bmax; ++b)
229 fprintf(outputMeta,
" %d",
RecordList[r]->bytesize[b]);
230 fprintf(outputMeta,
"\n");
231 fprintf(outputMeta,
"RecordDiscType = %u ", r);
232 for (b=0; b<bmax; ++b)
233 fprintf(outputMeta,
" %s",
RecordList[r]->disctypes[b].c_str());
234 fprintf(outputMeta,
"\n");
235 fprintf(outputMeta,
"RecordOffset = %u ", r);
237 for (b=0; b<bmax; ++b)
238 fprintf(outputMeta,
" %ld",
RecordList[r]->offset[0][b]);
239 fprintf(outputMeta,
"\n");
257 ERRORMSG(
"Bad config file in DiscParticle::read_meta." <<
endl);
261 bool iserror =
false;
264 DPFDBG(std::string dbgmsgname(
"DP:read_meta:"));
288 DiscMeta outputMeta(filename.c_str());
289 if (outputMeta.size() == 0)
294 for ( ; metaline != outputMeta.end(); ++metaline) {
296 int linesread = (*metaline).first;
297 int numtokens = (*metaline).second.first;
298 std::string *tokens = (*metaline).second.second;
301 if (tokens[0] ==
"Type") {
302 if (numtokens > 1 && sf == 0)
304 }
else if (tokens[0] ==
"SMPs" && numtokens == 2) {
305 unsigned int checkfileSMPs = atoi(tokens[1].c_str());
307 ERRORMSG(
"SMP number mismatch in file " << filename);
312 }
else if (tokens[0] ==
"NextOffset" && numtokens == 2) {
314 }
else if (tokens[0] ==
"Records" && numtokens == 2) {
315 unsigned int numrec = atoi(tokens[1].c_str());
317 ERRORMSG(
"Illegal Records value in file '" << filename <<
"' ");
323 for (
int r=0; r < atoi(tokens[1].c_str()); ++r)
326 }
else if (tokens[0] ==
"RecordAttribs" && numtokens == 3) {
327 unsigned int recnum = atoi(tokens[1].c_str());
328 int attribs = atoi(tokens[2].c_str());
330 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
332 }
else if (sf > 0 && attribs !=
RecordList[recnum]->attributes) {
333 ERRORMSG(
"Illegal number of attributes in file " << filename);
334 ERRORMSG(
" (" << attribs <<
" != ");
340 }
else if (tokens[0] ==
"RecordLocPtcl" && numtokens == 3) {
341 unsigned int recnum = atoi(tokens[1].c_str());
342 int nump = atoi(tokens[2].c_str());
344 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
347 RecordList[recnum]->localparticles.push_back(nump);
349 }
else if (tokens[0] ==
"RecordGlobPtcl" && numtokens == 3) {
350 unsigned int recnum = atoi(tokens[1].c_str());
351 int nump = atoi(tokens[2].c_str());
353 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
355 }
else if (sf > 0 && nump !=
RecordList[recnum]->globalparticles) {
356 ERRORMSG(
"Illegal number of global particles in file "<<filename);
363 }
else if (tokens[0] ==
"RecordElemByte" && numtokens >= 2) {
364 unsigned int recnum = atoi(tokens[1].c_str());
366 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
369 for (
int b=2; b < numtokens; ++b) {
370 int bytesize = atoi(tokens[b].c_str());
371 if (sf > 0 && bytesize !=
RecordList[recnum]->bytesize[b-2]) {
372 ERRORMSG(
"Illegal byte size for attribute " << b-2);
373 ERRORMSG(
" in file " << filename <<
"(" << bytesize);
377 }
else if (sf == 0) {
378 RecordList[recnum]->bytesize.push_back(bytesize);
383 static_cast<unsigned int>(
RecordList[recnum]->attributes))) {
384 ERRORMSG(
"Incorrect number of byte size values in file ");
389 }
else if (tokens[0] ==
"RecordDiscType" && numtokens >= 2) {
390 unsigned int recnum = atoi(tokens[1].c_str());
392 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
395 for (
int b=2; b < numtokens; ++b) {
396 if (sf > 0 && tokens[b] !=
RecordList[recnum]->disctypes[b-2]) {
397 ERRORMSG(
"Inconsistent DiscType for attribute " << b-2);
398 ERRORMSG(
" in file " << filename <<
"(" << tokens[b]);
402 }
else if (sf == 0) {
403 RecordList[recnum]->disctypes.push_back(tokens[b]);
408 static_cast<unsigned int>(
RecordList[recnum]->attributes))) {
409 ERRORMSG(
"Incorrect number of DiscType values in file ");
414 }
else if (tokens[0] ==
"RecordOffset" && numtokens >= 2) {
415 unsigned int recnum = atoi(tokens[1].c_str());
417 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
420 std::vector<Offset_t> offsetvec;
421 for (
int b=2; b < numtokens; ++b) {
422 Offset_t offset = atol(tokens[b].c_str());
423 if (sf > 0 && offset !=
RecordList[recnum]->offset[sf][b-2]) {
424 ERRORMSG(
"Illegal offset for attribute " << b-2);
425 ERRORMSG(
" in file " << filename <<
"(");
426 ERRORMSG(static_cast<long>(offset) <<
" != ");
430 }
else if (sf == 0) {
431 offsetvec.push_back(offset);
435 if (offsetvec.size() != (
RecordList[recnum]->attributes==0 ? 1u :
436 static_cast<unsigned int>(
RecordList[recnum]->attributes))) {
437 ERRORMSG(
"Incorrect number of offset values in file ");
441 RecordList[recnum]->offset.push_back(offsetvec);
450 DPFDBG(dbgmsg <<
"On box0: finished line with tokens[0]='"<<tokens[0]);
451 DPFDBG(dbgmsg <<
"' ... iserror = " << iserror <<
endl);
455 ERRORMSG(
"Format error on line " << linesread <<
" in file ");
466 DPFDBG(dbgmsg <<
"Summary of meta info:" <<
endl);
467 DPFDBG(dbgmsg <<
" iserror = " << iserror <<
endl);
475 DPFDBG(dbgmsg <<
"Informing " << numinform <<
" SMP's of meta info");
477 for (
int s=0; s <= numinform; ++s) {
489 int errint = iserror;
496 for (
unsigned int r=0; r <
RecordList.size(); ++r) {
497 int filesnum =
RecordList[r]->localparticles.size();
501 for (
unsigned int p=0; p <
RecordList[r]->localparticles.size(); ++p)
503 for (
unsigned int b=0; b <
RecordList[r]->bytesize.size(); ++b)
507 std::string unknowndtype =
"u";
508 for (
unsigned int dr =
RecordList[r]->disctypes.size();
510 RecordList[r]->disctypes.push_back(unknowndtype);
512 for (
unsigned int t=0; t <
RecordList[r]->bytesize.size(); ++t)
514 for (
unsigned int z=0; z <
RecordList[r]->offset.size(); ++z) {
515 for (
unsigned int o=0; o <
RecordList[r]->offset[z].size(); ++o) {
524 DPFDBG(dbgmsg<<
"Sending meta info to node " << node <<
" with tag ");
525 DPFDBG(dbgmsg<< tag <<
", on SMP " << smp <<
endl);
535 DPFDBG(dbgmsg <<
"Waiting for meta info from node " << node);
536 DPFDBG(dbgmsg <<
" with tag " << tag <<
endl);
541 DPFDBG(dbgmsg <<
"Summary of received meta info:" <<
endl);
544 int errint = 0, numrec = 0, val = 0;
546 iserror = (errint != 0);
547 DPFDBG(dbgmsg <<
" iserror = " << iserror <<
endl);
552 DPFDBG(dbgmsg <<
" CurrentOffset = " << curroff <<
endl);
554 DPFDBG(dbgmsg <<
" NumRecords = " << numrec <<
endl);
555 for (
int r=0; r < numrec; ++r) {
556 DPFDBG(dbgmsg <<
" For record " << r <<
":" <<
endl);
558 int filesnum =
RecordList[r]->localparticles.size();
560 DPFDBG(dbgmsg <<
" Filesets=" << filesnum <<
endl);
565 DPFDBG(dbgmsg <<
" Attribs=" << numattr <<
endl);
568 for (
int p=0; p < filesnum; ++p) {
570 DPFDBG(dbgmsg <<
" Local " << p <<
" = " << val <<
endl);
573 for (
int b=0; b < numattr; ++b) {
575 DPFDBG(dbgmsg <<
" Bytesize " << b <<
" = " << val <<
endl);
578 for (
int t=0; t < numattr; ++t) {
581 DPFDBG(dbgmsg <<
" Disctype " << t <<
" = " << dtype <<
endl);
584 for (
int z=0; z < filesnum; ++z) {
585 std::vector<Offset_t> offsetvec;
588 for (
int o=0; o < numattr; ++o) {
591 DPFDBG(dbgmsg <<
" Offset " << z <<
"," << o <<
" = ");
593 offsetvec.push_back(offset);
607 DPFDBG(dbgmsg<<
"Cleaning up error record info at end of read_meta"<<
endl);
629 std::vector<int> numvec;
630 std::vector<Offset_t> offsetvec;
636 ERRORMSG(
" in .data file for DiscParticle::write_data." <<
endl);
645 for (
int a=0; a < numattr; ++a) {
646 DPFDBG(dbgmsg<<
"Writing out data from messages for attrib " << a <<
endl);
650 for (
unsigned int n=0;
n < msgvec.size(); ++
n) {
655 msgvec[
n]->get(nump);
656 numvec.push_back(nump);
661 DPFDBG(dbgmsg <<
" Attrib " << a <<
" has " << nump <<
" particles ");
666 void *msgdata = msgvec[
n]->remove();
669 unsigned int totalbytes = nump * info->
bytesize[a];
670 DPFDBG(dbgmsg <<
" Writing out block of " << nump <<
" particles, ");
671 DPFDBG(dbgmsg <<
"with " << totalbytes <<
" bytes." <<
endl);
672 if (fwrite(msgdata, 1, totalbytes, outputData) != totalbytes) {
673 ERRORMSG(
"Write error in DiscParticle::write_data" <<
endl);
687 if ((a+1) == numattr)
693 DPFDBG(dbgmsg <<
"At end of attrib write; totalnum = " << totalnum <<
endl);
694 info->
offset.push_back(offsetvec);
706 unsigned int record,
unsigned int fileset) {
711 int nump =
RecordList[record]->localparticles[fileset];
712 int bytesize =
RecordList[record]->bytesize[attrib];
713 DPFDBG(dbgmsg <<
"Particles=" << nump <<
", sizeof(T)=" << bytesize <<
endl);
716 if (nump < 1 || bytesize < 1)
722 DPFDBG(dbgmsg <<
"seekpos = " << seekpos <<
endl);
723 if (fseek(outputData, seekpos, SEEK_SET) != 0) {
724 ERRORMSG(
"Error seeking to position " << static_cast<long>(seekpos));
725 ERRORMSG(
" in .data file for DiscParticle::read_data." <<
endl);
732 unsigned int totalbytes = nump * bytesize;
733 void *buffer = malloc(totalbytes);
736 DPFDBG(dbgmsg <<
"Reading " << totalbytes <<
" bytes from file ..." <<
endl);
737 if (fread(buffer, 1, totalbytes, outputData) != totalbytes) {
738 ERRORMSG(
"Read error in DiscParticle::read_data" <<
endl);
763 msg <<
"NextOffset = " <<
static_cast<long>(
CurrentOffset) << endl;
766 msg <<
"For record " << r <<
":" <<
endl;
769 msg <<
" Byte size of attributes =";
773 msg <<
" DiscTypes of attributes =";
780 msg <<
" Local number of particles in fileset " << f <<
" = ";
783 msg <<
" Offset of attribute " << a <<
" in fileset " << f <<
" = ";
784 msg << static_cast<long>(
RecordList[r]->offset[f][a]) << endl;
789 msg <<
"Configuration file information:" <<
endl;
void * read_data(FILE *outputData, unsigned int attrib, unsigned int record, unsigned int fileset)
const std::string & getConfigFile() const
std::vector< std::vector< Offset_t > > offset
static void abort(const char *=0, int exitcode=(-1))
const char * get_DiscType(unsigned int record=0, unsigned int attrib=0) const
std::vector< int > localparticles
unsigned int get_ElemByteSize(unsigned int record=0, unsigned int attrib=0) const
unsigned int get_NumLocalParticles(unsigned int record=0) const
unsigned int getNumSMPNodes() const
DiscParticle(const char *fname, const char *config, int iomode, const char *typestr=0)
unsigned int fileSMPs() const
int next_tag(int t, int s=1000)
unsigned int getNumOtherSMP() const
unsigned int get_NumGlobalParticles(unsigned int record=0) const
std::vector< RecordInfo * > RecordList
void printDebug(Inform &)
unsigned int get_NumAttributes(unsigned int record=0) const
unsigned int mySMP() const
unsigned int getOtherSMP(unsigned int sn) const
unsigned int get_NumRecords() const
std::vector< int > bytesize
unsigned int getSMPNode(unsigned int n) const
FILE * open_file(const std::string &fnm, const std::string &mode, bool reporterr=true)
bool write_data(FILE *outputData, std::vector< Message * > &, RecordInfo *)
Message & get(const T &cval)
Message & put(const T &val)
container_t::iterator iterator
void getMessage(Message &m, T &t)
const std::string & getFilename(unsigned int fn) const
std::string::iterator iterator
void putMessage(Message &m, const T &t)
unsigned int getSMPBox0() const
Message * receive_block(int &node, int &tag)
static Communicate * Comm
bool send(Message *, int node, int tag, bool delmsg=true)
unsigned int getNumFiles() const
void initialize(const char *base, const char *config, const char *typestr, int iomode)
Inform & endl(Inform &inf)