Beispiel #1
0
int plarrv
(proc_t *procinfo, in_t *Dstruct, val_t *Wstruct,
 vec_t *Zstruct, tol_t *tolstruct, int *nzp, int *myfirstp)
{
  int     n  = Dstruct->n;
  double  *W = Wstruct->W;

  /* Allocate work space and copy eigenvalues */
  double *Wshifted = (double*)malloc(n*sizeof(double));
  assert(Wshifted != NULL);

  memcpy(Wshifted, W, n*sizeof(double));
  Wstruct->Wshifted = Wshifted;

  /* Assign eigenvectors to processes */
  assign_to_proc(procinfo, Dstruct, Wstruct, Zstruct, nzp, myfirstp);

  /* Create work queue Q, counter, threads to empty Q */
  workQ_t *workQ = create_workQ();
  counter_t *num_left = PMR_create_counter(*nzp);

  /* Initialize work queue of process */
  int info = init_workQ(procinfo, Dstruct, Wstruct, nzp, workQ);
  assert(info == 0);

  /* Empty the work queue */
  auxarg3_t *auxarg = 
    create_auxarg3(0, procinfo, Wstruct, Zstruct, tolstruct, workQ, num_left);
  void *status = empty_workQ((void*)auxarg);
  assert(status == NULL);

  /* Clean up */
  free(Wshifted);
  destroy_workQ(workQ);
  PMR_destroy_counter(num_left);

  return 0;
}
Beispiel #2
0
int plarrv
(proc_t *procinfo, in_t *Dstruct, val_t *Wstruct,
 vec_t *Zstruct, tol_t *tolstruct, int *nzp, int *myfirstp)
{
  int     nthreads = procinfo->nthreads;
  int     n        = Dstruct->n;
  double  *W       = Wstruct->W;

  /* Allocate work space and copy eigenvalues */
  double *Wshifted = (double*)malloc(n*sizeof(double));
  assert(Wshifted != NULL);

  memcpy(Wshifted, W, n*sizeof(double));
  Wstruct->Wshifted = Wshifted;

  pthread_t *threads = (pthread_t*)malloc(nthreads*sizeof(pthread_t));
  assert(threads != NULL);

  /* Assign eigenvectors to processes */
  assign_to_proc(procinfo, Dstruct, Wstruct, Zstruct, nzp, myfirstp);

  /* Create work queue Q, counter, threads to empty Q */
  workQ_t *workQ = create_workQ();
  counter_t *num_left = PMR_create_counter(*nzp);

  threads[0] = pthread_self();
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); 

  int i;
  for (i=1; i<nthreads; i++) {
    auxarg3_t *auxarg = 
      create_auxarg3(i, procinfo, Wstruct, Zstruct, tolstruct, workQ, num_left);
    int info = pthread_create(&threads[i], &attr, empty_workQ, (void*)auxarg);
    assert(info == 0);
  }

  /* Initialize work queue of process */
  int info = init_workQ(procinfo, Dstruct, Wstruct, nzp, workQ);
  assert(info == 0);

  /* Empty the work queue */
  auxarg3_t *auxarg = 
    create_auxarg3(0, procinfo, Wstruct, Zstruct, tolstruct, workQ, num_left);
  void *status = empty_workQ((void*)auxarg);
  assert(status == NULL);

  /* Join all the worker thread */
  for (i=1; i<nthreads; i++) {
    info = pthread_join(threads[i], &status);
    assert(info == 0 && status == NULL);
  }

  /* Clean up */
  free(Wshifted);
  free(threads);
  pthread_attr_destroy(&attr);
  destroy_workQ(workQ);
  PMR_destroy_counter(num_left);

  return 0;
}
Beispiel #3
0
int PMR_process_r_task(refine_t *rf, int tid, val_t *Wstruct, 
		       tol_t *tolstruct, double *work, int *iwork)
{
  int    rf_begin  = rf->begin;
  double *D        = rf->D;
  double *DLL      = rf->DLL;
  int    p         = rf->p;
  int    q         = rf->q;
  int    bl_size   = rf->bl_size;
  double bl_spdiam = rf->bl_spdiam;
  subtasks_t  *sts = rf->sts;

  double *Wshifted = Wstruct->Wshifted;
  double *Werr     = Wstruct->Werr;
  double *Wgap     = Wstruct->Wgap;
  int    *Windex   = Wstruct->Windex;
  double rtol1     = tolstruct->rtol1;
  double rtol2     = tolstruct->rtol2;
  double pivmin    = tolstruct->pivmin;

  /* Others */
  int info, offset, taskcount, rf_end, i;
  double sigma;
  double *restrict L;
  double *restrict W;

  offset = Windex[rf_begin] - 1;

  /* Bisection to refine the eigenvalues */
  dlarrb_(&bl_size, D, DLL, &p, &q, &rtol1, &rtol2,
	  &offset, &Wshifted[rf_begin], &Wgap[rf_begin], &Werr[rf_begin],
	  work, iwork, &pivmin, &bl_spdiam, &bl_size, &info);
  assert(info == 0);

  taskcount = PMR_decrement_counter(sts->counter, 1);
  
  if (taskcount == 0) {
    L = sts->RRR->L;
    W = Wstruct->W;
    rf_begin = sts->cl->begin;
    for (i=0; i<sts->num_tasks; i++) {
      rf_end = rf_begin + sts->chunk - 1;
      
      Wgap[rf_end] = Wshifted[rf_end + 1] - Werr[rf_end + 1]
	- Wshifted[rf_end] - Werr[rf_end];
      
      rf_begin = rf_end + 1;
    }
    sigma = L[bl_size-1];
    
    /* refined eigenvalues with all shifts applied in W */
    for ( i=sts->cl->begin; i<=sts->cl->end; i++ ) {
      W[i] = Wshifted[i] + sigma;
    }
    
    /* create subtasks */
    info = PMR_create_subtasks(sts->cl, tid, sts->nthreads, sts->num_left, 
			       sts->workQ, sts->RRR, Wstruct, 
			       sts->Zstruct, tolstruct, work, iwork);
    assert(info == 0);

    PMR_destroy_counter(sts->counter); 
    free(sts);
  }
  
  free(rf);

  return(0);
}
Beispiel #4
0
int mrrr_vec(int nthreads, in_t *Dstruct, val_t *Wstruct, 
	     vec_t *Zstruct, tol_t *tolstruct)
{
  int            n = Dstruct->n;
  int            m = Wstruct->m;
  double         *Wshifted;
  int            i, info;
  pthread_t      *threads;
  pthread_attr_t attr;
  void           *status;
  aux3_t         *arg;
  workQ_t        *workQ;
  counter_t      *num_left;

  Wshifted = (double *) malloc( n * sizeof(double) );
  assert(Wshifted != NULL);

  Wstruct->Wshifted = Wshifted;

  threads = (pthread_t *) malloc(nthreads * sizeof(pthread_t));
  assert(threads != NULL);

  /*  Initialize index vector for eigenvectors */
  init_zindex(Dstruct, Wstruct, Zstruct);

  /* Create work queue, counter, and threads to empty work queue */
  workQ      = create_workQ( );
  num_left   = PMR_create_counter(m);

  threads[0] = pthread_self();
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);

  /* Create nthreads-1 additional threads */
  for (i=1; i<nthreads; i++) {

    arg = create_aux3(i, nthreads, num_left, workQ, Dstruct, 
		      Wstruct, Zstruct, tolstruct);

    info = pthread_create(&threads[i], &attr, empty_workQ, 
			  (void *) arg);
    assert(info == 0);
  }
  
  /* Initialize the work queue with tasks */
  init_workQ(workQ, Dstruct, Wstruct);

  arg = create_aux3(0, nthreads, num_left, workQ, Dstruct, 
		    Wstruct, Zstruct, tolstruct);

  status = empty_workQ((void *) arg);
  assert(status == NULL);
 
  /* Join all the worker thread */
  for (i=1; i<nthreads; i++) {
    info = pthread_join(threads[i], &status);
    assert(info == 0 && status == NULL);
  }

  /* Clean up and return */
  free(Wshifted);
  free(threads);
  pthread_attr_destroy(&attr);
  destroy_workQ(workQ);
  PMR_destroy_counter(num_left);
  
  return(0);
}