コード例 #1
0
/* Le o arquivo de entrada. */
int read_file(char *path) {
     FILE *f;
     char t;
     int k, flag, dist = 0;
     f = fopen(path, "r");
     if (f == NULL) {
          return -1;
     }
     fscanf(f, "%d", &m);
     fscanf(f, "%d", &n);
     fscanf(f, "%c", &v); /* Ler o '\n'. */
     fscanf(f, "%c", &v);
     fscanf(f, "%d", &d);
     fscanf(f, "%c", &t); /* '\n'... */
     ll_init();
     while (dist < d) {
          fscanf(f, "%c", &t);
          fscanf(f, "%d", &k);
          dist += k;
          flag = ll_add(t, k);
          if (flag != 0) {
               ll_clean();
               return -1;
          }
          fscanf(f, "%c", &t);
     }
     fclose(f);
     return 0;
}
コード例 #2
0
ファイル: db.c プロジェクト: clarkds/Benchmark-Results
/**************************************************************************
* The main function.
**************************************************************************/
int main(int argc, char** argv)
{
  DBState dbState;
  char *m_paramfile, *m_instfile, *m_timefile, *m_resfile;
  pca_timer_t timer;
  PcaCArrayFloat timing;
  uint i = 0;
  float timeSum = 0.0;

  /* check arguments */
  if (argc < 2) {
    fprintf(stderr, "Usage: %s [dataset idx]\n", argv[0]);
    exit(-1);
  }
    
  /* initialize memory managers */
#ifdef VERBOSE
#ifdef PCA_DB_MEM
  printf("Using custom memory management.\n");
#else
  printf("Using standard malloc/free.\n");
#endif
#endif
  ll_init(NUM_LL_BLOCKS);
  rb_init(NUM_RB_BLOCKS);
  tr_init(NUM_TR_BLOCKS);

  /* load up db state and create timing array */
  m_paramfile = (char*) malloc(strlen("data/") + strlen(argv[1]) + 
			       strlen("-db-param.dat") + 1);
  m_instfile = (char*)  malloc(strlen("data/") + strlen(argv[1]) + 
			       strlen("-db-inst.dat") + 1);
  sprintf(m_paramfile, "data/%s-db-param.dat", argv[1]);
  sprintf(m_instfile, "data/%s-db-inst.dat", argv[1]);
  DBState_load(&dbState, m_paramfile, m_instfile);
  pca_create_carray_1d(float, timing, dbState.num_cycles, PCA_REAL);

  /* run the database */
#ifdef VERBOSE
  printf("Running with %d total record(s)... ", dbState.total_records);
#endif
  while (dbState.p_currcmd < dbState.p_lastcmd) {
    timer = startTimer();
    runDatabase(&dbState);
    timing.data[i++] = stopTimer(timer);
    timeSum = timeSum + timing.data[i-1];
  }
  printf("Done.  Latency: %f s.\n", timeSum/((float)dbState.num_cycles));

  /* output timings */
  m_timefile = (char*) malloc(strlen("data/") + strlen(argv[1]) +
			      strlen("-db-timing.dat") + 1);
  sprintf(m_timefile, "data/%s-db-timing.dat", argv[1]);
  writeToFile(float, m_timefile, timing);
  clean_mem(float, timing);

  /* output results of database */
  m_resfile = (char*) malloc(strlen("data/") + strlen(argv[1]) +
			     strlen("-db-results.dat") + 1);
  sprintf(m_resfile, "data/%s-db-results.dat", argv[1]);
  writeToFile(int, m_resfile, dbState.sresults);

  /* cleanup */ 
  free(m_paramfile);
  free(m_instfile);
  free(m_timefile);
  free(m_resfile);
  DBState_clean(&dbState);
  ll_clean();
  rb_clean();
  tr_clean();

  return 0;
}