void dataset_convert(dataset_t* data, stream_t* out) { void* m; int i; printf("Allocating %d bytes.\n", ACTUAL_MEMORY_SIZE(out)); m = malloc(ACTUAL_MEMORY_SIZE(out)); if(m == NULL) { printf("Cannot allocate memory.\n"); return; } memset(m, 0, ACTUAL_MEMORY_SIZE(out)); for(i = 0; i < data->n_records / MEMORY_RECORDS(out); i++) { memcpy(m, data->records + (i * MEMORY_RECORDS(out) * RECORD_SIZE(out)), MEMORY_RECORDS(out) * RECORD_SIZE(out)); memory_write(out, m, MEMORY_RECORDS(out)); stats_print(); } if(data->n_records % MEMORY_RECORDS(out)) { memcpy(m, data->records + (i * MEMORY_RECORDS(out) * RECORD_SIZE(out)), (data->n_records % MEMORY_RECORDS(out)) * RECORD_SIZE(out)); memory_write(out, m, data->n_records % MEMORY_RECORDS(out)); stats_print(); } free(m); }
static void stats_poll(int interval, bool err_only) { struct stats_record rec, prev; int map_fd; memset(&rec, 0, sizeof(rec)); /* Trick to pretty printf with thousands separators use %' */ setlocale(LC_NUMERIC, "en_US"); /* Header */ if (verbose) printf("\n%s", __doc__); /* TODO Need more advanced stats on error types */ if (verbose) printf(" - Stats map: %s\n", map_data[0].name); map_fd = map_data[0].fd; stats_print_headers(err_only); fflush(stdout); while (1) { memcpy(&prev, &rec, sizeof(rec)); stats_collect(map_fd, &rec); stats_print(&rec, &prev, err_only); fflush(stdout); sleep(interval); } }
void mgr_on_end() { read_set_free( &p_trans.read_set ); write_set_free( &p_trans.write_set ); #ifdef TM_STATS stats_print( stdout, stats_get_total(stdout) ); fflush(stdout); #endif }
static int control(struct af_instance_s *af, int cmd, void *arg) { struct af_stats *s = af->setup; switch(cmd) { case AF_CONTROL_REINIT: return stats_init(af, s, arg); case AF_CONTROL_PRE_DESTROY: stats_print(s); return AF_OK; } return AF_UNKNOWN; }
uint16_t char_rx(uint8_t c) { switch (c) { case 'm': state = SM_TX; break; case 'h': //stop sending seq_max = 0; break; case 'f': //stop queue pop stop = 1; break; case 's': stats_print(0); break; case 'z': stats_clear(); break; } return 1; }
static void stats_poll(int interval, bool err_only) { struct stats_record *rec, *prev; rec = alloc_stats_record(); prev = alloc_stats_record(); stats_collect(rec); if (err_only) printf("\n%s\n", __doc_err_only__); /* Trick to pretty printf with thousands separators use %' */ setlocale(LC_NUMERIC, "en_US"); /* Header */ if (verbose) printf("\n%s", __doc__); /* TODO Need more advanced stats on error types */ if (verbose) { printf(" - Stats map0: %s\n", map_data[0].name); printf(" - Stats map1: %s\n", map_data[1].name); printf("\n"); } fflush(stdout); while (1) { swap(&prev, &rec); stats_collect(rec); stats_print(rec, prev, err_only); fflush(stdout); sleep(interval); } free_stats_record(rec); free_stats_record(prev); }
int main_unnested (int argc, char* argv[]) { cerr << "K version: " << VERSION << endl; cerr << "Reference: " << REFERENCE << endl; cerr << "Compiled by: " << CXX_VERSION << endl; cerr << "Compilation flags: " << CXXFLAGS << endl; const char* thisfunction = "main_unnested"; KConfig K; KInt MI = 500; KInt MJ = 40; KInt g = 1; KScalar U = 1.0; KScalar s = 1.0; KScalar h = 0.0; KScalar S = 0.01; /* selfing rate */ Trajectory trajectory; if (0) { K = initiate_quick(MI, MJ, g, U, s, h, S); K->fitness_function = FITNESS_MULTIPLICATIVE; } else { K = initiate_KConfig(); initiate_load_classes(K, MI, MJ); initiate_genotypes(K, g); K->U = U; K->fitness_function = FITNESS_MULTIPLICATIVE; K->fit_s = s; K->fit_h = h; K->S[0] = S; K->epsilon = 0.00000001; K->savefile = K->loadfile = "savefile.txt"; if (cmdline_args(K, argc, argv)) { fatal("Usage: K --help"); } set_repro(K, K->S[0], 0.0, K->A[0], 0.0); } // set_debug(DEBUG_LETHALS); // set_debug(DEBUG_TRACE1); // set_debug(DEBUG_TRACE2); // set_debug(DEBUG_GENERATIONS); set_debug(DEBUG_FOLLOW_EQUILIBRIUM); // set_debug(DEBUG_EQUILIBRIUM); // set_debug(DEBUG_NORMALIZATION); // set_debug(DEBUG_TRUNCATE); // set_debug(DEBUG_TRUNCATE_DETAIL); initiate_model_state(K); compute_adults_initial(K); // K->option_table = 1; // K->load = 1; if (K->load) { load_loadfile(K, K->x); } else { fill_KArray(K, K->x, 0.0); K->x[10][0][0] = 1.0; } // fill_KArray(K, K->x, 0.0); // K->x[20][0][0] = 1.0; /* the above method leaves all adults in the population ** in one load class, L(0,0). Now, we'll shift these ** around a little to examine the results of outcrossing */ /* add a few mutations */ /* for (i=0; i < 10; i++) { apply_mutation(K, temp, K->x); copy_KArray(K, K->x, temp); } */ // fprintf(stderr, "K --------------------------------------------------\n"); // fprintf(stderr, "U\ts\th\tS\n%lg\t%lg\t%lg\t%lg\n", K->U, K->fit_s, K->fit_h, K->S[0]); while (! is_equilibrium(K) || K->generation <= GENERATION_MINIMUM) { if (K->generation > GENERATION_CUTOFF) { fprintf(stderr, "exceeded GENERATION_CUTOFF=%d, stopping\n", GENERATION_CUTOFF); break; } if (DEBUG(DEBUG_GENERATIONS) || (K->progress && K->generation % K->progress == 0)) fprintf(stderr, "generation %d\n", K->generation); IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "generation %d\n", K->generation); if (K->option_truncate) truncate_KArray(K, K->x, LOADCLASS_TRUNCATE); compute_mutation(K); compute_self_progeny(K); compute_apomixis_progeny(K); // compute_outcross_progeny(K); // inefficient Kondrashov method compute_gametes(K); compute_zygotes(K); compute_summed_progeny(K); compute_selection(K); compute_adults_nextgen(K); IF_DEBUG(DEBUG_EQUILIBRIUM) { fprintf(stderr, "checking equilibrium at end of generation %d------------\n", K->generation - 1); fprintf(stderr, "dump of K->x[..][0][0]\n"); dump_KArray(K, K->x, K->MI, 0, 1); fprintf(stderr, "calling is_equilibrium(K) just to check...\n"); (void) is_equilibrium(K); fprintf(stderr, "end of equilibrium check ---------------\n"); } normalize_KArray(K, K->x); /* if (K->generation - 1 == 0) { trajectory.start(K, "trajectory.txt", "end_of_gen", 5); trajectory.debug(true); } else if (trajectory.active()) { trajectory.check(K); } */ // dump_KArray(K, K->x, 100, 0, 0); } // fprintf(stderr, "\n"); if (!K->option_nolethal && K->is_lethal) { /* ** We need one more run through everything to get the ** progeny arrays built correctly. We don't do mutation ** here. */ K->createlethal = 1; IF_DEBUG(DEBUG_LETHALS) fprintf(stderr, "%s: one more run, to get progeny arrays\n", thisfunction); IF_DEBUG(DEBUG_LETHALS) fprintf(stderr, "%s: K->createlethal=%d\n", thisfunction, K->createlethal); compute_self_progeny(K); compute_apomixis_progeny(K); compute_gametes(K); compute_zygotes(K); compute_summed_progeny(K); compute_selection(K); compute_adults_nextgen(K); K->generation--; normalize_KArray(K, K->x); } stats_all(K); stats_print(K); if (trajectory.active() && trajectory.lastgen() != K->generation) { trajectory.write(K); trajectory.stop(); } // dump_KArray(K, K->x, 10, 0, 0); //K->save_savefile = 1; if (K->save) { save_savefile(K, K->x); } return 0; }
// Handle SIGINT (Ctrl+C) and exit server properly static void sigint_handler() { printf("\b\b"), server_stop(), stats_print(), terminate_logger(); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { FILE* f; metadata_t* meta; fp_context_t* context; struct sort_config sc; dataset_t* ds; char target[256]; stream_t* stream; config_t conf; external_dataset_t* ext; int i; if(argc < 2) { printf("Barf!\n"); exit(-1); } if((f = fopen(argv[1], "r")) == NULL) { printf("Cannot open dataset file %s.\n", argv[1]); return -1; } meta = metadata_read(f); sc.verbose = 1; sc.normalize = 0; sc.denormalize = 0; sc.benchmark = 1; sc.find_order = ITERATIVE; sc.index = KEEP; sc.cmp = HILBERT; sc.print = stdout; context = fp_create_context(&sc, meta->dimz, meta->dimf, meta->start_order); ds = dataset_read(f, meta, context); fclose(f); dataset_print(ds, FALSE); strcpy(target, argv[1]); strcat(target, ".stream"); printf("Number of records: %d\n", ds->n_records); printf("Record size: %d\n", context->record_size); conf.memory_size = 1000; conf.block_size = 0x100; conf.record_size = context->record_size; stream = stream_create(&conf, target); stream_open(stream, O_CREAT | O_TRUNC | O_SYNC | O_WRONLY); dataset_convert(ds, stream); stream_close(stream); stream_open(stream, O_SYNC | O_RDONLY); ext = external_dataset_create(stream, meta, ds->n_records); for(i = 0; i < ds->n_records / MEMORY_RECORDS(stream); i++) { memory_read(stream, ext->mem->records, MEMORY_RECORDS(stream)); ext->mem->n_records = MEMORY_RECORDS(stream); dataset_print(ext->mem, FALSE); } if(ds->n_records % MEMORY_RECORDS(stream)) { memory_read(stream, ext->mem->records, ds->n_records % MEMORY_RECORDS(stream)); ext->mem->n_records = ds->n_records % MEMORY_RECORDS(stream); dataset_print(ext->mem, FALSE); } printf("Stream position: %ld vs. %ld\n", stream->pos, stream_tell(stream)); external_dataset_sort(ext); external_dataset_destroy(ext); stream_destroy(stream); stats_print(); dataset_destroy(ds); fp_destroy_context(context); metadata_destroy(meta); return 0; }
void handler_alarm(int sig) { stats_print(); signal(SIGALRM, handler_alarm); alarm(FREQ); }