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 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);
}