Beispiel #1
0
void htable_init(htable_ctx_t *ctx) {
	int i;

	// allocate cache-line aligned memory for the chunks array
	int r = posix_memalign((void**)&ctx->chunks, HTABLE_CACHE_LINE_SIZE, 
		HTABLE_MAX_NR_OF_CHUNKS * HTABLE_CHUNK_SIZE * sizeof(bucket_t));

	// allocate handle pointers for chunk retrieval
	ctx->handle = (upc_handle_t*)malloc(2 * HTABLE_MAX_NR_OF_CHUNKS * sizeof(upc_handle_t*));

	// allocate the shared table 
	ctx->table = (shared [HTABLE_BLOCK_SIZE] bucket_t*)
		upc_all_alloc(THREADS, HTABLE_BLOCK_SIZE * sizeof(bucket_t));

	// now allocate the actual handles. We need 2 per chunk..
	for (i = 0; i < 2 * HTABLE_MAX_NR_OF_CHUNKS; i++) {
		ctx->handle[i] = NULL;
	}
}
void setup_limited_directory(int max_dir_size)
{
    s_time  = (shared int *) upc_all_alloc( THREADS, sizeof(int) );
    s_read  = (shared int *) upc_all_alloc( THREADS, sizeof(int) );
    s_write = (shared int *) upc_all_alloc( THREADS, sizeof(int) );
    
    sentinel = (shared strict int *) upc_all_alloc( THREADS, sizeof(int) );
    
    s_directory  = (shared sintpt *) upc_all_alloc( THREADS, sizeof(sintpt) );
    s_directory[MYTHREAD] = (sintpt) upc_alloc(max_dir_size * sizeof(int));
    
    dir_locks = (shared slockpt *) upc_all_alloc(THREADS, sizeof(slockpt));
    dir_locks[MYTHREAD] = upc_global_lock_alloc();
    
    upc_barrier;
}
void ws_init(void *func, size_t input_s, size_t output_s) {
	// store input parameters
	input_size = input_s;
	output_size = output_s;
	handler = func;

	// allocate the shared private deque collectively
	task_size = sizeof(uint64_t) + input_s + output_s;
	block_size = WS_DEQUE_SIZE * task_size;
	
	if (MYTHREAD == 0)
		deque = upc_alloc(block_size * 4);

	// allocate and initialize the 'empty task'
	empty_task = malloc(task_size);
	*(uint64_t*)empty_task = WS_TASK_EMPTY;
	has_last_hint = false;

	// allocate shared transfer cells
	transfer = upc_all_alloc(THREADS, task_size);

	// get local pointers to shared data owned by this thread
	deque_p = upc_cast(WS_DEQUE_ELEM(WS_DEQUE_OFFSET));
	deque_head_p = upc_cast(WS_DEQUE_ELEM(WS_DEQUE_OFFSET));
	transfer_p = upc_cast(WS_TRANS_ELEM(MYTHREAD));
	request_p = upc_cast(&request[MYTHREAD]);
	term_p = upc_cast(&term[MYTHREAD]);

	// assign initial values
	*request_p = 0;
	head = 0;
	tail = 0;

	// initialize victim arrays and semaphores
	init_victim_array();
	init_comp_semaphores();
}
Beispiel #4
0
int main(int argc, char **argv)
{
	int i, j, ntimes, err, flag, strl;
	double stim, read_tim, write_tim;
	double min_read_tim, min_write_tim, read_bw, write_bw;
	 upcio_file_t *fh;
	upc_flag_t sync = 0;
	char *filename;
	
	shared int *buf;
	shared char *gfilename;
	shared int *len;

	ntimes=1;
/* process 0 takes the file name as a command-line argument and 
   broadcasts it to other processes */
	len = (shared int *) upc_all_alloc(1, sizeof(int));
	upc_barrier;
	if (!MYTHREAD) {
		i = 1;
		while ((i < argc) && strcmp("-fname", *argv)) {
			i++;
			argv++;
		}
		if (i >= argc) {
			fprintf(stderr, "\n*#  Usage: perf -fname filename\n\n");
			upc_global_exit(-1);
		}
		argv++;
		strl = strlen(*argv);
		upc_memput(len, &strl, sizeof(int));
	}

	upc_barrier;
	upc_memget(&strl, len, sizeof(int));
	upc_barrier;
	gfilename = (shared char *) upc_all_alloc(1,sizeof(char)*(strl));
	if (!MYTHREAD)
	{
		upc_memput(gfilename, *argv, strl);
		fprintf(stderr, "Access size per process = %d bytes, ntimes = %d\n", SIZE, ntimes);
	}

	upc_barrier;
	filename = (char *) malloc(sizeof(char)*(strl+1));
	upc_memget(filename, gfilename, strl);
	filename[strl] = '\0';

	/* allocate the shared buf on each thread
	   this is for shared w/r with INDIVIDUAL FP */
	buf = (shared int *) upc_global_alloc(1,SIZE);

	upc_barrier;
	min_read_tim=0.0;
	min_write_tim=0.0;

	upc_barrier;

	fh = uopen( filename, 0); 
	for (j=0; j<ntimes; j++) {
		upc_barrier;
		stim = UPC_Wtime();
		upc_all_fseek(fh, MYTHREAD*SIZE + SIZE*THREADS*j, UPC_SEEK_SET);
		err = upc_all_fwrite_shared(fh, buf, BLOCK, SIZE, sizeof(unsigned char), sync);
		if( err == -1 )
		{
			fprintf(stderr, "TH%2d: Error in write\n", MYTHREAD);
			break;
		}

		write_tim = UPC_Wtime() - stim;       
		min_write_tim += write_tim;	
	}

	upc_all_fclose(fh);
	upc_all_fsync(fh);
	min_write_tim /= ntimes;

	upc_barrier;
	fh = uopen( filename, 1); 
	for (j=0; j<ntimes; j++) {
		upc_barrier;
		stim = UPC_Wtime();
		upc_all_fseek(fh, MYTHREAD*SIZE + SIZE*THREADS*j, UPC_SEEK_SET);
		err = upc_all_fread_shared(fh, buf, BLOCK, SIZE, sizeof(unsigned char), sync);
		if( err == -1 )
		{
			fprintf(stderr, "TH%2d: Error in read\n", MYTHREAD);
			break;
		}

		read_tim = UPC_Wtime() - stim;
		min_read_tim += read_tim;
	}

	upc_all_fclose(fh);
	min_read_tim /= ntimes;
	
	upc_barrier;
    
	if (!MYTHREAD) {
		read_bw = (SIZE*THREADS*ntimes)/(min_read_tim*1024.0*1024.0);
		write_bw = (SIZE*THREADS*ntimes)/(min_write_tim*1024.0*1024.0);
		printf("TH: %d - Write bandwidth with a prior file sync = %f Mbytes/sec\n", MYTHREAD, write_bw);
		printf("TH: %d - Read bandwidth with a prior file sync = %f Mbytes/sec\n", MYTHREAD, read_bw);
	}

	upc_barrier;
	/* only thread 0 clean up the single shared buf */
	if(!MYTHREAD) {
		upc_free(buf);
		upc_free(gfilename);
		upc_free(len);
	}

	free(filename);
	return 0;
}
Beispiel #5
0
extern int user_main(
  int argc,
  char ** argv)
