示例#1
0
void pbksb(void) {
  register int i,j;
  register double sum;
  int pid;
  double *b;
  int n,p;
  GET_PID(pid);
  b = gm->b;
  n = gm->n;
  p = gm->p;
  double *a_prime;
  a_prime = gm->a_prime;

  //--------------------------------------------------
  // Parallelize the consecutive substract operations
  //--------------------------------------------------
  for (i = n-p+pid; i >= pid; i -= p)
  {
    sum = b[i];
    for (j = n-1; j > i; j--)
    {
      WAITPAUSE(gm->pse[j])
      sum -= a_prime[(n-i) * (n-1-i)/2 + (n-1-j)] * b[j];
    }

    b[i] = sum / a_prime[(n-i) * (n-1-i)/2 + (n-1-i)];
    SETPAUSE(gm->pse[i])
  }

}
示例#2
0
//
//
// Return the array indices of a sub-array that needs sorting. 
//	int PopWork(TaskElement *);
//
//
int PopWork(TaskElement * task){
    int i;

    if (!Sequential) {
		//Tmk_lock_acquire(gMem->TaskStackLock);
		pthread_taskstack_lock(gMem->TaskStackLock);

		while (gMem->TaskStackTop == 0) {		// Check for empty stack!
		    if (++gMem->NumWaiting == Tmk_nprocs) {
				// DONE
				SETPAUSE(pauseFlag);
				//Tmk_lock_release(gMem->TaskStackLock);
				pthread_taskstack_unlock(gMem->TaskStackLock);
				return(DONE);
		    }
		    else {
				// Wait for some work to get pushed on... 
				if (gMem->NumWaiting == 1){
			    	CLEARPAUSE(pauseFlag);
				}
				//Tmk_lock_release(gMem->TaskStackLock);
				pthread_taskstack_unlock(gMem->TaskStackLock);
	
				if (debug){
					fprintf(stderr,"\t%d: PopWork waiting for work.\n",Tmk_proc_id);
				}
				
				WAITPAUSE(pauseFlag);
				//Tmk_lock_acquire(gMem->TaskStackLock);
				pthread_taskstack_lock(gMem->TaskStackLock);

				if (gMem->NumWaiting == Tmk_nprocs) {
					//Tmk_lock_release(gMem->TaskStackLock);
					pthread_taskstack_unlock(gMem->TaskStackLock);
					return(DONE);
				}
				--gMem->NumWaiting;
		    }// end of else
		} // while task-stack empty 
    }
    else // non-sequential
    if (gMem->TaskStackTop == 0) {
    	return(DONE);
    }

    gMem->TaskStackTop--;
    task->left  = gMem->TaskStack[gMem->TaskStackTop].left;
    task->right = gMem->TaskStack[gMem->TaskStackTop].right;

    if (debug) {
    	fprintf(stderr,"\t%d: PopWork - returning <%d,%d>.  Top now %d.\n",
				Tmk_proc_id, task->left, task->right,
		      	gMem->TaskStackTop);
    }
    
    if (!Sequential) {
		//Tmk_lock_release(gMem->TaskStackLock);
		pthread_taskstack_unlock(gMem->TaskStackLock);
    }

    return(0);

}