int main( int argc, char **argv ) { pthread_attr_t attr; size_t stacksize; struct thread_info threads[NTHREADS]; int thread_num; unsigned long start = memory_report(); printf( "Create %d threads with stack size = %d\n", NTHREADS, KB(set_stack_size(&attr)) ); for ( thread_num = 0 ; thread_num < NTHREADS ; thread_num++ ) { struct thread_info *current = &( threads[thread_num] ); if ( pthread_create(&(current->tid), &attr, dowork, current) != 0 ) { perror( "pthread_create" ); exit( -1 ); } pthread_yield(); /* to make sure thread gets started */ } unsigned long end = memory_report(); unsigned long delta = end - start; printf( "Memory delta is %lu KB (%lu MB)\n", KB(delta), KB(KB(delta)) ); pthread_exit(NULL); }
void p_mem(void) { printf("\n------------- memory usage (for entire run) -------------------\n"); printf("\nTotal malloced: %d megabytes\n", megs_malloced()); fprint_strbuf_mem(stdout, 1); fprint_parse_mem(stdout, 0); fprint_glist_mem(stdout, 0); fprint_term_mem(stdout, 0); fprint_topform_mem(stdout, 0); fprint_clist_mem(stdout, 0); fprint_mclause_mem(stdout, 0); fprint_mstate_mem(stdout, 0); fprint_estack_mem(stdout, 0); memory_report(stdout); } /* p_mem */
int run_checks() { int numerr = 0; if ( memdebug ) memory_report(); numerr += list_check(); if ( web.representation != SIMPLEX ) { numerr += facetedge_check(REGCHECK); if ( web.skel[BODY].count > 0 ) numerr += facet_body_check(); numerr += collapse_check(); numerr += vertex_facet_check(); } numerr += method_check(); if ( web.symmetry_flag ) numerr += wrap_check(); #ifdef MPI_EVOLVER numerr += mpi_task_checks(); #endif check_count = numerr; return numerr; } /* end run_checks() */
int main(int argc, char *argv[]) { char *unixctl_path = NULL; struct unixctl_server *unixctl; char *remote; bool exiting; int retval; set_program_name(argv[0]); retval = dpdk_init(argc,argv); argc -= retval; argv += retval; ovs_cmdl_proctitle_init(argc, argv); service_start(&argc, &argv); remote = parse_options(argc, argv, &unixctl_path); fatal_ignore_sigpipe(); ovsrec_init(); daemonize_start(); if (want_mlockall) { #ifdef HAVE_MLOCKALL if (mlockall(MCL_CURRENT | MCL_FUTURE)) { VLOG_ERR("mlockall failed: %s", ovs_strerror(errno)); } #else VLOG_ERR("mlockall not supported on this system"); #endif } retval = unixctl_server_create(unixctl_path, &unixctl); if (retval) { exit(EXIT_FAILURE); } unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting); bridge_init(remote); free(remote); exiting = false; while (!exiting) { memory_run(); if (memory_should_report()) { struct simap usage; simap_init(&usage); bridge_get_memory_usage(&usage); memory_report(&usage); simap_destroy(&usage); } bridge_run(); unixctl_server_run(unixctl); netdev_run(); memory_wait(); bridge_wait(); unixctl_server_wait(unixctl); netdev_wait(); if (exiting) { poll_immediate_wake(); } poll_block(); if (should_service_stop()) { exiting = true; } } bridge_exit(); unixctl_server_destroy(unixctl); service_stop(); return 0; }
int main(int argc, char *argv[]) { char *unixctl_path = NULL; struct unixctl_server *unixctl; struct signal *sighup; char *remote; bool exiting; int retval; proctitle_init(argc, argv); set_program_name(argv[0]); stress_init_command(); remote = parse_options(argc, argv, &unixctl_path); signal(SIGPIPE, SIG_IGN); sighup = signal_register(SIGHUP); process_init(); ovsrec_init(); daemonize_start(); if (want_mlockall) { #ifdef HAVE_MLOCKALL if (mlockall(MCL_CURRENT | MCL_FUTURE)) { VLOG_ERR("mlockall failed: %s", ovs_strerror(errno)); } #else VLOG_ERR("mlockall not supported on this system"); #endif } worker_start(); retval = unixctl_server_create(unixctl_path, &unixctl); if (retval) { exit(EXIT_FAILURE); } unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting); bridge_init(remote); free(remote); exiting = false; while (!exiting) { worker_run(); if (signal_poll(sighup)) { vlog_reopen_log_file(); } memory_run(); if (memory_should_report()) { struct simap usage; simap_init(&usage); bridge_get_memory_usage(&usage); memory_report(&usage); simap_destroy(&usage); } bridge_run_fast(); bridge_run(); bridge_run_fast(); unixctl_server_run(unixctl); netdev_run(); worker_wait(); signal_wait(sighup); memory_wait(); bridge_wait(); unixctl_server_wait(unixctl); netdev_wait(); if (exiting) { poll_immediate_wake(); } poll_block(); } bridge_exit(); unixctl_server_destroy(unixctl); return 0; }
int command_sys_mem(struct cli * c, int argc, char **argv) { memory_report(); return 0; }
int main(int argc, char *argv[]) { precompute(); #ifdef USE_HASH hash_init(); #endif // load_endgames(); // load_bitbases(); if (argc == 2 && !strcmp(argv[1], "nobook")) { printf("Skipping opening book\n"); } else if (argc == 2 && !strcmp(argv[1], "makebook")) { load_opening_book(1); opening_book_grow(0); return 0; } else if (argc == 2 && !strcmp(argv[1], "showbook")) { load_opening_book(1); opening_book_grow(1); return 0; } else load_opening_book(2); new_game(); int ply; int i, j, k; FILE * input; FILE * output; char command[80] = ""; char buffer[4100] = ""; /* if (argc == 2 && !strcmp(argv[1], "files")) { printf("Using files for I/O\n"); input = fopen("input.txt", "r+"); output = fopen("output.txt", "w"); } else */ { input = stdin; output = stdout; } if (argc == 2 && !strcmp(argv[1], "bitbases")) { bitbase_report(); return 0; } if (argc == 7 && !strcmp(argv[1], "position")) { i = bitbase_test( atoi(argv[2]) ,atoi(argv[3]) ,atoi(argv[4]) ,atoi(argv[5]) ,atoi(argv[6]) ); printf("%s\n", i ? "is a win for black" : "not a win for black"); int pieces[MAX_BDB_PIECES]; int total_pieces = 0; for (i = 0; i < atoi(argv[2]); ++i) pieces[total_pieces++] = 0; for (i = 0; i < atoi(argv[3]); ++i) pieces[total_pieces++] = 1; for (i = 0; i < atoi(argv[4]); ++i) pieces[total_pieces++] = 2; for (i = 0; i < atoi(argv[5]); ++i) pieces[total_pieces++] = 3; position_decode(atoi(argv[6]), pieces, total_pieces); print_board(0); return 0; } if (argc == 2 && !strcmp(argv[1], "sanity")) { sanity_checks(); memory_report(); return 0; } if (argc == 2 && !strcmp(argv[1], "perft")) { iterative_performance_test(); #ifdef SORT_STATISTIC for (i = 0; i < 5; ++i) printf("Returns at sort level %d: %d\n" , i , sort_statistic[i]); #endif return 0; } if (argc >= 4 && !strcmp(argv[1], "pdn")) { ply = 0; FILE * pdn; pdn = fopen(argv[3], "a+"); if (!pdn) { printf("error: fopen \"%s\" for append/create\n", argv[3]); // printf("err: %d - %s\n", errno, strerror(errno)); // getcwd(buffer, sizeof(buffer)); // printf("pwd: %s\n", buffer); return 1; } while (!feof(pdn)) // fixme: this loader sux... { if (!fgets(buffer, 4096, pdn)) break; //if (!buffer || feof(pdn)) // break; i = 0; while (j = load_move_from_pdn(buffer, command, &i)) { generate_moves(0, 0); k = find_move(0, command); if (k < 0 || k >= move_counter[0]) { fprintf(output, "error invalid move from pdn (%s)\n" , command); for (k = 0; k < move_counter[0]; ++k) { fprintf(output, "move %d ",k); print_move(&moves[0][k], 0); fprintf(output, "\n"); } } else { ++ply; //fprintf(output, "executing move at index %d: ", k); if (!strcmp(argv[2], "show") || !strcmp(argv[2], "step")) { if (ply % 2 == 1) printf("%3d. ", (ply+1) / 2); print_move(&moves[0][k], 0); if (ply % 2 == 0) { printf("\n"); //print_board(0); } else printf(" "); if (!strcmp(argv[2], "step") && ply % 2 == 0) { print_board(0); getc(stdin); } } //fprintf(output, "\n"); move_do(&moves[0][k], 0); move_list_push(&moves[0][k]); } } if (feof(pdn)) break; } fclose(pdn); if (!strcmp(argv[2], "play")) { pdn = fopen(argv[3], "a"); if (!pdn) { printf("error: fopen \"%s\" for append\n", argv[3]); return 1; } if (argc >= 5 && strcmp(argv[4], "hint") && strcmp(argv[4], "move")) { generate_moves(0, 0); i = find_move(0, argv[4]); if (i < 0 || i >= move_counter[0]) { print_moves(0); i = -1; } else { move_do(&moves[0][i], 0); move_list_push(&moves[0][i]); fprintf(pdn, "%s ", argv[4]); if (moves[0][i].same_player_square != -1) i = -1; } } if (i != -1) { if (argc >= 6) strength = atoi(argv[5]); if (argc >= 7) thinking_time = atoi(argv[6]); if (strength == 1) thinking_time = 1; if (!strcmp(argv[4], "hint")) bestmove(0, 0); else while (bestmove(pdn, 1)); } fclose(pdn); fprintf(output, "boardok "); for (i = 0; i < 64; ++i) fprintf(output, "%d", board[i]); fprintf(output, " %d", state.tactical_square); fprintf(output, " %d", state.side_to_move); fprintf(output, " %d", state.this_piece_must_take); fprintf(output, "\n"); } else { print_board(0); //debug_moves = 1; generate_moves(0, 0); if (!strcmp(argv[2], "show")) print_moves(0); } if (!strcmp(argv[2], "load")) { printf("PDN loaded\n"); command[0] = 0; buffer[0] = 0; } else return 0; } for (;;) { fscanf(input, "%20s", command); if (parse(command, "quit")) break; else if (parse(command, "gnt")) fprintf(output, "id name GNTredux\nid author QuakePhil\ngntok\n"); else if (parse(command, "new")) new_game(); else if (parse(command, "flipside")) state.side_to_move ^= 1; else if (parse(command, "flipkings")) { for (i = 0; i < 64; ++i) if (initial_board[i] != 4) { if (initial_board[i] < 2) initial_board[i] += 2; else initial_board[i] -= 2; } new_game(); } else if (parse(command, "flipboardonly")) { // fixme: need to re-do materials here? int temp[64]; int flip_piece[5] = {1,0,3,2,4}; j = 64; for (i = 0; i < 64; ++i) temp[--j] = flip_piece[board[i]]; for (i = 0; i < 64; ++i) board[i] = temp[i]; state.side_to_move ^= 1; } else if (parse(command, "rand")) rand_board(); else if (parse(command, "think")) { bestmove(0, 0); } else if (parse(command, "go")) { bestmove(0, 1); } else if (parse(command, "perft")) { iterative_performance_test(); } else if (parse(command, "ping")) { fprintf(output, "pong %.6lf\n", timer()); } else if (parse(command, "pboard")) print_board(0); else if (parse(command, "board")) { fprintf(output, "boardok "); for (i = 0; i < 64; ++i) fprintf(output, "%d", board[i]); fprintf(output, " %d", state.tactical_square); fprintf(output, " %d", state.side_to_move); fprintf(output, " %d", state.this_piece_must_take); fprintf(output, "\n"); } else if (parse(command, "time")) { fscanf(input, "%d", &thinking_time); printf("Think time limit set to: %d seconds\n", thinking_time); } else if (parse(command, "pdn")) { fscanf(input, "%20s", buffer); generate_moves(0, 0); i = find_move(0, buffer); if (i < 0 || i >= move_counter[0]) fprintf(output, "error invalid move\n"); else { move_do(&moves[0][i], 0); move_list_push(&moves[0][i]); //fprintf(output, "executing move at index %d: ", i); //print_move(&moves[0][i], 0); //fprintf(output, "\n"); fprintf(output, "done\n"); } } else if (parse(command, "do") || parse(command, "toggle")) { fscanf(input, "%d", &i); fprintf(output, "executing move %d\n", i); generate_moves(0, 0); if (i < 0) fprintf(output, "error move can't be negative\n"); else if (i >= move_counter[0]) fprintf(output, "error no such move\n"); else { move_do(&moves[0][i], 0); move_list_push(&moves[0][i]); if (parse(command, "toggle")) { print_board(0); fprintf(output, "undoing move %d\n", i); move_undo(&moves[0][i], 0); print_board(0); } } fprintf(output, "done\n"); } else if (parse(command, "list")) { print_move_list(); } else if (parse(command, "pbook")) { print_book(); } else if (parse(command, "moves")) { generate_moves(0, 0); for (i = 0; i < move_counter[0]; ++i) { fprintf(output, "move %d ",i); print_move(&moves[0][i], 1); fprintf(output, "\n"); } fprintf(output, "movesok\n"); } else // if (!strcmp(command, "help")) { // fprintf(output, "?\n"); } fflush(output); } #ifdef HASH_STATISTIC printf("Hash saves: %d\n", hash_saves); printf("Hash collisions: %d\n", hash_collisions); printf("Hash probes: %d\n", hash_probes); printf("Hash hits: %d\n", hash_hits); #endif #ifdef SORT_STATISTIC for (i = 0; i < 5; ++i) printf("Returns at sort level %d: %d\n" , i , sort_statistic[i]); #endif fclose(output); fclose(input); return 0; }