static void flush(ID3ASFilterContext *context) 
{
  codec_t *this = context->priv_data;

  for (int i = 0; i < context->num_downstream_filters; i++) {
    
    frame_entry_t *frame_entry = (frame_entry_t *) malloc(sizeof(frame_entry_t));
    frame_entry->exit_thread = 1;
    
    ADD_TO_QUEUE(context, this->threads[i].inbound_frame_queue, frame_entry);
  }
  
  for (int i = 0; i < context->num_downstream_filters; i++) {
    pthread_join(this->threads[i].thread, NULL);
  }
}
static void process(ID3ASFilterContext *context, AVFrame *frame, AVRational timebase)
{
  codec_t *this = context->priv_data;
  
  for (int i = 0; i < context->num_downstream_filters; i++) {
    
    frame_entry_t *frame_entry = (frame_entry_t *) malloc(sizeof(frame_entry_t));
    frame_entry->timebase = timebase;
    frame_entry->frame = av_frame_clone(frame);
    frame_entry->exit_thread = 0;
    
    ADD_TO_QUEUE(context, this->threads[i].inbound_frame_queue, frame_entry);
  }
  
  if (sync_mode) {
    for (int i = 0; i < context->num_downstream_filters; i++) {
      pthread_cond_wait(&this->threads[i].complete, &this->threads[i].complete_mutex);
    }
  }
}
Example #3
0
// Sets up and runs the parallel kenken solver
void runParallel(unsigned P) {
  int i, pid;
  long long myNodeCount;
  job_t* myJob;
  cell_t* myCells;
  constraint_t* myConstraints;
  struct timeval startCompTime, endCompTime;

  // Begin parallel
  omp_set_num_threads(P);

  // Run algorithm
#pragma omp parallel default(shared) private(i, pid, myNodeCount, myJob, \
                                             myCells, myConstraints)
{
  // Initialize local variables and data-structures
  pid = omp_get_thread_num();
  myNodeCount = 0;

  myConstraints = (constraint_t*)calloc(sizeof(constraint_t), numConstraints);
  if (!myConstraints)
    unixError("Failed to allocate memory for myConstraints");

  myCells = (cell_t*)calloc(sizeof(cell_t), totalNumCells);
  if (!myCells)
    unixError("Failed to allocate memory for myCells");

  myJob = (job_t*)malloc(sizeof(job_t));
  if (!myJob)
    unixError("Failed to allocate memory for myJob");

  // Record start of computation time
  #pragma omp single
    gettimeofday(&startCompTime, NULL);

  // Get and complete new job until none left, or solution found
  while (getNextJob(pid, myJob)) {
    memcpy(myConstraints, constraints, numConstraints * sizeof(constraint_t));
    memcpy(myCells, cells, totalNumCells * sizeof(cell_t));

    for (i = 0; i < myJob->length; i++)
      applyValue(myCells, myConstraints, myJob->assignments[i].cellIndex,
                 myJob->assignments[i].value);

    if (ADD_TO_QUEUE(&(jobQueues[pid]), myJob)) {
      myNodeCount++;
      // Guarenteed to succeed given ADD_TO_QUEUE(...) returned true
      addToQueue(myJob->length, myCells, myConstraints, &(jobQueues[pid]),
                 myJob->assignments, AVAILABLE(&jobQueues[pid]));
    }
    else
      solve(myJob->length, myCells, myConstraints, &myNodeCount);
  }

  #pragma omp critical
    nodeCount += myNodeCount;
}

  // Calculate computation time
  gettimeofday(&endCompTime, NULL);
  compTime = TIME_DIFF(endCompTime, startCompTime);
}