Ejemplo n.º 1
0
int energymon_init_rapl(energymon* em) {
  if (em == NULL || em->state != NULL) {
    errno = EINVAL;
    return -1;
  }

  unsigned int count = rapl_zone_count();
  if (count == 0) {
    if (errno) {
      perror(RAPL_BASE_DIR);
    } else {
      fprintf(stderr, "energymon_init_rapl: No RAPL zones found!\n");
    }
    return -1;
  }

  size_t size = sizeof(energymon_rapl) + count * sizeof(rapl_zone);
  energymon_rapl* state = calloc(1, size);
  if (state == NULL) {
    return -1;
  }

  if (rapl_init(state, count)) {
    free(state);
    return -1;
  }

  em->state = state;
  return 0;
}
Ejemplo n.º 2
0
void fileparse(unsigned int num_rows){

  char search_phrase[] = "AdeptProject";
  size_t sp_len = strlen(search_phrase);

  unsigned int desired_line_len = 81;
  char line[desired_line_len];

  srand(time(NULL)); // Set seed

  int i = 0;
  int r = 0;
  int m = 0;
  int mismatch = 0;
  int r_count = 0;
  int m_count = 0;
  struct timespec start, end;

  FILE* fp;
  fp = fopen("testfile", "w+");

  for (i=0;i<num_rows;i++){
    r = create_line(search_phrase, sp_len, line, desired_line_len);
    m = seek_match(search_phrase, sp_len, line, desired_line_len);
    if (r!=m){
      mismatch++;
    }
    if (r==0){
      r_count++;
    }
    fprintf(fp, "%s\n", line);
  }
  fsync(fileno(fp));
  fclose(fp);

  m=0;

  /* As an example, here we initialise the library, and then start measurements. */
  rapl_init();
  rapl_start();
  clock_gettime(CLOCK, &start);
  fp = fopen("testfile", "r");
  while (fscanf(fp, "%s\n", line)!=EOF){
    m = seek_match(search_phrase, sp_len, line, desired_line_len);
    if (m==0){
      m_count++;
    }
  }
  fclose(fp);
  clock_gettime(CLOCK, &end);
  rapl_end();
  rapl_deinit();
  /* And then we finish the meausurements and free the library */
  elapsed_time_hr(start, end, "Fileparse");

  unlink("testfile"); // Use this to ensure the generated file is removed from the system upon finish

}
Ejemplo n.º 3
0
void printing_functions(int * idx, int argc, char ** argv)
{
    uint64_t * rapl_flags = NULL;
    struct rapl_data * rd = NULL, *r1 = NULL, *r2 = NULL;
    switch(argv[*idx][2])
    {
        rapl_init(&rd, &rapl_flags);
        case '\0':
            if (*idx >= argc)
            {
                generic_error(*idx, argv);
            }
            type2_print(idx, argc, argv);
            break;
        case 'r':
            get_rapl_stuff();
            break;
        case 'i':
            dump_rapl_power_info(stdout);
            break;
        default:
            generic_error(*idx, argv);
    }
}
Ejemplo n.º 4
0
int conjugate_gradient(unsigned int s)
{
  CSRmatrix *A;
  int i;
  double *x, *b, *r, *p, *omega;
  int k;
  double r0, r1, beta, dot, alpha;
  double tol = PCG_TOLERANCE * PCG_TOLERANCE;

  struct timespec start, end;

  /*======================================================================
   *
   * generate a random matrix of size s x s
   *
   *======================================================================*/
  A = malloc(sizeof(CSRmatrix));
  A->nrow = s;
  A->ncol = s;
  A->nzmax = s;
  A->colIndex = malloc(A->nzmax * sizeof(int));
  A->rowStart = malloc((A->nrow+1) * sizeof(int));
  A->values = malloc(A->nzmax * sizeof(double));

  /* generate structure for matrix */
  for (i = 0; i < A->nrow; i++) {
    A->rowStart[i] = i;
    A->colIndex[i] = i;
  }
  A->rowStart[i] = i;

  /* now generate values for matrix */
  srand((unsigned int)time(NULL));

  for (i = 0; i < A->nzmax; i++) {
    A->values[i] = rand() / 32768.0;
  }

  /*======================================================================
   *
   * Initialise vectors
   *
   *======================================================================*/
  /* allocate vectors (unknowns, RHS and temporaries) */
  x = malloc(s * sizeof(double));
  b = malloc(s * sizeof(double));
  r = malloc(s * sizeof(double));
  p = malloc(s * sizeof(double));
  omega = malloc(s * sizeof(double));

  /* generate a random vector of size s for the unknowns */
  for (i = 0; i < s; i++) {
    x[i] = rand() / 32768.0;
  }

  /* multiply matrix by vector to get RHS */
  CSR_matrix_vector_mult(A, x, b);

  /* clear initial guess and initialise temporaries */
  for (i = 0; i < s; i++) {
    x[i] = 0.0;

    /* r = b - Ax; since x is 0, r = b */
    r[i] = b[i];

    /* p = r ( = b)*/
    p[i] = b[i];

    omega[i] = 0.0;
  }

  /* As an example, here we initialise the library, and then start measurements. */
  rapl_init();
  rapl_start();
  clock_gettime(CLOCK, &start);

  /* compute initial residual */
  r1 = dotProduct(r, r, s);
  r0 = r1;

  /*======================================================================
   *
   * Actual solver loop
   *
   *======================================================================*/
  k = 0;
  while ((r1 > tol) && (k <= PCG_MAX_ITER)) {
    /* omega = Ap */
    CSR_matrix_vector_mult(A, p, omega);

    /* dot = p . omega */
    dot = dotProduct(p, omega, s);

    alpha = r1 / dot;

    /* x = x + alpha.p */
    vecAxpy(p, x, s, alpha);

    /* r = r - alpha.omega */
    vecAxpy(omega, r, s, -alpha);

    r0 = r1;

    /* r1 = r . r */
    r1 = dotProduct(r, r, s);

    beta = r1 / r0;

    /* p = r + beta.p */
    vecAypx(r, p, s, beta);
    k++;
  }

  clock_gettime(CLOCK, &end);
  rapl_end();
  rapl_deinit();
  /* And then we finish the meausurements and free the library */

  elapsed_time_hr(start, end, "Conjugate gradient solve.");

  /*======================================================================
   *
   * Free memory
   *
   *======================================================================*/
  /* free the vectors */
  free(omega);
  free(p);
  free(r);
  free(b);
  free(x);

  /* free the matrix */
  free(A->colIndex);
  free(A->rowStart);
  free(A->values);
  free(A);
  return 0;
}