Example #1
0
int main(int argc, char* argv[]) {
  //
  // This is a user invocation, so parse the arguments to determine
  // the number of locales.
  //
  int32_t execNumLocales;

  // Set up main argument parsing.
  chpl_gen_main_arg.argv = chpl_mem_allocMany(argc, sizeof(char*),
                                      CHPL_RT_MD_COMMAND_BUFFER, -1, 0);
  chpl_gen_main_arg.argv[0] = argv[0];
  chpl_gen_main_arg.argc = 1;
  chpl_gen_main_arg.return_value = 0;

  CreateConfigVarTable();
  parseArgs(true, parse_normally, &argc, argv);

  execNumLocales = getArgNumLocales();

  //
  // If the user did not specify a number of locales let the
  // comm layer decide how many to use (or flag an error)
  //
  if (execNumLocales == 0) {
    execNumLocales = chpl_comm_default_num_locales();
  }
  //
  // Before proceeding, allow the comm layer to verify that the
  // number of locales is reasonable
  //
  chpl_comm_verify_num_locales(execNumLocales);

  //
  // Let the comm layer do any last-minute pre-launch activities it
  // needs to.
  //
  CHPL_COMM_PRELAUNCH();

  //
  // Launch the program
  // This may not return (e.g., if calling chpl_launch_using_exec())
  //
  return chpl_launch(argc, argv, execNumLocales);
}
Example #2
0
//
// Chapel runtime initialization
//
// Factored out of "int main(int argc, char* argv[])" for the purpose
// re-using it when in "library-mode".
//
// Called from main.c:main(...) and chpl-init.c:chpl_library_init(...)
//
void chpl_rt_init(int argc, char* argv[]) {
  int32_t execNumLocales;
  int runInGDB;

  // Check that we can get the page size.
  assert( sys_page_size() > 0 );

  // Declare that we are 'locale aware' so that
  // UTF-8 functions (e.g. wcrtomb) work as
  // indicated by the locale environment variables.
  setlocale(LC_CTYPE,"");
  // So that use of localtime_r is portable.
  tzset();

  //
  // Handle options that set the environment before doing any other
  // runtime initialization.
  //
  parseArgs(false, parse_dash_E, &argc, argv);

  chpl_error_init();  // This does local-only initialization
  chpl_topo_init();
  chpl_comm_init(&argc, &argv);
  chpl_mem_init();
  chpl_comm_post_mem_init();

  chpl_comm_barrier("about to leave comm init code");

  CreateConfigVarTable();      // get ready to start tracking config vars
  chpl_gen_main_arg.argv = chpl_malloc(argc * sizeof(char*));
  chpl_gen_main_arg.argv[0] = argv[0];
  chpl_gen_main_arg.argc = 1;
  chpl_gen_main_arg.return_value = 0;
  parseArgs(false, parse_normally, &argc, argv);
  recordExecutionCommand(argc, argv);

  //
  // If the user specified a number of locales, have the comm layer
  // verify that it is reasonable.
  //
  execNumLocales = getArgNumLocales();
  if (execNumLocales != 0) {
    chpl_comm_verify_num_locales(execNumLocales);
  }

  runInGDB = _runInGDB();
  if (runInGDB) {
    int status;
    if (chpl_comm_run_in_gdb(argc, argv, runInGDB, &status)) {
      chpl_exit_all(status);
    }
  }

  //
  // Initialize the task management layer.
  //
  chpl_task_init();

  // Initialize privatization, needs to happen before hitting module init
  chpl_privatization_init();

  //
  // Some comm layer initialization has to wait until after the
  // tasking layer is initialized.
  //
  chpl_comm_post_task_init();
  chpl_comm_rollcall();

  //
  // Make sure the runtime is fully set up on all locales before we start
  // running Chapel code.
  //
  chpl_comm_barrier("barrier before main");
}