Esempio n. 1
0
int main(int argc, char** argv) {
  char const *deps[] = { "system" }; 
  hclib::launch(deps, 1, [&]() {
    myNew = new double[(SIZE + 2)];
    myVal = new double[(SIZE + 2)];
    initialOutput = new double[(SIZE + 2)];
    memset(myNew, 0, sizeof(double) * (SIZE + 2));
    memset(myVal, 0, sizeof(double) * (SIZE + 2));
    memset(initialOutput, 0, sizeof(double) * (SIZE + 2));
    initialOutput[SIZE + 1] = 1.0;
    myVal[SIZE + 1] = 1.0;
#ifdef VERIFY
    long start_seq = hclib_current_time_ms();
    runSequential();
    long end_seq = hclib_current_time_ms();
    double dur_seq = ((double)(end_seq-start_seq))/1000;
    printf("Sequential Time = %.3f\n",dur_seq);
#endif
    long start = hclib_current_time_ms();
    runParallel();
    long end = hclib_current_time_ms();
    double dur = ((double)(end-start))/1000;
#ifdef VERIFY
    validateOutput();
#endif
    printf("Time = %.3f\n",dur);
    delete(myNew);
    delete(myVal);
    delete(initialOutput);
  });
}
Esempio n. 2
0
int main(int argc, char **argv) {
  int i;
  struct timeval startTime, endTime;

  if (argc != 3)
    usage(argv[0]);

  // Record start of total time
  gettimeofday(&startTime, NULL);

  // Initialize global variables and data-structures.
  P = atoi(argv[1]);
  initialize(argv[2], &cells, &constraints);
  nodeCount = 0;
  found = 0;

  jobQueues = (job_queue_t*)calloc(sizeof(job_queue_t), P);
  if (!jobQueues)
    unixError("Failed to allocated memory for the job queues");

  for (i = 0; i < P; i++)
    omp_init_lock(&(jobQueues[i].headLock));

  // Add initial job (nothing assigned) to root processor
  jobQueues[0].tail = 1;


  runParallel(P);
  if (!found)
    appError("No solution found");

  // Use final time to calculate total time
  gettimeofday(&endTime, NULL);
  totalTime = TIME_DIFF(endTime, startTime);

  // Print out number of nodes visited and calculated times
  printf("Nodes Visited: %lld\n", nodeCount);
  printf("Computation Time = %.3f millisecs\n", compTime);
  printf("      Total Time = %.3f millisecs\n", totalTime);

  return 0;
}