asciiprinter.cpp
Go to the documentation of this file.
59 //TODO: It would be good to add something like this to the Gambit Utils to use as a standard I think. 69 ss << "IO error while opening file for writing! Tried to open ofstream to file \""<<filename<<"\", but encountered error bit in the created ostream."; 99 output_file = Utils::ensure_path_exists(options.getValueOrDef<std::string>(f.str(),"output_file")); 175 AP_DBUG( std::cout << "Destructing asciiPrinter object (with name=\""<<printer_name<<"\")..." << std::endl; ) 179 // Run by dependency resolver, which supplies the functors with a vector of VertexIDs whose requiresPrinting flags are set to true. 182 // Currently don't seem to need this... could use it to check if all VertexID's have submitted print requests. 191 err << "Sorry, the asciiPrinter is currently in a state of neglect, and lacks features necessary for constructing reader objects for resume data. If you really want these features then please file a bug to make your desires known :)." << std::endl; 200 AP_DBUG( std::cout << "Buffer (of asciiPrinter with name=\""<<printer_name<<"\") successfully dumped..." << std::endl; ) 221 // Used to just erase the records, but preserve vertex IDs. Not sure this is necessary, so for now just 231 void asciiPrinter::addtobuffer(const std::vector<double>& functor_data, const std::vector<std::string>& functor_labels, const int vID, const int rank, const int pointID) 233 //TODO: If a functor gets called twice without the printer advancing the data will currently just be overwritten. Should generate an error or something. 237 PPIDpair ppid(pointID,rank); // This is a bit clunky because I added PPIDpairs later, so not all asciiprinter internals have been updated to use these instead of simple pairs. 240 AP_DBUG( std::cout << "Rank "<<myRealRank<<": adding data from (ptID,rank) "<<ppid<<"; labels="<<functor_labels<<std::endl; ) 241 AP_DBUG( std::cout << "Rank "<<myRealRank<<": last point was from (ptID,rank) "<<lastPointID<<std::endl; ) 242 //AP_DBUG( std::cout << "Rank "<<this->getRank()<<": Note: nullpoint is (ptID,rank) "<<nullpoint<<std::endl; ) 260 err << "Tried to move asciiPrinter buffer to new point '" << ppid << "', however the *previous* point '" << endl 261 << lastPointID << "' could not be found in the buffer (we need to set it as 'finished'). This " << endl 262 << "probably means that the old point was never actually entered into the buffer, which must " << endl 275 AP_DBUG( std::cout << "asciiPrinter: Buffer full ("<< buffer.size() <<" records), running buffer dump"<<std::endl; ) 296 // Do not write suspicious points to buffer as this will require extending the dataset, which is not possible in ascii 305 if ( label_record.find(vID)==label_record.end() or functor_labels.size()>label_record.at(vID).size() ) 307 // Assume the new, longer label list is better to use. This variation of functor_data length from point to point is kind of dangerous for an ascii output file though and we might want to forbid it. There is some probability that my method of allocating the columns according to the longest used by each functor in the first buffer dump will fail. 317 // Note the downside of using a map as the buffer; the order of stuff in the output file is going 318 // to be kind of haphazard due to the sorted order used by map. Will have to do more work to achieve 331 // To do this we need to go through the buffer and find the maximum length of vector associated with each VertexID. 358 errmsg << "Error! Output format has changed since last buffer dump! The asciiPrinter cannot handle this!" 392 for(std::vector<int>::iterator it = increased_lengths.begin(); it!=increased_lengths.end(); ++it) 395 errmsg<<" orig length="<<lineindexrecord.at(*it)<<", new length="<<newlineindexrecord.at(*it)<<std::endl; 408 open_output_file(info_fstream, info_file, std::ofstream::trunc); // trunc mode overwrites old content 435 AP_DBUG( std::cout << "asciiPrinter: Examining record with key <rank="<<bufentry->first.first<<", pointID="<<bufentry->first.second<<">"<< std::endl; ) 480 AP_DBUG( std::cout << "asciiPrinter: Erasing record <rank="<<bkey.first<<", pointID="<<bkey.second<<">"<< std::endl; ) Define overloadings of the stream operator for various containers. LineBuf data The data; each functor outputs a vector of doubles. We index these by vertexID. Definition: asciiprinter.hpp:58 std::map< int, int > lineindexrecord Definition: asciiprinter.hpp:214 unsigned long long int pointID Definition: new_mpi_datatypes.hpp:92 bool info_file_written Definition: asciiprinter.hpp:218 void reset(bool force=false) Delete contents of output file (to be replaced/updated) and erase everything in the buffer... Definition: asciiprinter.cpp:209 unsigned int bufferlength Number of lines to store in buffer before printing. Definition: asciiprinter.hpp:181 Definition: log_tags.hpp:38 bool hasKey(const args &... keys) const Getters for key/value pairs (which is all the options node should contain) Definition: yaml_options.hpp:67 General small utility functions. void erase_buffer() Ask the printer for the highest ID number known for a given rank process (needed for resuming... Definition: asciiprinter.cpp:219 void common_constructor(const Options &) Tasks common to the various constructors. Definition: asciiprinter.cpp:85 Ascii printer class declaration. Definition: log_tags.hpp:36 asciiPrinter(const Options &, BasePrinter *const primary=NULL) TODO: proper gambit error. Definition: asciiprinter.cpp:153 std::string printer_name Label for printer, mostly for more helpful error messages. Definition: asciiprinter.hpp:190 std::string get_output_filename() Definition: asciiprinter.cpp:227 EXPORT_SYMBOLS const str & ensure_path_exists(const str &) Ensure that a path exists (and then return the path, for chaining purposes) Definition: util_functions.cpp:227 std::map< int, std::vector< std::string > > label_record Record a set of labels for each printer item: used to write "info" file explain what is in each colum... Definition: asciiprinter.hpp:217 TYPE getValueOrDef(TYPE def, const args &... keys) const Definition: yaml_options.hpp:115 A simple C++ wrapper for the MPI C bindings. void addtobuffer(const std::vector< double > &, const std::vector< std::string > &, const int, const int, const int) Definition: asciiprinter.cpp:231 void initialise(const std::vector< int > &) Virtual function overloads: Definition: asciiprinter.cpp:180 PPIDpair lastPointID Recording of which model point each process is working on. Definition: asciiprinter.hpp:210 Exception objects required for standalone compilation. void open_output_file(std::ofstream &output, std::string filename, std::ios_base::openmode mode) Open file stream with error checking. Definition: asciiprinter.cpp:61 Options resume_reader_options() Definition: asciiprinter.cpp:188 Structure to hold data for a single model point. Definition: asciiprinter.hpp:54 void dump_buffer(bool force=false) Definition: asciiprinter.cpp:314 EXPORT_SYMBOLS const PPIDpair nullpoint Define 'nullpoint' const. Definition: new_mpi_datatypes.cpp:185 int get_bufferlength() Definition: asciiprinter.cpp:228 pointID / process number pair Used to identify a single parameter space point Definition: new_mpi_datatypes.hpp:90 std::string info_file Info file (describes contents of output file, i.e. contents of columns) Definition: asciiprinter.hpp:173 bool readyToPrint Flag to indicate if record is available to send for output. Definition: asciiprinter.hpp:62 |