//print stats, uninitialize simulator components, and exit w/ exitcode void exit_now(int exit_code) { //print simulation stats and SMT statistics sim_print_stats(stderr); smt_print_stats(); //un-initialize the simulator sim_uninit(); //Various cleanup if(sim_simout != NULL) { fclose(stderr); } if(sim_progout != NULL) { close(sim_progfd); } if(sim_progerr != NULL) { close(sim_progerrfd); } delete v_argv; delete v_envp; delete sim_odb; delete sim_sdb; //all done! exit(exit_code); }
/* print stats, uninitialize simulator components, and exit w/ exitcode */ static void exit_now(int exit_code) { /* print simulation stats */ sim_print_stats(stderr); /* un-initialize the simulator */ sim_uninit(); /* all done! */ exit(exit_code); }
/* print stats, uninitialize simulator components, and exit w/ exitcode */ static void exit_now (int exit_code) { /* print simulation stats */ sim_print_stats (stderr); /* un-initialize the simulator */ sim_uninit (); if (exit_code) fprintf (stderr, "error: some function call exit_now with exit_code %d\n", exit_code); /* all done! */ exit (exit_code); }
int main(int argc, char **argv) { int c; int argco = argc; char **argvo = argv; fitness_type = FITNESS_MEAN_LIGHTSENSOR; int run_type = STANDARD_RUN; pid_t pid = getpid(); random_seed = (long) time(NULL) ^ pid; save_prefix = "."; quiet = 0; int force = 0; while ((c = getopt (argc, argv, "DT:F:s:fqM:d:R:")) != -1) switch (c) { case 'D': run_type = DEBUG_RUN; break; case 'T': run_type = atoi(optarg); break; case 'F': fitness_type = atoi(optarg); break; case 's': random_seed = atol(optarg); break; case 'f': force = 1; break; case 'q': quiet = 1; break; case 'M': mut_prob = atof(optarg); break; case 'd': save_prefix = optarg; break; case 'R': reset_freq = atoi(optarg); break; case '?': break; default: abort (); } // next argument at argv[optind] argc -= (optind - 1); argv += (optind - 1); srand48(random_seed); if (! quiet) printf("alps-like: Started!\n"); if (run_type == DEBUG_RUN) { goal_fitness = 0.9; } else if (run_type == EASY_RUN) { goal_fitness = 0.8; } if (argc != 4) { fprintf(stderr, "usage: alps-like [-fDq] [-M mutP] [-R resetF] [-T run-type] [-F fitness-type] [-d save-dir] <experiment-name> <task-index> <lobotomise> \n"); fprintf(stderr, "experiment names: An, Bn, Ap, Bp, Ao, Bo\n"); return 2; } //register_signal_handlers(); sim_init(); exp_name = argv[1]; task_index = atoi(argv[2]) - 1; lobotomise = (atoi(argv[3]) == 1); //if (mkdir(save_prefix, 0777)) { char cmd[255]; sprintf(cmd, "mkdir -p %s", save_prefix); if (system(cmd)) { fprintf(stderr, "error: cannot create directory '%s'.\n", save_prefix); return 4; } char filename[255]; sprintf(filename, "%s/results.m", save_prefix); mfile = fopen(filename, "w"); sprintf(filename, "%s/table.txt", save_prefix); table = fopen(filename, "w"); sprintf(filename, "%s/run_again.sh", save_prefix); FILE *run_again = fopen(filename, "w"); fprintf(run_again, "#!/bin/bash\n"); int i; mprintf(1, "commandLine -> \""); for (i = 0; i < argco; i++) { fprintf(run_again, "%s ", argvo[i]); mprintf(0, "%s ", argvo[i]); } mprintf(0, "\"\n"); fprintf(run_again, "\n"); fclose(run_again); mprintf(1, "directory -> \"%s\"\n", save_prefix); int err; err = experiment_phase_count(exp_name, &phase_count); if (err) { fprintf(stderr, "error: cannot get phase count for experiment '%s'.\n", exp_name); err = 1; goto finish; } sprintf(filename, "%s/eval.sh", save_prefix); script = fopen(filename, "w"); fprintf(script, "#!/bin/bash\n" "cd $(dirname $0)\n"); int steps; err = run_alps(&steps); if (err) { fprintf(stderr, "error: alps-like did not find an adequate solution.\n"); } mprintf(1, "{ success -> %s, exitCode -> %d }\n", err == 0 ? "True" : "False", err); sprintf(filename, "%s/FAILURE", save_prefix); if (err) { FILE* fail = fopen(filename, "w"); fprintf(fail, "%d\n", steps); fprintf(fail, "%d\n", err); fclose(fail); } else { unlink(filename); } sprintf(filename, "%s/SUCCESS", save_prefix); if (err) { unlink(filename); } else { FILE* suc = fopen(filename, "w"); fprintf(suc, "%d\n", steps); fclose(suc); } finish: if (! quiet) printf("alps-like: Finished. Logs: \n\n\t%s\n", save_prefix); sim_uninit(); if (mfile) fclose(mfile); if (table) fclose(table); if (script) fclose(script); return err; }