int copyCorrectOutput(HyPerCol * hc, int argc, char * argv[]) { int status = PV_SUCCESS; std::string sourcePathString = hc->getOutputPath(); sourcePathString += "/" "a3_reconstruction.pvp"; const char * sourcePath = sourcePathString.c_str(); MoviePvp * correctLayer = dynamic_cast<MoviePvp *>(hc->getLayerFromName("correct")); assert(correctLayer); const char * destPath = correctLayer->getInputPath(); if (strcmp(&destPath[strlen(destPath)-4], ".pvp")!=0) { if (hc->columnId()==0) { fprintf(stderr, "%s --generate: This system test assumes that the layer \"correct\" is a Movie layer with imageListPath ending in \".pvp\".\n", argv[0]); } MPI_Barrier(hc->icCommunicator()->communicator()); exit(EXIT_FAILURE); } if (hc->columnId()==0) { PV_Stream * infile = PV_fopen(sourcePath, "r", false/*verifyWrites*/); assert(infile); PV_fseek(infile, 0L, SEEK_END); long int filelength = PV_ftell(infile); PV_fseek(infile, 0L, SEEK_SET); char * buf = (char *) malloc((size_t) filelength); size_t charsread = PV_fread(buf, sizeof(char), (size_t) filelength, infile); assert(charsread == (size_t) filelength); PV_fclose(infile); infile = NULL; PV_Stream * outfile = PV_fopen(destPath, "w", false/*verifyWrites*/); assert(outfile); size_t charswritten = PV_fwrite(buf, sizeof(char), (size_t) filelength, outfile); assert(charswritten == (size_t) filelength); PV_fclose(outfile); outfile = NULL; free(buf); buf = NULL; } return status; }
int TrainingLayer::readTrainingLabels(const char * filename, int ** trainingLabelsFromFile) { PV_Stream * instream = PV_fopen(filename, "r", false/*verifyWrites*/); if( instream == NULL ) { fprintf( stderr, "TrainingLayer error opening \"%s\": %s\n", filename, strerror(errno) ); *trainingLabelsFromFile = NULL; return 0; } int didReadLabel; int n = 0; int label; int * labels = NULL; int * oldlabels; do { didReadLabel = fscanf(instream->fp, "%d", &label); updatePV_StreamFilepos(instream); // to recalculate instream->filepos since it's not easy to tell how many characters were read switch( didReadLabel ) { case 0: PV_fseek( instream, 1L, SEEK_CUR ); break; case 1: n++; oldlabels = labels; labels = (int *) malloc((size_t) n * sizeof(int) ); assert(labels); for(int k=0; k<n-1; k++) labels[k] = oldlabels[k]; labels[n-1] = label; free(oldlabels); break; } } while( didReadLabel != EOF ); PV_fclose(instream); *trainingLabelsFromFile = labels; return n; }
int PointProbe::initOutputStream(const char * filename) { if(parent->columnId()==0){ // Called by LayerProbe::initLayerProbe, which is called near the end of PointProbe::initPointProbe // So this->xLoc, yLoc, fLoc have been set. if( filename != NULL ) { char * outputdir = getParent()->getOutputPath(); char * path = (char *) malloc(strlen(outputdir)+1+strlen(filename)+1); sprintf(path, "%s/%s", outputdir, filename); outputstream = PV_fopen(path, "w", false/*verifyWrites*/); if( !outputstream ) { fprintf(stderr, "LayerProbe error opening \"%s\" for writing: %s\n", path, strerror(errno)); exit(EXIT_FAILURE); } free(path); } else { outputstream = PV_stdout(); } } return PV_SUCCESS; }
int generate(PV_Init* initObj, int rank) { // Remove -r and -c initObj->setRestartFlag(false); initObj->setCheckpointReadDir(NULL); if (rank==0) { pvInfo().printf("Running --generate with effective command line\n", initObj->getProgramName()); initObj->printState(); } if (rank==0) { PV_Stream * emptyinfile = PV_fopen("input/correct.pvp", "w", false/*verifyWrites*/); // Data for a CORRECT_PVP_NX-by-CORRECT_PVP_NY layer with CORRECT_PVP_NF features. // Sparse activity with no active neurons so file size doesn't change with number of features int emptydata[] = {80, 20, 2, CORRECT_PVP_NX, CORRECT_PVP_NY, CORRECT_PVP_NF, 1, 0, 4, 2, 1, 1, CORRECT_PVP_NX, CORRECT_PVP_NY, 0, 0, 0, 1, 0, 0, 0, 0, 0}; size_t numwritten = PV_fwrite(emptydata, 23, sizeof(int), emptyinfile); if (numwritten != 23) { pvErrorNoExit().printf("%s failure to write placeholder data into input/correct.pvp file.\n", initObj->getProgramName()); } PV_fclose(emptyinfile); } int status = rebuildandrun(initObj, NULL, ©CorrectOutput, NULL, 0); return status; }
static char * load_program_source(const char *filename) { struct stat statbuf; char * source; size_t count; PV_Stream * pvstream = PV_fopen(filename, "r", false/*verifyWrites*/); // TODO Only root process should read file and then broadcast to other processes if (pvstream == 0) { fprintf(stderr, "Failed to find source for file %s\n", filename); return NULL; } stat(filename, &statbuf); source = (char *) malloc(statbuf.st_size + 1); count = PV_fread(source, statbuf.st_size, 1, pvstream); assert(count == 1); source[statbuf.st_size] = '\0'; return source; }
int generate(PV_Init* initObj, int rank) { PV_Arguments * arguments = initObj->getArguments(); // Remove -r and -c arguments->setRestartFlag(false); arguments->setCheckpointReadDir(NULL); if (rank==0) { printf("%s --generate running PetaVision with arguments\n", arguments->getProgramName()); arguments->printState(); } if (rank==0) { PV_Stream * emptyinfile = PV_fopen("input/correct.pvp", "w", false/*verifyWrites*/); // Data for a CORRECT_PVP_NX-by-CORRECT_PVP_NY layer with CORRECT_PVP_NF features. // Sparse activity with no active neurons so file size doesn't change with number of features int emptydata[] = {80, 20, 2, CORRECT_PVP_NX, CORRECT_PVP_NY, CORRECT_PVP_NF, 1, 0, 4, 2, 1, 1, CORRECT_PVP_NX, CORRECT_PVP_NY, 0, 0, 0, 1, 0, 0, 0, 0, 0}; size_t numwritten = PV_fwrite(emptydata, 23, sizeof(int), emptyinfile); if (numwritten != 23) { fprintf(stderr, "%s error writing placeholder data into input/correct.pvp file.\n", arguments->getProgramName()); } PV_fclose(emptyinfile); } int status = rebuildandrun(initObj, NULL, ©CorrectOutput, NULL, 0); return status; }
/* * Notes: * - writeImages, offsetX, offsetY are initialized by Image::initialize() */ int Movie::initialize(const char * name, HyPerCol * hc) { int status = Image::initialize(name, hc); if (status != PV_SUCCESS) { fprintf(stderr, "Image::initialize failed on Movie layer \"%s\". Exiting.\n", name); exit(PV_FAILURE); } //Update on first timestep setNextUpdateTime(parent->simulationTime() + hc->getDeltaTime()); PVParams * params = hc->parameters(); //assert(!params->presentAndNotBeenRead(name, "randomMovie")); // randomMovie should have been set in ioParams //if (randomMovie) return status; // Nothing else to be done until data buffer is allocated, in allocateDataStructures //If not pvp file, open fileOfFileNames //assert(!params->presentAndNotBeenRead(name, "readPvpFile")); // readPvpFile should have been set in ioParams if (hc->columnId()==0) { filenamestream = PV_fopen(inputPath, "r", false/*verifyWrites*/); if( filenamestream == NULL ) { fprintf(stderr, "Movie::initialize error opening \"%s\": %s\n", inputPath, strerror(errno)); exit(EXIT_FAILURE); } } //if (!randomMovie) { // //frameNumber handled here // //imageFilename = strdup(getNextFileName(startFrameIndex)); // //assert(imageFilename != NULL); //} // set output path for movie frames if(writeImages){ status = parent->ensureDirExists(movieOutputPath); } if(writeFrameToTimestamp){ std::string timestampFilename = std::string(parent->getOutputPath()); timestampFilename += "/timestamps/"; parent->ensureDirExists(timestampFilename.c_str()); timestampFilename += name; timestampFilename += ".txt"; if(getParent()->icCommunicator()->commRank()==0){ //If checkpoint read is set, append, otherwise, clobber if(getParent()->getCheckpointReadFlag()){ struct stat statbuf; if (PV_stat(timestampFilename.c_str(), &statbuf) != 0) { fprintf(stderr, "%s \"%s\" warning: timestamp file \"%s\" unable to be found. Creating new file.\n", getKeyword(), name, timestampFilename.c_str()); timestampFile = PV::PV_fopen(timestampFilename.c_str(), "w", parent->getVerifyWrites()); } else { timestampFile = PV::PV_fopen(timestampFilename.c_str(), "r+", false/*verifyWrites*/); } } else{ timestampFile = PV::PV_fopen(timestampFilename.c_str(), "w", parent->getVerifyWrites()); } assert(timestampFile); } } return PV_SUCCESS; }