Пример #1
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;
}
Пример #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;
}
Пример #3
0
int MapReduceKernelConn::reduceKernels(const int arborID) {
	int status = HyPerConn::reduceKernels(arborID);
	int rootproc = 0;
	InterColComm *icComm = parent->icCommunicator();
	const int numPatches = getNumDataPatches();
	const size_t patchSize = nxp * nyp * nfp * sizeof(pvdata_t);
	const size_t localSize = numPatches * patchSize;
	const size_t arborSize = localSize * this->numberOfAxonalArborLists();
	if (icComm->commRank() == rootproc) {
		// write dW for this instantiation of PetaVision to disk
		status = HyPerConn::writeWeights(NULL, this->get_dwDataStart(),
				getNumDataPatches(), dWeightsList[dWeightFileIndex],
				parent->simulationTime(), /*writeCompressedWeights*/false, /*last*/
				false);
		if (status != PV_SUCCESS) {
			fprintf(stderr,
					"MapReduceKernelConn::reduceKernels::HyPerConn::writeWeights: problem writing to file %s, "
							"SHUTTING DOWN\n", dWeightsList[dWeightFileIndex]);
			exit(EXIT_FAILURE);
		} // status
		  // use dWeightsList to read in the weights written by other PetaVision instantiations
		double dW_time;
		double simulation_time = parent->simulationTime();
		int filetype, datatype;
		int numParams = NUM_BIN_PARAMS + NUM_WGT_EXTRA_PARAMS;
		int params[NUM_BIN_PARAMS + NUM_WGT_EXTRA_PARAMS];
		const PVLayerLoc *preLoc = this->preSynapticLayer()->getLayerLoc();
		int file_count = 0;
		for (file_count = 0; file_count < num_dWeightFiles; file_count++) {
			if (file_count == dWeightFileIndex) {
				continue;
			}
			int num_attempts = 0;
			const int MAX_ATTEMPTS = 5;
			dW_time = 0;
			while (dW_time < simulation_time && num_attempts <= MAX_ATTEMPTS) {
				pvp_read_header(dWeightsList[file_count], icComm, &dW_time,
						&filetype, &datatype, params, &numParams);
				num_attempts++;
			} // while
			if (num_attempts > MAX_ATTEMPTS) {
				fprintf(stderr,
						"PV::MapReduceKernelConn::reduceKernels: problem reading arbor file %s, SHUTTING DOWN\n",
						dWeightsList[file_count]);
				status = EXIT_FAILURE;
				exit(EXIT_FAILURE);
			} // num_attempts > MAX_ATTEMPTS
			int status = PV::readWeights(NULL, get_dwDataStart(),
					this->numberOfAxonalArborLists(), this->getNumDataPatches(), nxp, nyp, nfp,
					dWeightsList[file_count], icComm, &dW_time, preLoc);
			if (status != PV_SUCCESS) {
				fprintf(stderr,
						"MapReduceKernelConn::reduceKernels::PV::readWeights: problem reading file %s, "
								"SHUTTING DOWN\n", dWeightsList[file_count]);
				exit(EXIT_FAILURE);
			} // status
		} // file_count < numWeightFiles
		  // average dW from map-reduce
		pvwdata_t * dW_data = this->get_dwDataStart(0);
		for (int i_dW = 0; i_dW < arborSize; i_dW++) {
			dW_data[i_dW] /= num_dWeightFiles;
		}
	} // rootproc

	// broadcast map-reduced dWeights to all non-root processes
	MPI_Comm mpi_comm = icComm->communicator();
#ifdef PV_USE_MPI
	MPI_Bcast(this->get_wDataStart(0), arborSize, MPI_FLOAT, rootproc, mpi_comm);
#endif
	return PV_BREAK;
}