Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}