int libgretl_mpi_init (int self, int np, int dcmt) { int err; libset_init(); /* let geneval know */ set_mpi_rank_and_size(self, np); /* load MPI library functions */ err = gretl_MPI_init(); if (err) { return err; } if (dcmt && np > 1) { /* use DCMT for multiple RNGs */ gretl_dcmt_init(np, self, 4172); } else { /* just use one RNG */ gretl_rand_init(); } gretl_xml_init(); gretl_stopwatch_init(); mpf_set_default_prec(get_mp_bits()); /* be relatively quiet by default */ set_gretl_echo(0); set_gretl_messages(0); return 0; }
static ExecState *gretl_console_init (char *cbuf) { ExecState *s; PRN *prn; s = mymalloc(sizeof *s); if (s == NULL) { return NULL; } if (bufopen(&prn)) { free(s); return NULL; } set_gretl_echo(1); gretl_exec_state_init(s, CONSOLE_EXEC, cbuf, get_lib_cmd(), model, prn); command_history_init(); return s; }
int main (int argc, char *argv[]) { #ifdef WIN32 char *callname = argv[0]; #endif char linecopy[MAXLINE]; DATASET *dset = NULL; MODEL *model = NULL; ExecState state; char *line = NULL; int quiet = 0; int makepkg = 0; int load_datafile = 1; char filearg[MAXLEN]; char runfile[MAXLEN]; double scriptval = NADBL; CMD cmd; PRN *prn = NULL; PRN *cmdprn = NULL; int err = 0; #ifdef G_OS_WIN32 win32_set_gretldir(callname); #endif nls_init(); #ifdef HAVE_READLINE rl_bind_key(0x18, ctrl_x); #endif dset = datainfo_new(); if (dset == NULL) { noalloc(); } if (argc < 2) { load_datafile = 0; } else { gretlopt opt = 0; err = parse_options(&argc, &argv, &opt, &scriptval, filearg); if (!err && (opt & (OPT_DBOPEN | OPT_WEBDB))) { /* catch GUI-only options */ err = E_BADOPT; } if (err) { /* bad option */ usage(1); } else if (opt & (OPT_HELP | OPT_VERSION)) { /* we'll exit in these cases */ if (opt & OPT_HELP) { usage(0); } else { logo(0); exit(EXIT_SUCCESS); } } if (opt & (OPT_BATCH | OPT_RUNIT | OPT_MAKEPKG)) { if (*filearg == '\0') { /* we're missing a filename argument */ usage(1); } else { /* record argument (not a datafile) */ strcpy(runfile, filearg); load_datafile = 0; if (opt & OPT_BATCH) { batch = 1; } else if (opt & OPT_MAKEPKG) { batch = 1; makepkg = 1; } else { runit = 1; } } } else if (*filearg == '\0') { load_datafile = 0; } if (opt & OPT_QUIET) { quiet = 1; } if (opt & OPT_ENGLISH) { force_language(LANG_C); } } libgretl_init(); logo(quiet); if (!quiet) { session_time(NULL); } prn = gretl_print_new(GRETL_PRINT_STDOUT, &err); if (err) { noalloc(); } line = malloc(MAXLINE); if (line == NULL) { noalloc(); } #ifdef WIN32 win32_cli_read_rc(callname); #else cli_read_rc(); #endif /* WIN32 */ if (!batch) { strcpy(cmdfile, gretl_workdir()); strcat(cmdfile, "session.inp"); cmdprn = gretl_print_new_with_filename(cmdfile, &err); if (err) { errmsg(err, prn); return EXIT_FAILURE; } } if (load_datafile) { handle_datafile(filearg, runfile, dset, prn, cmdprn); } /* allocate memory for model */ model = allocate_working_model(); if (model == NULL) { noalloc(); } gretl_cmd_init(&cmd); gretl_exec_state_init(&state, 0, line, &cmd, model, prn); set_debug_read_func(get_interactive_line); /* print list of variables */ if (data_status) { varlist(dset, prn); } if (!na(scriptval)) { /* define "scriptopt" */ gretl_scalar_add("scriptopt", scriptval); } /* misc. interactive-mode setup */ if (!batch) { check_help_file(); fb = stdin; push_input_file(fb); if (!runit && !data_status) { fputs(_("Type \"open filename\" to open a data set\n"), stdout); } } #ifdef HAVE_READLINE initialize_readline(); #endif if (batch || runit) { /* re-initialize: will be incremented by "run" cmd */ runit = 0; if (makepkg) { set_gretl_echo(0); } if (strchr(runfile, ' ')) { sprintf(line, "run \"%s\"", runfile); } else { sprintf(line, "run %s", runfile); } err = cli_exec_line(&state, dset, cmdprn); if (err && fb == NULL) { exit(EXIT_FAILURE); } } *linecopy = '\0'; /* main command loop */ while (cmd.ci != QUIT && fb != NULL && !xout) { if (err && gretl_error_is_fatal()) { gretl_abort(linecopy); } if (gretl_execute_loop()) { if (gretl_loop_exec(&state, dset, NULL)) { return 1; } } else { err = cli_get_input_line(&state); if (err) { errmsg(err, prn); break; } } if (!state.in_comment) { if (cmd.context == FOREIGN || cmd.context == MPI || gretl_compiling_python(line)) { tailstrip(line); } else { err = maybe_get_input_line_continuation(line); if (err) { errmsg(err, prn); break; } } } strcpy(linecopy, line); tailstrip(linecopy); err = cli_exec_line(&state, dset, cmdprn); } /* end of get commands loop */ if (!err) { err = gretl_if_state_check(0); if (err) { errmsg(err, prn); } } if (makepkg && !err) { switch_ext(filearg, runfile, "gfn"); sprintf(line, "makepkg %s\n", filearg); cli_exec_line(&state, dset, cmdprn); } /* leak check -- try explicitly freeing all memory allocated */ destroy_working_model(model); destroy_dataset(dset); if (fb != stdin && fb != NULL) { fclose(fb); } free(line); gretl_print_destroy(prn); gretl_cmd_free(&cmd); libgretl_cleanup(); return 0; }