#line 14 "pgen.upc"
{
#line 14 "pgen.upc"
  UPCR_BEGIN_FUNCTION();
  register _IEEE64 _bupc_comma;
  register _INT64 _bupc_comma0;
  register _INT32 _bupc_comma1;
  register _UINT64 _bupc_comma2;
  register _IEEE64 _bupc_comma3;
  register _IEEE64 _bupc_comma4;
  register _INT64 _bupc_comma5;
  register _INT64 _bupc_comma7;
  register _INT64 _bupc_comma6;
  register _IEEE64 _bupc_comma8;
  register _IEEE64 _bupc_comma9;
  register _IEEE64 _bupc_comma10;
  _IEEE64 inputTime;
  _IEEE64 constrTime;
  _IEEE64 traversalTime;
  int n_total_kmers;
  int n_kmers_to_process_ideal;
  int start_kmer;
  int end_kmer;
  int n_kmers_to_process;
  int char_start_position;
  int chars_to_read;
  unsigned char * buffer;
  unsigned char * _bupc__casttmp9;
  struct __sFILE * input_file;
  int _bupc__spilleq10;
  unsigned long _bupc__spilleq11;
  struct memory_heap_t private_memory_heap;
  struct hash_table_t * private_hashtable;
  int nints;
  upcr_pshared_ptr_t process_kmer_list_offsets_global;
  int * process_kmer_list_offsets;
  int max_kmers_to_transfer_to_single_process;
  int nchars;
  upcr_pshared_ptr_t kmers_to_transfer_global;
  char * kmers_to_transfer;
  int i;
  int process_owner;
  int _bupc_w2c_i0;
  int n_kmers_char_to_transfer_to_self;
  int j;
  long long _bupc__spilleq12;
  void * _bupc_call5;
  struct __sFILE * _bupc_call6;
  struct hash_table_t * _bupc_call7;
  upcr_shared_ptr_t _bupc_call8;
  upcr_shared_ptr_t _bupc_call9;
  upcr_pshared_ptr_t _bupc_Mstopcvt10;
  upcr_pshared_ptr_t _bupc_Mptra11;
  int * _bupc_Mcvtptr12;
  upcr_pshared_ptr_t _bupc_Mstopcvt13;
  upcr_pshared_ptr_t _bupc_Mptra14;
  char * _bupc_Mcvtptr15;
  upcr_pshared_ptr_t _bupc_Mptra16;
  upcr_pshared_ptr_t _bupc_Mptra17;
  int _bupc_spillld18;
  upcr_pshared_ptr_t _bupc_Mptra19;
  upcr_pshared_ptr_t _bupc_Mptra20;
  upcr_shared_ptr_t _bupc_Mstopcvt21;
  
#line 17 "pgen.upc"
  inputTime = 0.0;
#line 17 "pgen.upc"
  constrTime = 0.0;
#line 17 "pgen.upc"
  traversalTime = 0.0;
#line 20 "pgen.upc"
  upcr_barrier(346153894, 1);
#line 21 "pgen.upc"
  _bupc_comma = gettime();
#line 21 "pgen.upc"
  inputTime = inputTime - _bupc_comma;
#line 24 "pgen.upc"
  _bupc_comma0 = getNumKmersInUFX((const char *) * (argv + 1LL));
#line 24 "pgen.upc"
  n_total_kmers = _bupc_comma0;
#line 25 "pgen.upc"
  n_kmers_to_process_ideal = n_total_kmers / ((int) upcr_threads () );
#line 26 "pgen.upc"
  start_kmer = ((int) upcr_mythread () ) * n_kmers_to_process_ideal;
#line 27 "pgen.upc"
  end_kmer = (((int) upcr_mythread () ) + 1) * n_kmers_to_process_ideal;
#line 28 "pgen.upc"
  if(((int) upcr_mythread () ) == (((int) upcr_threads () ) + -1))
#line 28 "pgen.upc"
  {
#line 28 "pgen.upc"
    end_kmer = n_total_kmers;
  }
#line 29 "pgen.upc"
  n_kmers_to_process = end_kmer - start_kmer;
#line 30 "pgen.upc"
  char_start_position = start_kmer * 23;
#line 31 "pgen.upc"
  chars_to_read = n_kmers_to_process * 23;
#line 32 "pgen.upc"
  _bupc_call5 = malloc((unsigned long)(_UINT64)(chars_to_read));
#line 32 "pgen.upc"
  _bupc__casttmp9 = _bupc_call5;
#line 32 "pgen.upc"
  buffer = _bupc__casttmp9;
#line 34 "pgen.upc"
  printf("Process %d: Reading and creating graph for K-mers %d - %d\n", ((int) upcr_mythread () ), start_kmer, end_kmer);
#line 37 "pgen.upc"
  _bupc_call6 = fopen((const char *) * (argv + 1LL), "r");
#line 37 "pgen.upc"
  input_file = _bupc_call6;
#line 38 "pgen.upc"
  _bupc_comma1 = fseek(input_file, (long) char_start_position, (int) 1);
#line 38 "pgen.upc"
  _bupc__spilleq10 = _bupc_comma1;
#line 38 "pgen.upc"
  if(_bupc__spilleq10 != 0)
#line 38 "pgen.upc"
  {
#line 39 "pgen.upc"
    printf("Error Seeking...");
#line 40 "pgen.upc"
    upcri_do_exit((int) 0);
  }
#line 42 "pgen.upc"
  _bupc_comma2 = fread(buffer, (unsigned long) 1ULL, (unsigned long)(_UINT64)(chars_to_read), input_file);
#line 42 "pgen.upc"
  _bupc__spilleq11 = _bupc_comma2;
#line 42 "pgen.upc"
  if(_bupc__spilleq11 != (_UINT64)(chars_to_read))
#line 42 "pgen.upc"
  {
#line 43 "pgen.upc"
    printf("Error reading...");
#line 44 "pgen.upc"
    upcri_do_exit((int) 0);
  }
#line 46 "pgen.upc"
  fclose(input_file);
#line 47 "pgen.upc"
  upcr_barrier(346153895, 1);
#line 48 "pgen.upc"
  _bupc_comma3 = gettime();
#line 48 "pgen.upc"
  inputTime = inputTime + _bupc_comma3;
#line 51 "pgen.upc"
  _bupc_comma4 = gettime();
#line 51 "pgen.upc"
  constrTime = constrTime - _bupc_comma4;
#line 56 "pgen.upc"
  _bupc_call7 = create_hash_table((long long)(n_kmers_to_process * 2), &private_memory_heap);
#line 56 "pgen.upc"
  private_hashtable = _bupc_call7;
#line 59 "pgen.upc"
  nints = ((int) upcr_threads () );
#line 60 "pgen.upc"
  _bupc_call8 = upc_all_alloc((unsigned long)(_UINT64)(((int) upcr_threads () )), (unsigned long)((_UINT64)(nints) * 4ULL));
#line 60 "pgen.upc"
  _bupc_Mstopcvt10 = UPCR_SHARED_TO_PSHARED(_bupc_call8);
#line 60 "pgen.upc"
  process_kmer_list_offsets_global = _bupc_Mstopcvt10;
#line 61 "pgen.upc"
  _bupc_Mptra11 = UPCR_ADD_PSHARED1(process_kmer_list_offsets_global, 4ULL, ((int) upcr_mythread () ));
#line 61 "pgen.upc"
  _bupc_Mcvtptr12 = (int *) UPCR_PSHARED_TO_LOCAL(_bupc_Mptra11);
#line 61 "pgen.upc"
  process_kmer_list_offsets = _bupc_Mcvtptr12;
#line 62 "pgen.upc"
  memset(process_kmer_list_offsets, (int) 0, (unsigned long)((_UINT64)(((int) upcr_threads () )) * 4ULL));
#line 64 "pgen.upc"
  max_kmers_to_transfer_to_single_process = (n_kmers_to_process_ideal / ((int) upcr_threads () )) * 2;
#line 65 "pgen.upc"
  nchars = (max_kmers_to_transfer_to_single_process * ((int) upcr_threads () )) * 23;
#line 68 "pgen.upc"
  _bupc_call9 = upc_all_alloc((unsigned long)(_UINT64)(((int) upcr_threads () )), (unsigned long)(_UINT64)(nchars));
#line 68 "pgen.upc"
  _bupc_Mstopcvt13 = UPCR_SHARED_TO_PSHARED(_bupc_call9);
#line 68 "pgen.upc"
  kmers_to_transfer_global = _bupc_Mstopcvt13;
#line 70 "pgen.upc"
  _bupc_Mptra14 = UPCR_ADD_PSHARED1(kmers_to_transfer_global, 1ULL, ((int) upcr_mythread () ));
#line 70 "pgen.upc"
  _bupc_Mcvtptr15 = (char *) UPCR_PSHARED_TO_LOCAL(_bupc_Mptra14);
#line 70 "pgen.upc"
  kmers_to_transfer = _bupc_Mcvtptr15;
#line 73 "pgen.upc"
  i = 0;
#line 73 "pgen.upc"
  while(i < (n_kmers_to_process * 23))
#line 73 "pgen.upc"
  {
#line 74 "pgen.upc"
    _bupc_comma5 = hashkmer((long long) ((int) upcr_threads () ), (char *)(buffer + i));
#line 74 "pgen.upc"
    process_owner = _bupc_comma5;
#line 76 "pgen.upc"
    if(process_owner == ((int) upcr_mythread () ))
#line 76 "pgen.upc"
    {
#line 77 "pgen.upc"
      add_kmer(private_hashtable, &private_memory_heap, buffer + i, (char)(char) * ((buffer + (i + 19)) + 1LL), (char)(char) * ((buffer + (i + 19)) + 2LL));
    }
    else
#line 77 "pgen.upc"
    {
#line 83 "pgen.upc"
      memcpy(kmers_to_transfer + (*(process_kmer_list_offsets + process_owner) + ((process_owner * max_kmers_to_transfer_to_single_process) * 23)), buffer + i, (unsigned long) 23ULL);
#line 84 "pgen.upc"
      * (process_kmer_list_offsets + process_owner) = *(process_kmer_list_offsets + process_owner) + 23;
    }
#line 86 "pgen.upc"
    _1 :;
#line 86 "pgen.upc"
    i = i + 23;
  }
#line 89 "pgen.upc"
  upcr_barrier(346153896, 1);
#line 91 "pgen.upc"
  _bupc_w2c_i0 = 0;
#line 91 "pgen.upc"
  while(_bupc_w2c_i0 < ((int) upcr_threads () ))
#line 91 "pgen.upc"
  {
#line 92 "pgen.upc"
    if(_bupc_w2c_i0 != ((int) upcr_mythread () ))
#line 92 "pgen.upc"
    {
#line 93 "pgen.upc"
      _bupc_Mptra16 = UPCR_ADD_PSHARED1(process_kmer_list_offsets_global, 4ULL, _bupc_w2c_i0);
#line 93 "pgen.upc"
      _bupc_Mptra17 = UPCR_ADD_PSHAREDI(_bupc_Mptra16, 4ULL, ((int) upcr_mythread () ));
#line 93 "pgen.upc"
      UPCR_GET_PSHARED(&_bupc_spillld18, _bupc_Mptra17, 0, 4);
#line 93 "pgen.upc"
      n_kmers_char_to_transfer_to_self = _bupc_spillld18;
#line 96 "pgen.upc"
      _bupc_Mptra19 = UPCR_ADD_PSHARED1(kmers_to_transfer_global, 1ULL, _bupc_w2c_i0);
#line 96 "pgen.upc"
      _bupc_Mptra20 = UPCR_ADD_PSHAREDI(_bupc_Mptra19, 1ULL, (((int) upcr_mythread () ) * max_kmers_to_transfer_to_single_process) * 23);
#line 96 "pgen.upc"
      _bupc_Mstopcvt21 = UPCR_PSHARED_TO_SHARED(_bupc_Mptra20);
#line 96 "pgen.upc"
      upc_memget(buffer, _bupc_Mstopcvt21, (unsigned long)(_UINT64)(n_kmers_char_to_transfer_to_self));
#line 98 "pgen.upc"
      j = 0;
#line 98 "pgen.upc"
      while(j < n_kmers_char_to_transfer_to_self)
#line 98 "pgen.upc"
      {
#line 99 "pgen.upc"
        _bupc_comma7 = hashkmer((long long) ((int) upcr_threads () ), (char *)(buffer + j));
#line 99 "pgen.upc"
        _bupc__spilleq12 = _bupc_comma7;
#line 99 "pgen.upc"
        if(_bupc__spilleq12 != (_INT64)(((int) upcr_mythread () )))
#line 99 "pgen.upc"
        {
#line 99 "pgen.upc"
          _bupc_comma6 = hashkmer((long long) ((int) upcr_threads () ), (char *)(buffer + j));
#line 99 "pgen.upc"
          printf("%d %d\n", ((int) upcr_mythread () ), _bupc_comma6);
        }
#line 100 "pgen.upc"
        add_kmer(private_hashtable, &private_memory_heap, buffer + j, (char)(char) * ((buffer + (j + 19)) + 1LL), (char)(char) * ((buffer + (j + 19)) + 2LL));
#line 101 "pgen.upc"
        _3 :;
#line 101 "pgen.upc"
        j = j + 23;
      }
    }
#line 103 "pgen.upc"
    _2 :;
#line 103 "pgen.upc"
    _bupc_w2c_i0 = _bupc_w2c_i0 + 1;
  }
#line 105 "pgen.upc"
  upcr_barrier(346153897, 1);
#line 106 "pgen.upc"
  _bupc_comma8 = gettime();
#line 106 "pgen.upc"
  constrTime = constrTime + _bupc_comma8;
#line 109 "pgen.upc"
  _bupc_comma9 = gettime();
#line 109 "pgen.upc"
  traversalTime = traversalTime - _bupc_comma9;
#line 114 "pgen.upc"
  upcr_barrier(346153898, 1);
#line 115 "pgen.upc"
  _bupc_comma10 = gettime();
#line 115 "pgen.upc"
  traversalTime = traversalTime + _bupc_comma10;
#line 119 "pgen.upc"
  if(((int) upcr_mythread () ) == 0)
#line 119 "pgen.upc"
  {
#line 120 "pgen.upc"
    printf("%s: Input set: %s\n", *argv, *(argv + 1LL));
#line 121 "pgen.upc"
    printf("Number of UPC threads: %d\n", ((int) upcr_threads () ));
#line 122 "pgen.upc"
    printf("Input reading time: %f seconds\n", inputTime);
#line 123 "pgen.upc"
    printf("Graph construction time: %f seconds\n", constrTime);
#line 124 "pgen.upc"
    printf("Graph traversal time: %f seconds\n", traversalTime);
  }
#line 126 "pgen.upc"
  UPCR_EXIT_FUNCTION();
#line 126 "pgen.upc"
  return 0;
} /* user_main */
shared int64_t *pred2= (shared int64_t*)
                       upc_all_alloc( nlocalverts * sizeof( int64_t));
shared int64)
shared int64_t *local_vertices= (shared int64_t*)
                                upc_all_alloc(nlocalverts * sizeof(int64_t));

upc_all_reduceI( (shared int64_t*) pred2,
                 (shared int64_t*) (local_vertices + v_local),
                 (upc_op_t) UPC_MIN,
                 (int64_t) (nlocalverts * THREADS),
                 (int64_t) nlocalverts, NULL,
                 (upc_flag_t) sync_mode);

upc_free(pred2);
upc_free(local_vertices);