int MapReduceKernelConn::initialize(const char * name, HyPerCol * hc) {
   int status = HyPerConn::initialize(name, hc);
   // if (status==PV_SUCCESS) status = setMovieLayerName();
   InterColComm *icComm = parent->icCommunicator();
   int rootproc = 0;
   int file_count = 0;
   PV_Stream * dWeightstream = pvp_open_read_file(this->dWeightsListName,
           icComm);
   if ((dWeightstream == NULL) && (icComm->commRank() == rootproc)) {
       fprintf(stderr,
             "MapReduceKernelConn::initialize: Cannot open list of dWeight files \"%s\".  Exiting.\n",
             this->dWeightsListName); // CHECK THIS! // CHECK THIS! this->dWeightsListName was filename but filename is no more
       exit(EXIT_FAILURE);
   } // dWeightstream == NULL

   if (icComm->commRank() == rootproc) {
      for (file_count = 0; file_count < num_dWeightFiles; file_count++) {
         /*
         for (int i_char = 0; i_char < PV_PATH_MAX; i_char++) {
            dWeightsList[file_count][i_char] = 0;
         }
         */

         char * fgetsstatus = fgets(dWeightsList[file_count], PV_PATH_MAX, dWeightstream->fp);
         if (fgetsstatus == NULL) {
            bool endoffile = feof(dWeightstream->fp) != 0;
            if (endoffile) {
               fprintf(stderr,
                       "MapReduceKernelConn::initialize: "
                               "File of weight files \"%s\" reached end of file before all %d weight files were read.  "
                               "Exiting.\n", dWeightstream->name, num_dWeightFiles); // CHECK THIS! dWeightstream->name was filename but filename is no more
               exit(EXIT_FAILURE);
            }
            else {
               int error = ferror(dWeightstream->fp);
               assert(error);
               fprintf(stderr,
                     "MapReduceKernelConn::initialize: File of weight files error reading:%s.  Exiting.\n", strerror(error));
               exit(error);
            }
         }
         else {
            // Remove linefeed from end of string
            dWeightsList[file_count][PV_PATH_MAX - 1] = '\0';
            int len = strlen(dWeightsList[file_count]);
            if (len > 1) {
               if (dWeightsList[file_count][len - 1] == '\n') {
                  dWeightsList[file_count][len - 1] = '\0';
               }
            }
         } // fgetsstatus == NULL
     } // file_count
     this->dWeightsFilename = strdup(dWeightsList[dWeightFileIndex]);
     std::cout << "dWeightFile[" << dWeightFileIndex << "] = "
           << dWeightsList[dWeightFileIndex] << std::endl;
   } // commRank() == rootproc
   return status;
}
Esempio n. 2
0
int InitWeights::readListOfArborFiles(PVPatch *** patches, pvwdata_t ** dataStart, int numPatches, const char * listOfArborsFilename, double * timef) {
   int arbor=0;
   InterColComm *icComm = callingConn->getParent()->icCommunicator();
   int numArbors = callingConn->numberOfAxonalArborLists();
   const PVLayerLoc *preLoc = callingConn->preSynapticLayer()->getLayerLoc();
   double timed;
   PV_Stream * arborstream = pvp_open_read_file(listOfArborsFilename, icComm);

   int rootproc = 0;
   char arborfilename[PV_PATH_MAX];
   while( arbor < callingConn->numberOfAxonalArborLists() ) {
      if( icComm->commRank() == rootproc ) {
         char * fgetsstatus = fgets(arborfilename, PV_PATH_MAX, arborstream->fp);
         if( fgetsstatus == NULL ) {
            bool endoffile = feof(arborstream->fp)!=0;
            if( endoffile ) {
               fprintf(stderr, "File of arbor files \"%s\" reached end of file before all %d arbors were read.  Exiting.\n", listOfArborsFilename, numArbors);
               exit(EXIT_FAILURE);
            }
            else {
               int error = ferror(arborstream->fp);
               assert(error);
               fprintf(stderr, "File of arbor files: error %d while reading.  Exiting.\n", error);
               exit(error);
            }
         }
         else {
            // Remove linefeed from end of string
            arborfilename[PV_PATH_MAX-1] = '\0';
            int len = strlen(arborfilename);
            if (len > 1) {
               if (arborfilename[len-1] == '\n') {
                  arborfilename[len-1] = '\0';
               }
            }
         }
      } // commRank() == rootproc
      int filetype, datatype;
      int numParams = NUM_BIN_PARAMS+NUM_WGT_EXTRA_PARAMS;
      int params[NUM_BIN_PARAMS+NUM_WGT_EXTRA_PARAMS];
      pvp_read_header(arborfilename, icComm, &timed, &filetype, &datatype, params, &numParams);
      int thisfilearbors = params[INDEX_NBANDS];
      const int nxp = callingConn->xPatchSize();
      const int nyp = callingConn->yPatchSize();
      const int nfp = callingConn->fPatchSize();

      int status = PV::readWeights(patches ? &patches[arbor] : NULL, &dataStart[arbor], numArbors-arbor, numPatches, nxp, nyp, nfp, arborfilename, icComm, &timed, preLoc);
      if (status != PV_SUCCESS) {
         fprintf(stderr, "PV::InitWeights::readWeights: problem reading arbor file %s, SHUTTING DOWN\n", arborfilename);
         exit(EXIT_FAILURE);
      }
      arbor += thisfilearbors;
   }  // while
   pvp_close_file(arborstream, icComm);
   return PV_SUCCESS;
}
Esempio n. 3
0
int InitWeights::readCombinedWeightFiles(PVPatch *** patches, pvwdata_t ** dataStart,int numPatches, const char * fileOfWeightFiles, double * timef) {
   InterColComm *icComm = callingConn->getParent()->icCommunicator();
   int numArbors = callingConn->numberOfAxonalArborLists();
   const PVLayerLoc *preLoc = callingConn->preSynapticLayer()->getLayerLoc();
   double timed;
   int rootproc = 0;
   int max_weight_files = 1;  // arbitrary limit...
   int num_weight_files = weightParams->getNumWeightFiles();
   int file_count=0;
   PV_Stream * weightstream = pvp_open_read_file(fileOfWeightFiles, icComm);
   if ((weightstream == NULL) && (icComm->commRank() == rootproc) ){
      pvError().printf("Cannot open file of weight files \"%s\".  Exiting.\n", fileOfWeightFiles);
   }

   char weightsfilename[PV_PATH_MAX];
   while( file_count < num_weight_files ) {
      if( icComm->commRank() == rootproc ) {
         char * fgetsstatus = fgets(weightsfilename, PV_PATH_MAX, weightstream->fp);
         if( fgetsstatus == NULL ) {
            bool endoffile = feof(weightstream->fp)!=0;
            if( endoffile ) {
               pvError().printf("File of weight files \"%s\" reached end of file before all %d weight files were read.  Exiting.\n", fileOfWeightFiles, num_weight_files);
            }
            else {
               int error = ferror(weightstream->fp);
               assert(error);
               pvError().printf("File of weight files: error %d while reading.  Exiting.\n", error);
            }
         }
         else {
            // Remove linefeed from end of string
            weightsfilename[PV_PATH_MAX-1] = '\0';
            int len = strlen(weightsfilename);
            if (len > 1) {
               if (weightsfilename[len-1] == '\n') {
                  weightsfilename[len-1] = '\0';
               }
            }
         }
      } // commRank() == rootproc
      int filetype, datatype;
      int numParams = NUM_BIN_PARAMS+NUM_WGT_EXTRA_PARAMS;
      int params[NUM_BIN_PARAMS+NUM_WGT_EXTRA_PARAMS];
      pvp_read_header(weightsfilename, icComm, &timed, &filetype, &datatype, params, &numParams);
      const int nxp = callingConn->xPatchSize();
      const int nyp = callingConn->yPatchSize();
      const int nfp = callingConn->fPatchSize();
      int status = PV::readWeights(patches, dataStart, numArbors, numPatches, nxp, nyp, nfp, weightsfilename, icComm, &timed, preLoc);
      if (status != PV_SUCCESS) {
         pvError().printf("PV::InitWeights::readWeights: problem reading arbor file %s, SHUTTING DOWN\n", weightsfilename);
      }
      file_count += 1;
   } // file_count < num_weight_files

   return PV_SUCCESS;
}
  int ANNWeightedErrorLayer::allocateDataStructures() 
  {
    int status = HyPerLayer::allocateDataStructures();
    int nf = getLayerLoc()->nf;
    errWeights = (float *) calloc(nf, sizeof(float *));
    for(int i_weight = 0; i_weight < nf; i_weight++){
      errWeights[i_weight] = 1.0f;
    }
    PV_Stream * pvstream = NULL;
    InterColComm *icComm = getParent()->icCommunicator();
    char errWeight_string[PV_PATH_MAX];
    if (getParent()->icCommunicator()->commRank()==0) {
      PV_Stream * errWeights_stream = pvp_open_read_file(errWeightsFileName, icComm);
      for(int i_weight = 0; i_weight < nf; i_weight++){

	char * fgetsstatus = fgets(errWeight_string, PV_PATH_MAX, errWeights_stream->fp);
	if( fgetsstatus == NULL ) {
	  bool endoffile = feof(errWeights_stream->fp)!=0;
	  if( endoffile ) {
	    fprintf(stderr, "File of errWeights \"%s\" reached end of file before all %d errWeights were read.  Exiting.\n", errWeightsFileName, nf);
	    exit(EXIT_FAILURE);
	  }
	  else {
	    int error = ferror(errWeights_stream->fp);
	    assert(error);
	    fprintf(stderr, "File of errWeights: error %d while reading.  Exiting.\n", error);
	    exit(error);
	  }
	}
	else {
	  // Remove linefeed from end of string
	  errWeight_string[PV_PATH_MAX-1] = '\0';
	  int len = strlen(errWeight_string);
	  if (len > 1) {
	    if (errWeight_string[len-1] == '\n') {
	      errWeight_string[len-1] = '\0';
	    }
	  }
	} // fgetstatus
	
	// set errWeight = chance / relative fraction 
	float errWeight_tmp = atof(errWeight_string);
	fprintf(stderr, "errWeight %i = %f\n", i_weight, errWeight_tmp);
	errWeights[i_weight] = (1.0/nf) / errWeight_tmp;

      } // i_weight
      
    } // commRank() == rootproc
#ifdef PV_USE_MPI
      //broadcast errWeights
    MPI_Bcast(errWeights, nf, MPI_FLOAT, 0, icComm->communicator());
#endif // PV_USE_MPI
     
  }