dev:data_output
Table of Contents
Getting Statistical Data Out of Your Simulation
You have a simulation up and running, but how do you get the statistical data you need ouput to a file? Below you will find some code provided by Professor Ackley that will allow you to do so.
There are two files that need to be modified:
1. /src/drivers/mfmc/src/main.cpp 2. /src/sim/include/AbstractDriver.h
main.cpp
To edit the main.cpp file, paste the following code into the Private section of the file:
const char* GetSimDirPathTemporary(const char* format, ...) const { static OverflowableCharBufferByteSink<500> buf; buf.Reset(); buf.Printf("%s",this->GetSimulationBasePath()); va_list ap; va_start(ap, format); buf.Vprintf(format, ap); if (buf.HasOverflowed()) { FAIL(OUT_OF_ROOM); } return buf.GetZString(); }
and
typedef typename CC::PARAM_CONFIG P; typedef typename CC::ATOM_TYPE T;
Then paste the following in the public section of main.cpp:
virtual void DoEpochEvents(Grid<GC>& grid, u32 epochs, u32 epochAEPS) { u32 H = Grid<GC>::GetHeight(); u32 W = Grid<GC>::GetWidth(); u32 emptyCount = 0; for (u32 y = 0; y < H; ++y) { for (u32 x = 0; x < W; ++x) { Tile<CC> & tile = grid.GetTile(SPoint(x,y)); for (u32 x = 0; x < P::TILE_WIDTH; ++x) { for (u32 y = 0; y < P::TILE_WIDTH; ++y) { const SPoint pt(x, y); if(Tile<CC>::IsInCache(pt)) { continue; } const T * atom = tile.GetAtom(x,y); //<<<TODO>>> This is where you grab the data from your element. Modify accordingly. if (atom->GetType() == Element_Empty<CC>::THE_INSTANCE.GetType()) ++emptyCount; } } } } //<<<TODO>>> replace FILE_NAME with the file name of your choice const char* path = GetSimDirPathTemporary("tbd/FILE_NAME.dat"); FILE* fp = fopen(path, "a"); //<<<TODO>>> This is where you output the specific data you need. Modify accordingly. fprintf(fp, "%d %d %d\n",epochs, epochAEPS, emptyCount); fclose(fp); // Remember to let the parent run too! Super::DoEpochEvents(grid, epochs, epochAEPS); }
Please note: There are 3 TODO tags in the above snippet. These are where you'll need to modify the code to suit your needs.
AbstractDriver.h
Now we need to do a small modifcation to the AbstractDriver.h file. Paste the following code into the public section:
const char * GetSimulationBasePath() const { return &m_simDirBasePath[0]; }
And that's it! Happy scienceing.
dev/data_output.txt · Last modified: 2014/10/17 03:55 by csymonds