void* receive_wire(const char* channel) { Handle* handle = malloc(sizeof(Handle)); handle->state.fd = hs_open(channel); setupThread(handle); return handle; }
void* logw_wire(const char* file) { Handle* handle = malloc(sizeof(Handle)); handle->state.fd = hs_open(file); setupThread(handle); return handle; }
static void cpu_pre_run(void) { int cpunum; logerror("Machine reset\n"); begin_resource_tracking(); /* read hi scores information from hiscore.dat */ hs_open(Machine->gamedrv->name); hs_init(); /* initialize the various timers (suspends all CPUs at startup) */ cpu_inittimers(); watchdog_counter = -1; /* reset sound chips */ sound_reset(); /* first pass over CPUs */ for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++) { /* enable all CPUs (except for audio CPUs if the sound is off) */ if (!(Machine->drv->cpu[cpunum].cpu_flags & CPU_AUDIO_CPU) || Machine->sample_rate != 0) cpunum_resume(cpunum, SUSPEND_ANY_REASON); else cpunum_suspend(cpunum, SUSPEND_REASON_DISABLE, 1); /* reset the interrupt state */ cpuint_reset_cpu(cpunum); /* reset the total number of cycles */ cpu[cpunum].totalcycles = 0; cpu[cpunum].localtime = 0; } vblank = 0; /* do this AFTER the above so machine_init() can use cpu_halt() to hold the */ /* execution of some CPUs, or disable interrupts */ if (Machine->drv->machine_init) (*Machine->drv->machine_init)(); /* now reset each CPU */ for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++) cpunum_reset(cpunum, Machine->drv->cpu[cpunum].reset_param, cpu_irq_callbacks[cpunum]); /* reset the globals */ cpu_vblankreset(); current_frame = 0; state_save_dump_registry(); }
void* logw_wire(logw_Callback* callback, const char* file) { DEBUGOUT("logw_wire(%p, %s)", callback, file); Handle* handle = malloc(sizeof(Handle)); handle->callback = callback; handle->shared.fd = hs_open(file); handle->shared.buf = NULL; handle->shared.len = 0; setupThread(handle); DEBUGOUT("logw_wire(...) -> %p", handle); return handle; }
/* run simulation */ int run(void) { gmx_mtop_t *mtop; int i, ndata, nat, rescnt = 0; char fxtc[FILENAME_MAX] = ""; char *ftop; matrix box; rvec *xref = NULL, *xrefbb = NULL; zedata_t *ze = NULL; trj_t *trj = NULL; double dt, bref = 1.0/(BOLTZ*Tref), wtot = 0.0; hist_t *hsrms = NULL; bb_t *bb = NULL; FILE *fplog = NULL; memset(box, 0, sizeof(box)); /* read topology and the reference structure */ die_if ((ftop = nfexists(fntop, 7)) == NULL, "no topology file %s\n", fntop); mtop = read_tpx_conf(ftop, &xref, box, &nat, &dt); printf("using the structure in %s as the reference\n", ftop); bb = init_index(&rescnt, mtop); /* get indices for backbone dihedrals */ xnew(xrefbb, rescnt * 3); xgetbb(xrefbb, xref, bb, rescnt); hsrms = hs_open(1, 0.0, xmax, xdel); if (fnlog) { xfopen(fplog, fnlog, "w", exit(1)); } if (fndist2 != NULL) { /* if there's a second database, combine it with the first database */ die_if (0 != hs_load(hsrms, fndist, HIST_VERBOSE), "cannot load master %s\n", fndist); die_if (0 != hs_load(hsrms, fndist2, HIST_VERBOSE|HIST_ADDITION), "cannot add the second %s\n", fndist2); } else { /* if there's no second database, we accumulate trajectories */ /* 1. initialize multiple histogram weights for tempering */ if (!ctmd) { if ((ze = ze_load(fnze, 10)) == NULL) { fprintf(stderr, "cannot load %s\n", fnze); return -1; } /* we first load TRACE, compute weight of each frame */ if ((trj = trj_loadseq(fntr, &ndata, dt, tequil, ze, bref, delbet)) == NULL) { fprintf(stderr, "failed to load trace\n"); return -1; } } else { /* for regular MD, set ndata to a large number */ ndata = 10000000; } /* 2. we now successively load xtc from each data dir, * try to match the TRACE frames */ if (!ctmd) trj->pos = 0; for (i = 1; i <= ndata; i++) { sprintf(fxtc, "data%d/%s", i, fnxtc); if (!fexists(fxtc)) { /* test if the file exists */ die_if(!ctmd, "cannot read %s\n", fnxtc); break; } if (0 != dotrj(hsrms, bb, rescnt, fplog, trj, fxtc, xrefbb, nat, box, &wtot)) { fprintf(stderr, "error doing %s\n", fnxtc); return -1; } } } hs_save(hsrms, fndist, HIST_ADDAHALF|HIST_VERBOSE); hs_close(hsrms); sfree(mtop); if (!ctmd) { if (trj) trj_free(trj); if (ze) ze_free(ze); } free(xrefbb); return 0; }
HStore* hs_open(char *path, int height, time_t before, int scan_threads) { if (NULL == path) return NULL; if (height < 0 || height > 3) { fprintf(stderr, "invalid db height: %d\n", height); return NULL; } if (before != 0){ if (before<0) { fprintf(stderr, "invalid time:%ld\n", before); return NULL; }else{ fprintf(stderr, "serve data modified before %s\n", ctime(&before)); } } char *paths[20], *rpath = path; int npath = 0; while ((paths[npath] = strsep(&rpath, ",:;")) != NULL) { if (npath >= MAX_PATHS) return NULL; path = paths[npath]; if (0 != access(path, F_OK) && 0 != mkdir(path, 0755)){ fprintf(stderr, "mkdir %s failed\n", path); return NULL; } if (height > 1){ // try to mkdir HStore *s = hs_open(path, height - 1, 0, 0); if (s == NULL){ return NULL; } hs_close(s); } npath ++; } int i, j, count = 1 << (height * 4); HStore *store = (HStore*) malloc(sizeof(HStore) + sizeof(Bitcask*) * count); if (!store) return NULL; memset(store, 0, sizeof(HStore) + sizeof(Bitcask*) * count); store->height = height; store->count = count; store->before = before; store->scan_threads = scan_threads; store->op_start = 0; store->op_end = 0; store->op_limit = 0; store->mgr = mgr_create((const char**)paths, npath); if (store->mgr == NULL) { free(store); return NULL; } for (i=0; i<NUM_OF_MUTEX; i++) { pthread_mutex_init(&store->locks[i], NULL); } char *buf[20] = {0}; for (i=0;i<npath;i++) { buf[i] = malloc(255); } for (i=0; i<count; i++){ for (j=0; j<npath; j++) { path = paths[j]; switch(height){ case 0: sprintf(buf[j], "%s", path); break; case 1: sprintf(buf[j], "%s/%x", path, i); break; case 2: sprintf(buf[j], "%s/%x/%x", path, i>>4, i & 0xf); break; case 3: sprintf(buf[j], "%s/%x/%x/%x", path, i>>8, (i>>4)&0xf, i&0xf); break; } } Mgr *mgr = mgr_create((const char**)buf, npath); if (mgr == NULL) return NULL; store->bitcasks[i] = bc_open2(mgr, height, i, before); } for (i=0;i<npath;i++) { free(buf[i]); } if (store->scan_threads > 1 && count > 1) { parallelize(store, bc_scan); }else{ for (i=0; i<count; i++) { bc_scan(store->bitcasks[i]); } } return store; }