Esempio n. 1
0
int main(int argc , char* argv[])
{
    svar.ParseMain(argc,argv);
    mode=svar.GetInt("Mode",0);
    if(mode<0||mode>=9) return -1;
    circulate=svar.GetInt("Circle",circulate);
    THREAD_COUNT=svar.GetInt("Count",THREAD_COUNT);
    usec=svar.GetInt("Delay",usec);
    modeStr=modes[mode];

    std::vector<Thread>  thread_array(THREAD_COUNT);
    boost::progress_timer t;
    for(int i=0;i<10;i++)
        queue.write(i);

    std::cout<<"-----------thread create-----------"<<std::endl;

    for(int i=0;i<THREAD_COUNT;++i)
    {
        thread_array[i].reset(new boost::thread(testdata));
    }

    while(1)
    {
        if(count1>=THREAD_COUNT)
            return 0;
    }
}
Esempio n. 2
0
void amuxCRSParallelPThreads (double a,
	unsigned n, unsigned const * const iA, unsigned const * const jA,
	double const * const A, double const * const x, double* y,
	unsigned num_of_pthreads)
{
#ifdef HAVE_PTHREADS
	// fill thread data objects
	MatMultThreadParam** thread_param_array (new MatMultThreadParam*[num_of_pthreads]);
	double step_size ((double)(n)/(double)(num_of_pthreads));
	for (unsigned k(0); k<num_of_pthreads; k++) {
		const unsigned beg (static_cast<unsigned>(k*step_size));
		const unsigned end (static_cast<unsigned>((k+1)*step_size));
		thread_param_array[k] = new MatMultThreadParam (a, beg, end, iA, jA, A, x, y);
	}

	// allocate thread_array and return value array
	pthread_t *thread_array (new pthread_t[num_of_pthreads]);
	int *ret_vals (new int[num_of_pthreads]);

	// create threads
	for (unsigned k(0); k<num_of_pthreads; k++) {
		ret_vals[k] = pthread_create( &(thread_array[k]), NULL, amuxCRSpthread, thread_param_array[k]);
	}

	// join threads
	for (unsigned k(0); k<num_of_pthreads; k++) {
		pthread_join (thread_array[k], NULL);
	}

	delete [] ret_vals;
	for (unsigned k(0); k<num_of_pthreads; k++)
		delete thread_param_array[k];
	delete [] thread_param_array;
	delete [] thread_array;
#else
	(void)num_of_pthreads;
	amuxCRS (a, n, iA, jA, A, x, y);
#endif
}
Esempio n. 3
0
void amuxCRSParallelPThreads (double a,
	unsigned n, unsigned const * const iA, unsigned const * const jA,
	double const * const A, double const * const x, double* y,
	unsigned num_of_pthreads, unsigned const*const workload_intervals)
{
    (void) n;   // Unused if HAVE_PTHREADS is not defined.

#ifdef HAVE_PTHREADS
	// fill thread data objects
	MatMultThreadParam** thread_param_array (new MatMultThreadParam*[num_of_pthreads]);
	for (unsigned k(0); k<num_of_pthreads; k++) {
		thread_param_array[k] = new MatMultThreadParam (a, workload_intervals[k], workload_intervals[k+1], iA, jA, A, x, y);
	}

	// allocate thread_array and return value array
	pthread_t *thread_array (new pthread_t[num_of_pthreads]);
	int *ret_vals (new int[num_of_pthreads]);

	// create threads
	for (unsigned k(0); k<num_of_pthreads; k++) {
		ret_vals[k] = pthread_create( &(thread_array[k]), NULL, amuxCRSpthread, thread_param_array[k]);
	}

	// join threads
	for (unsigned k(0); k<num_of_pthreads; k++) {
		pthread_join (thread_array[k], NULL);
	}

	delete [] ret_vals;
	for (unsigned k(0); k<num_of_pthreads; k++)
		delete thread_param_array[k];
	delete [] thread_param_array;
	delete [] thread_array;
#else
	(void)num_of_pthreads;
	amuxCRS (a, n, iA, jA, A, x, y);
#endif
}
  BASKER_INLINE
  int Basker<Int,Entry,Exe_Space>::nfactor_domain_error
  (
   INT_1DARRAY threads_start
   )
  {
    Int nthread_remalloc = 0;
    for(Int ti = 0; ti < num_threads; ti++)
      {

	//Note: jdb we can make this into a switch
	if(thread_array(ti).error_type ==
	   BASKER_ERROR_NOERROR)
	  {
	    threads_start(ti) = BASKER_MAX_IDX;
	    continue;
	  }//end if NOERROR

	if(thread_array(ti).error_type ==
	   BASKER_ERROR_SINGULAR)
	  {
	    printf("ERROR THREAD: %d DOMBLK SINGULAR: %d\n",
		   ti,
		   thread_array(ti).error_blk);
	    return BASKER_ERROR;
	  }//end if SINGULAR
	
	if(thread_array(ti).error_type ==
	   BASKER_ERROR_NOMALLOC)
	  {
	    printf("ERROR THREADS: %d DOMBLK NOMALLOC: %d\n",
		   ti,
		   thread_array(ti).error_blk);
	    return BASKER_ERROR;
	  }//end if NOMALLOC
	
	if(thread_array(ti).error_type ==
	   BASKER_ERROR_REMALLOC)
	  {

	    BASKER_ASSERT(thread_array(ti).error_blk > 0,
			  "nfactor_dom_error error_blk");

	    printf("ERROR THREADS: %d DOMBLK MALLOC: %d \n",
		   ti,
		   thread_array(ti).error_blk);
	    

	    //Resize L
	    BASKER_MATRIX &L = LL(thread_array(ti).error_blk)(0);
	    REALLOC_INT_1DARRAY(L.row_idx,
			       L.nnz,
			       thread_array(ti).error_info);
	    REALLOC_ENTRY_1DARRAY(L.val,
				 L.nnz,
				 thread_array(ti).error_info);
	    L.nnz = thread_array(ti).error_info;

	    //clean up workspace
	    if(L.w_fill == BASKER_TRUE)
	      {
		//Clear workspace
		for(Int i = 0; i < L.iws_size*L.iws_mult; ++i)
		  {
		    L.iws(i) = (Int) 0;
		  }
		for(Int i = 0; i < L.ews_size*L.ews_mult; ++i)
		  {
		    L.ews(i) = (Entry) 0;
		  }
		//Clear perm
		for(Int i = L.srow; i < L.srow+L.nrow; ++i)
		  {
		    gperm(i) = BASKER_MAX_IDX;
		  }
	      }
	    
	    //Resize U
	    BASKER_MATRIX &U = LU(thread_array(ti).error_blk)(0);
	    REALLOC_INT_1DARRAY(U.row_idx,
			       U.nnz,
			       thread_array(ti).error_info);
	    REALLOC_ENTRY_1DARRAY(U.val,
				 U.nnz,
				 thread_array(ti).error_info);
	    U.nnz = thread_array(ti).error_info;
	    
	    threads_start(ti) = thread_array(ti).error_blk;
	

	    //Reset 
	    thread_array(ti).error_type = BASKER_ERROR_NOERROR;
	    thread_array(ti).error_blk  = BASKER_MAX_IDX;
	    thread_array(ti).error_info = BASKER_MAX_IDX;

	    nthread_remalloc++;
    
	  }//if REMALLOC

      }//for all threads
    
    if(nthread_remalloc == 0)
      {
	return BASKER_SUCCESS;
      }
    else
      {
	return nthread_remalloc;
      }

    //Should never be here
    BASKER_ASSERT(0==1, "nfactor_diag_error, should never");
    return BASKER_SUCCESS;
  }//end nfactor_domain_error
  BASKER_INLINE
  int Basker<Int,Entry,Exe_Space>::nfactor_diag_error
  (
   INT_1DARRAY threads_start
   )
  {
    Int nthread_remalloc = 0;
    for(Int ti = 0; ti < num_threads; ti++)
      {

	//Note: jdb we can make this into a switch
	if(thread_array(ti).error_type ==
	   BASKER_ERROR_NOERROR)
	  {
	    threads_start(ti) = BASKER_MAX_IDX;
	    continue;
	  }//end if NOERROR

	if(thread_array(ti).error_type ==
	   BASKER_ERROR_SINGULAR)
	  {
	    printf("ERROR THREAD: %d DIAGBLK SINGULAR: %d\n",
		   ti,
		   thread_array(ti).error_blk);
	    return BASKER_ERROR;
	  }//end if SINGULAR
	
	if(thread_array(ti).error_type ==
	   BASKER_ERROR_NOMALLOC)
	  {
	    printf("ERROR THREADS: %d DIAGBLK NOMALLOC: %d\n",
		   ti,
		   thread_array(ti).error_blk);
	    return BASKER_ERROR;
	  }//end if NOMALLOC
	
	if(thread_array(ti).error_type ==
	   BASKER_ERROR_REMALLOC)
	  {

	    BASKER_ASSERT(thread_array(ti).error_blk > 0,
			  "nfactor_diag_error error_blk");

	    printf("ERROR THREADS: %d DIAGBLK MALLOC: %d \n",
		   ti,
		   thread_array(ti).error_blk);
	    
	    	    //Clean the workspace
	    printf("test: %d %d \n",
		   thread_array(ti).iws_size*thread_array(ti).iws_mult,
		   thread_array(ti).ews_size*thread_array(ti).ews_mult);

	    for(Int i = 0; 
		i < thread_array(ti).iws_size*thread_array(ti).iws_mult;
		i++)
	      {
		thread_array(ti).iws(i) = (Int) 0;
	      }
	    for(Int i = 0;
		i < thread_array(ti).ews_size*thread_array(ti).ews_mult;
		i++)
	      {
		thread_array(ti).ews(i) = (Entry) 0;
	      }

	   

	    //Resize L
	    BASKER_MATRIX &L = LBTF(thread_array(ti).error_blk);
	    REALLOC_INT_1DARRAY(L.row_idx,
			       L.nnz,
			       thread_array(ti).error_info);
	    REALLOC_ENTRY_1DARRAY(L.val,
				 L.nnz,
				 thread_array(ti).error_info);
	    L.nnz = thread_array(ti).error_info;
	    for(Int i = 0; i < L.ncol; i++)
	      {
		L.col_ptr(i) = 0;
	      }

	    for(Int i = L.srow; i < (L.srow+L.nrow); i++)
	      {
		gperm(i) = BASKER_MAX_IDX;
	      }

	    //Resize U
	    BASKER_MATRIX &U = UBTF(thread_array(ti).error_blk);
	    REALLOC_INT_1DARRAY(U.row_idx,
			       U.nnz,
			       thread_array(ti).error_info);
	    REALLOC_ENTRY_1DARRAY(U.val,
				 U.nnz,
				 thread_array(ti).error_info);
	    U.nnz = thread_array(ti).error_info;
	    for(Int i = 0; i < U.ncol; i++)
	      {
		U.col_ptr(i) = 0;
	      }

	    
	    printf("Setting thread start(%d) %d \n",
		   ti, thread_array(ti).error_blk);

	    threads_start(ti) = thread_array(ti).error_blk;
	

	    //Reset 
	    thread_array(ti).error_type = BASKER_ERROR_NOERROR;
	    thread_array(ti).error_blk  = BASKER_MAX_IDX;
	    thread_array(ti).error_info = BASKER_MAX_IDX;

	    nthread_remalloc++;
    
	  }//if REMALLOC

      }//for all threads
    
    if(nthread_remalloc == 0)
      {
	return BASKER_SUCCESS;
      }
    else
      {
	return nthread_remalloc;
      }

    //Should never be here
    BASKER_ASSERT(0==1, "nfactor_diag_error, should never");
    return BASKER_SUCCESS;
  }//end nfactor_diag_error