8 #include "PointProbe.hpp" 9 #include "../layers/HyPerLayer.hpp" 14 PointProbe::PointProbe() {
20 PointProbe::PointProbe(
const char *name, HyPerCol *hc) :
LayerProbe() {
25 PointProbe::~PointProbe() {}
27 int PointProbe::initialize_base() {
35 int PointProbe::initialize(
const char *name, HyPerCol *hc) {
45 ioParam_batchLoc(ioFlag);
49 void PointProbe::ioParam_xLoc(
enum ParamsIOFlag ioFlag) {
50 parent->parameters()->ioParamValueRequired(ioFlag, getName(),
"xLoc", &xLoc);
53 void PointProbe::ioParam_yLoc(
enum ParamsIOFlag ioFlag) {
54 parent->parameters()->ioParamValueRequired(ioFlag, getName(),
"yLoc", &yLoc);
57 void PointProbe::ioParam_fLoc(
enum ParamsIOFlag ioFlag) {
58 parent->parameters()->ioParamValueRequired(ioFlag, getName(),
"fLoc", &fLoc);
61 void PointProbe::ioParam_batchLoc(
enum ParamsIOFlag ioFlag) {
62 parent->parameters()->ioParamValueRequired(ioFlag, getName(),
"batchLoc", &batchLoc);
73 assert(getTargetLayer());
74 const PVLayerLoc *loc = getTargetLayer()->getLayerLoc();
75 bool isRoot = parent->getCommunicator()->commRank() == 0;
77 if ((xLoc < 0 || xLoc > loc->nxGlobal) && isRoot) {
79 "PointProbe on layer %s: xLoc coordinate %d is out " 80 "of bounds (layer has %d neurons in " 82 getTargetLayer()->getName(),
87 if ((yLoc < 0 || yLoc > loc->nyGlobal) && isRoot) {
89 "PointProbe on layer %s: yLoc coordinate %d is out " 90 "of bounds (layer has %d neurons in " 92 getTargetLayer()->getName(),
97 if ((fLoc < 0 || fLoc > loc->nf) && isRoot) {
99 "PointProbe on layer %s: fLoc coordinate %d is out " 100 "of bounds (layer has %d features.\n",
101 getTargetLayer()->getName(),
106 if ((batchLoc < 0 || batchLoc > loc->nbatch) && isRoot) {
108 "PointProbe on layer %s: batchLoc coordinate %d is " 109 "out of bounds (layer has %d " 111 getTargetLayer()->getName(),
118 return Response::SUCCESS;
122 PVLayerLoc const *loc = getTargetLayer()->getLayerLoc();
123 int xRank = xLoc / loc->nx;
124 int yRank = yLoc / loc->ny;
125 int batchRank = batchLoc / loc->nbatch;
131 if (xRank == blockColumnIndex and yRank == blockRowIndex and batchRank == blockBatchIndex) {
134 std::ios_base::openmode mode = std::ios_base::out;
135 if (!checkpointer->getCheckpointReadDirectory().empty()) {
136 mode |= std::ios_base::app;
138 if (path[0] !=
'/') {
141 auto stream =
new FileStream(path.c_str(), mode, checkpointer->doesVerifyWrites());
142 mOutputStreams.push_back(stream);
145 auto stream =
new PrintStream(PV::getOutputStream());
146 mOutputStreams.push_back(stream);
150 mOutputStreams.clear();
167 return Response::SUCCESS;
175 const PVLayerLoc *loc = getTargetLayer()->getLayerLoc();
177 const int kx0 = loc->kx0;
178 const int ky0 = loc->ky0;
179 const int kb0 = loc->kb0;
180 const int nx = loc->nx;
181 const int ny = loc->ny;
182 const int nf = loc->nf;
183 const int nbatch = loc->nbatch;
184 const int xLocLocal = xLoc - kx0;
185 const int yLocLocal = yLoc - ky0;
186 const int nbatchLocal = batchLoc - kb0;
189 if (xLocLocal >= 0 && xLocLocal < nx && yLocLocal >= 0 && yLocLocal < ny && nbatchLocal >= 0
190 && nbatchLocal < nbatch) {
191 const float *V = getTargetLayer()->getV();
192 const float *activity = getTargetLayer()->
getLayerData();
194 const int k = kIndex(xLocLocal, yLocLocal, fLoc, nx, ny, nf);
196 valuesBuffer[0] = V[k + nbatchLocal * getTargetLayer()->getNumNeurons()];
199 valuesBuffer[0] = 0.0;
202 const int kex = kIndexExtended(
203 k, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up);
204 valuesBuffer[1] = activity[kex + nbatchLocal * getTargetLayer()->getNumExtended()];
207 valuesBuffer[1] = 0.0;
210 if (parent->columnId() != 0) {
211 MPI_Send(valuesBuffer, 2, MPI_DOUBLE, 0, 0, parent->getCommunicator()->communicator());
216 if (parent->columnId() == 0) {
219 int xRank = xLoc / nx;
220 int yRank = yLoc / ny;
222 int srcRank = rankFromRowAndColumn(
225 parent->getCommunicator()->numCommRows(),
226 parent->getCommunicator()->numCommColumns());
236 parent->getCommunicator()->communicator(),
242 void PointProbe::writeState(
double timevalue) {
243 if (!mOutputStreams.empty()) {
LayerProbe(const char *name, HyPerCol *hc)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
char const * getProbeOutputFilename()
PrintStream & output(int b)
static bool completed(Status &a)
virtual void initNumValues() override
int getStartColumn() const
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
int getColumnIndex() const
double * getValuesBuffer()
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
int initialize(const char *name, HyPerCol *hc)
const char * getMessage()
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
virtual void calcValues(double timevalue) override
void getValues(double timevalue, double *valuesVector)
virtual void writeState(double timevalue) override
int getBatchIndex() const
int getStartBatch() const
virtual void initOutputStreams(const char *filename, Checkpointer *checkpointer) override
virtual Response::Status outputState(double timef) override
const float * getLayerData(int delay=0)
std::string makeOutputPathFilename(std::string const &path)