shared void* shr_unlink_and_free(shr_dlist l) { shared void *temp; if (l == NULL) return NULL; temp = l -> element; //printf("unlink_and_free(0x%0x-%d): Called by PE %d, work=0x%x-%d\n", upc_addrfield(l), upc_threadof(l), MYTHREAD, // upc_addrfield(temp), upc_threadof(temp)); //fflush(NULL); l -> next -> prev = l -> prev; l -> prev -> next = l -> next; upc_free(l); return temp; }
void htable_free(htable_ctx_t *ctx) { uint64_t i; // make sure that all async operations on ctx->table have been completed.. for (i = 0; i < 2 * HTABLE_MAX_NR_OF_CHUNKS; i++) { if (ctx->handle[i] != NULL) { upc_sync(ctx->handle[i]); } } upc_free(ctx->table); free(ctx->handle); free(ctx->chunks); }
void cleanup_limited_directory() { upc_lock_free(dir_locks[MYTHREAD]); upc_free(s_directory[MYTHREAD]); upc_barrier; if(MYTHREAD == 0) upc_free(dir_locks); if(MYTHREAD == 0) upc_free(s_directory); if(MYTHREAD == 0) upc_free((shared int *) sentinel); if(MYTHREAD == 0) upc_free(s_write); if(MYTHREAD == 0) upc_free(s_read); if(MYTHREAD == 0) upc_free(s_time); }
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; }