/* * The thread area is shared between the main process and the job * threads/processes. So setup a shared memory segment that will hold * all the job info. We use the end of the region for keeping track of * open files across jobs, for file sharing. */ static int setup_thread_area(void) { void *hash; if (threads) return 0; /* * 1024 is too much on some machines, scale max_jobs if * we get a failure that looks like too large a shm segment */ do { size_t size = max_jobs * sizeof(struct thread_data); size += file_hash_size; size += sizeof(unsigned int); #ifndef CONFIG_NO_SHM shm_id = shmget(0, size, IPC_CREAT | 0600); if (shm_id != -1) break; if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC) { perror("shmget"); break; } #else threads = malloc(size); if (threads) break; #endif max_jobs >>= 1; } while (max_jobs); #ifndef CONFIG_NO_SHM if (shm_id == -1) return 1; threads = shmat(shm_id, NULL, 0); if (threads == (void *) -1) { perror("shmat"); return 1; } #endif memset(threads, 0, max_jobs * sizeof(struct thread_data)); hash = (void *) threads + max_jobs * sizeof(struct thread_data); fio_debug_jobp = (void *) hash + file_hash_size; *fio_debug_jobp = -1; file_hash_init(hash); flow_init(); return 0; }
int main(void) { // Read input file main_read_input(); // Read and sort output directory for finding files within our time limits init_part_files(); init_flow_files(); // Create output directory create_output_dir(); // Get number of particles nparts = cgns_read_nparts(); // Initialize domain and flow arrays domain_init(); // Initialize partstruct and flow vars parts_init(); flow_init(); // Messy hack for taking advantage of CUDA_VISIBLE_DEVICES in SLURM dev_start = read_devices(); // Allocate device memory cuda_dev_malloc(); cuda_dom_push(); //cuda_part_push(); //cuda_part_pull(); // Calculate tetrad stats for (tt = 0; tt < nFiles; tt++) { // Read in new data and push to device cgns_fill_flow(); cuda_flow_push(); // Calculate phase average cuda_phase_averaged_vel(); } // write phaseAvereaged to file write_part_data(); // Free and exit free_vars(); cuda_dev_free(); return EXIT_SUCCESS; }
void compile(void) { LEXEME *lex = NULL ; SetGlobalFlag(TRUE); helpinit(); errorinit(); constoptinit(); declare_init(); init_init(); inlineinit(); lambda_init(); rtti_init(); expr_init(); libcxx_init(); statement_ini(); syminit(); preprocini(infile, inputFile); lexini(); setglbdefs(); templateInit(); #ifndef PARSER_ONLY SSAInit(); outcodeini(); conflictini(); iexpr_init(); iinlineInit(); flow_init(); genstmtini(); #endif ParseBuiltins(); if (chosenAssembler->intrinsicInit) chosenAssembler->intrinsicInit(); if (chosenAssembler->inlineAsmInit) chosenAssembler->inlineAsmInit(); if (chosenAssembler->outcode_init) chosenAssembler->outcode_init(); if (chosenAssembler->enter_filename) chosenAssembler->enter_filename(clist->data); if (cparams.prm_debug && chosenDebugger && chosenDebugger->init) chosenDebugger->init(); if (cparams.prm_browse && chosenDebugger && chosenDebugger->init_browsedata) chosenDebugger->init_browsedata(clist->data); browse_init(); browse_startfile(infile, 0); if (cparams.prm_assemble) { lex = getsym(); if (lex) { BLOCKDATA block; memset(&block, 0, sizeof(block)); block.type = begin; while ((lex = statement_asm(lex, NULL, &block)) != NULL) ; #ifndef PARSER_ONLY genASM(block.head); #endif } } else { #ifndef PARSER_ONLY asm_header(clist->data, version); #endif lex = getsym(); if (lex) { while ((lex = declare(lex, NULL, NULL, sc_global, lk_none, NULL, TRUE, FALSE, FALSE, FALSE, ac_public)) != NULL) ; } } #ifdef PARSER_ONLY ccDumpSymbols(); #endif if (!total_errors) { dumpInlines(); dumpInitializers(); dumpInlines(); dumpStartups(); #ifndef PARSER_ONLY dumpLits(); #endif /* rewrite_icode(); */ if (chosenAssembler->gen->finalGen) chosenAssembler->gen->finalGen(); if (!cparams.prm_assemble && cparams.prm_debug) if (chosenDebugger && chosenDebugger->outputtypedef) debug_dumptypedefs(globalNameSpace); #ifndef PARSER_ONLY putexterns(); #endif if (!cparams.prm_asmfile) if (chosenAssembler->output_obj_file) chosenAssembler->output_obj_file(); } findUnusedStatics(globalNameSpace); dumperrs(stdout); if (cparams.prm_debug && chosenDebugger && chosenDebugger->rundown) chosenDebugger->rundown(); if (cparams.prm_browse && chosenDebugger && chosenDebugger->rundown_browsedata) chosenDebugger->rundown_browsedata(); #ifndef PARSER_ONLY if (!cparams.prm_assemble) asm_trailer(); #endif }
int flowcache_newflow(FLOWCACHE *flowcachep, FLOWKEY *keyp, FLOW **flowpp) { static int run_once = 1; #ifdef FLOW_PERF_FIX FLOW *newflow = NULL; SFXHASH_NODE *new_node = NULL; #else static FLOW zeroflow; #endif static FLOWKEY searchkey; int ret; if(!flowcachep || !keyp || !flowpp) { return FLOW_ENULL; } FCS_new(flowcachep, keyp); if(run_once) { /* all the time that we're running this, we're actually going to be filling in the key, and having zero'd out counters */ #ifndef FLOW_PERF_FIX memset(&zeroflow, 0, sizeof(FLOW)); #endif memset(&searchkey, 0, sizeof(FLOWKEY)); run_once = 0; } flowkey_normalize(&searchkey, keyp); #ifdef FLOW_PERF_FIX /* This just eliminates a memcpy. */ /* Since we're using auto node recovery, we should get a node back * here that has a data pointer. */ /* flow_init resets the internal key & stats to zero. */ new_node = sfxhash_get_node(flowcachep->ipv4_table, &searchkey); if (new_node && new_node->data) { newflow = new_node->data; if(flow_init(newflow, keyp->protocol, keyp->init_address, keyp->init_port, keyp->resp_address, keyp->resp_port)) { return FLOW_ENULL; } ret = SFXHASH_OK; } else { ret = SFXHASH_NOMEM; } #else if(flow_init(&zeroflow, keyp->protocol, keyp->init_address, keyp->init_port, keyp->resp_address, keyp->resp_port)) { return FLOW_ENULL; } ret = sfxhash_add(flowcachep->ipv4_table, &searchkey, &zeroflow); #endif switch(ret) { case SFXHASH_OK: if(flowcache_mru(flowcachep,flowpp) != FLOW_SUCCESS) { /* something's wrong because we just added this thing!\n */ flow_printf("Unable to find a key I just added!\n"); return FLOW_BADJUJU; } if(init_flowdata(flowcachep, *flowpp)) { return FLOW_BADJUJU; } return FLOW_SUCCESS; case SFXHASH_NOMEM: return FLOW_ENOMEM; case SFXHASH_INTABLE: default: return FLOW_EINVALID; } }
/* name : input_init */ static int input_init( probe_t *probe, int flags ) { char *device = g_par.interface; int dltype; if ( flags & PROBE_OFFLINE ) { /* open file */ if ( (probe->pcap=pcap_open_offline( device, errbuf )) ==NULL) { errorf( "[%s] pcap_open_offline(): %s\n", device, errbuf ); return -1; } probe->cnt = 1; } else { /* open interface */ int promisc = (flags&PROBE_PROMISC)?1:0; char *p = probe->device; if ( *device == '\0' ) { if ((device=pcap_lookupdev( errbuf )) ==NULL) { errorf( "pcap_lookupdev() failed: %s\n", errbuf ); return -1; } } if ( (probe->pcap=pcap_open_live( device, g_snaplen, promisc, 100 /*ms*/, errbuf )) ==NULL ) { /* todo!! */ errorf( "pcap_open_live(%s): %s\n", p, errbuf ); return -1; } probe->cnt = 1000; } switch ( dltype = pcap_datalink(probe->pcap) ) { case DLT_EN10MB: probe->dltype = dltype; probe->offset = 14; break; case DLT_ATM_RFC1483: probe->dltype = dltype; probe->offset = 8; break; default: probe->dltype = DLT_RAW; probe->offset = 0; } if( g_par.filter != NULL ) { if( (pcap_compile( probe->pcap, &probe->fprg, g_par.filter, 1, 0 ) <0) || (pcap_setfilter( probe->pcap, &probe->fprg ) <0) ) { mlogf( 0, "[%s] unable to set filter: '%s'\n", g_par.progname, g_par.filter ); } else { mlogf( 1, "[%s] set filter to '%s'\n", g_par.progname, g_par.filter ); } } mlogf( 1, "[%s] device: %s, dltype=%d, %s\n", g_par.progname, (flags&PROBE_OFFLINE)?basename(device):device, probe->dltype, (flags&PROBE_OFFLINE)?"offline" :(flags&PROBE_PROMISC)?"promisc.":"no promisc." ); if ( flags & PROBE_OFFLINE ) { probe->fd = fileno( pcap_file( probe->pcap ) ); probe->device = strdup( basename( device ) ); } else { probe->fd = pcap_fileno( probe->pcap ); probe->device = strdup( device ); } if ( probe->fd >= 0) { if ( mpoll_fdadd( probe->fd, MPOLL_IN, cb_dispatch, (void*)probe ) <0 ) { mlogf( 0, "[%s] %s\n", g_par.progname, strerror(errno) ); return -1; } mlogf( 2, "[%s] add fd %d to poll loop\n", g_par.progname, probe->fd ); } if ( flow_init( &(probe->ipflows), g_par.ipflow_max, g_par.biflows, g_par.ipflow_timeout ) <0 ) { mlogf( 0, "[%s] ipflow initialisation failed: %s", g_par.progname, strerror(errno) ); return -1; } return 0; }