int main(int argc, char *argv[]) { int32_t ret; opal_cmd_line_t cmd_line; char *args = NULL; /*************** * Initialize ***************/ /* * Make sure to init util before parse_args * to ensure installdirs is setup properly * before calling mca_base_open(); */ if( ORTE_SUCCESS != (ret = orcm_init_util()) ) { return ret; } /* initialize the globals */ my_globals.help = false; my_globals.monitor = false; my_globals.update_rate = 5; my_globals.sched = 0; /* Parse the command line options */ opal_cmd_line_create(&cmd_line, cmd_line_opts); mca_base_open(); mca_base_cmd_line_setup(&cmd_line); ret = opal_cmd_line_parse(&cmd_line, true, argc, argv); /* extract the MCA/GMCA params */ mca_base_cmd_line_process_args(&cmd_line, &environ, &environ); /** * Now start parsing our specific arguments */ if (OPAL_SUCCESS != ret || my_globals.help) { args = opal_cmd_line_get_usage_msg(&cmd_line); orte_show_help("help-orcm-ps.txt", "usage", true, args); free(args); return ORTE_ERROR; } /*************************** * We need all of OPAL and ORTE - this will * automatically connect us to the CM ***************************/ if (ORCM_SUCCESS != (ret = orcm_init(ORCM_TOOL))) { goto cleanup; } /* register to receive responses */ if (ORCM_SUCCESS != (ret = orcm_pnp.register_receive("orcm-ps", "0.1", "alpha", ORCM_PNP_GROUP_INPUT_CHANNEL, ORCM_PNP_TAG_PS, ps_recv, NULL))) { ORTE_ERROR_LOG(ret); goto cleanup; } /* announce my existence */ if (ORCM_SUCCESS != (ret = orcm_pnp.announce("orcm-ps", "0.1", "alpha", NULL))) { ORTE_ERROR_LOG(ret); goto cleanup; } /* define an event to signal completion */ if (pipe(rel_pipe) < 0) { opal_output(0, "Cannot open release pipe"); goto cleanup; } opal_event_set(opal_event_base, &rel_ev, rel_pipe[0], OPAL_EV_READ, process_release, NULL); opal_event_add(&rel_ev, 0); /* we know we need to print the data once */ update_data(0, 0, NULL); opal_event_dispatch(opal_event_base); /*************** * Cleanup ***************/ cleanup: /* cleanup orcm */ orcm_finalize(); return ret; }
int main(int argc, char *argv[]) { int32_t ret, i; opal_cmd_line_t cmd_line; char **inpt; opal_buffer_t *buf; int count; char cwd[OPAL_PATH_MAX]; orcm_tool_cmd_t flag = ORCM_TOOL_STOP_CMD; int32_t master=0; uint16_t jfam=0; /*************** * Initialize ***************/ /* * Make sure to init util before parse_args * to ensure installdirs is setup properly * before calling mca_base_open(); */ if( ORTE_SUCCESS != (ret = orcm_init_util()) ) { return ret; } /* initialize the globals */ my_globals.help = false; my_globals.replicas = NULL; my_globals.sched = NULL; my_globals.hnp_uri = NULL; /* Parse the command line options */ opal_cmd_line_create(&cmd_line, cmd_line_opts); mca_base_open(); mca_base_cmd_line_setup(&cmd_line); ret = opal_cmd_line_parse(&cmd_line, true, argc, argv); /* extract the MCA/GMCA params */ mca_base_cmd_line_process_args(&cmd_line, &environ, &environ); /** * Now start parsing our specific arguments */ if (OPAL_SUCCESS != ret || my_globals.help) { char *args = NULL; args = opal_cmd_line_get_usage_msg(&cmd_line); orte_show_help("help-orcm-stop.txt", "usage", true, args); free(args); return ORTE_ERROR; } if (NULL != my_globals.sched) { if (0 == strncmp(my_globals.sched, "file", strlen("file")) || 0 == strncmp(my_globals.sched, "FILE", strlen("FILE"))) { char input[1024], *filename; FILE *fp; /* it is a file - get the filename */ filename = strchr(my_globals.sched, ':'); if (NULL == filename) { /* filename is not correctly formatted */ orte_show_help("help-openrcm-runtime.txt", "hnp-filename-bad", true, "scheduler", my_globals.sched); return ORTE_ERROR; } ++filename; /* space past the : */ if (0 >= strlen(filename)) { /* they forgot to give us the name! */ orte_show_help("help-openrcm-runtime.txt", "hnp-filename-bad", true, "scheduler", my_globals.sched); return ORTE_ERROR; } /* open the file and extract the pid */ fp = fopen(filename, "r"); if (NULL == fp) { /* can't find or read file! */ orte_show_help("help-openrcm-runtime.txt", "hnp-filename-access", true, "scheduler", filename); return ORTE_ERROR; } if (NULL == fgets(input, 1024, fp)) { /* something malformed about file */ fclose(fp); orte_show_help("help-openrcm-runtime.txt", "hnp-file-bad", "scheduler", true, filename); return ORTE_ERROR; } fclose(fp); input[strlen(input)-1] = '\0'; /* remove newline */ /* convert the pid */ master = strtoul(input, NULL, 10); } else { /* should just be the master itself */ master = strtoul(my_globals.sched, NULL, 10); } } /* if we were given HNP contact info, parse it and * setup the process_info struct with that info */ if (NULL != my_globals.hnp_uri) { if (0 == strncmp(my_globals.hnp_uri, "file", strlen("file")) || 0 == strncmp(my_globals.hnp_uri, "FILE", strlen("FILE"))) { char input[1024], *filename; FILE *fp; /* it is a file - get the filename */ filename = strchr(my_globals.hnp_uri, ':'); if (NULL == filename) { /* filename is not correctly formatted */ orte_show_help("help-openrcm-runtime.txt", "hnp-filename-bad", true, "uri", my_globals.hnp_uri); goto cleanup; } ++filename; /* space past the : */ if (0 >= strlen(filename)) { /* they forgot to give us the name! */ orte_show_help("help-openrcm-runtime.txt", "hnp-filename-bad", true, "uri", my_globals.hnp_uri); goto cleanup; } /* open the file and extract the uri */ fp = fopen(filename, "r"); if (NULL == fp) { /* can't find or read file! */ orte_show_help("help-openrcm-runtime.txt", "hnp-filename-access", true, filename); goto cleanup; } if (NULL == fgets(input, 1024, fp)) { /* something malformed about file */ fclose(fp); orte_show_help("help-openrcm-runtime.txt", "hnp-file-bad", true, filename); goto cleanup; } fclose(fp); input[strlen(input)-1] = '\0'; /* remove newline */ /* put into the process info struct */ orte_process_info.my_hnp_uri = strdup(input); } else { /* should just be the uri itself */ orte_process_info.my_hnp_uri = strdup(my_globals.hnp_uri); } } if (OPAL_SUCCESS != opal_getcwd(cwd, sizeof(cwd))) { opal_output(orte_clean_output, "failed to get cwd\n"); return ORTE_ERR_NOT_FOUND; } /*************************** * We need all of OPAL and ORTE - this will * automatically connect us to the CM ***************************/ if (ORTE_SUCCESS != orcm_init(ORCM_TOOL)) { orcm_finalize(); return 1; } /* if we were given the hnp uri, extract the job family for the * master id */ if (NULL != my_globals.hnp_uri) { master = ORTE_JOB_FAMILY(ORTE_PROC_MY_HNP->jobid); } /* register to receive responses */ if (ORCM_SUCCESS != (ret = orcm_pnp.register_receive("orcm-stop", "0.1", "alpha", ORCM_PNP_GROUP_INPUT_CHANNEL, ORCM_PNP_TAG_TOOL, ack_recv, NULL))) { ORTE_ERROR_LOG(ret); goto cleanup; } /* announce my existence */ if (ORCM_SUCCESS != (ret = orcm_pnp.announce("orcm-stop", "0.1", "alpha", NULL))) { ORTE_ERROR_LOG(ret); goto cleanup; } /* setup the buffer to send our cmd */ buf = OBJ_NEW(opal_buffer_t); /* indicate the scheduler to be used */ jfam = master & 0x0000ffff; opal_dss.pack(buf, &jfam, 1, OPAL_UINT16); /* get the apps to stop */ inpt = NULL; opal_cmd_line_get_tail(&cmd_line, &count, &inpt); if (0 == count) { /* if no apps were given, then we stop the entire * DVM itself by telling the daemon's to terminate */ if (ORCM_SUCCESS != (ret = orcm_pnp.output_nb(ORCM_PNP_SYS_CHANNEL, NULL, ORCM_PNP_TAG_TERMINATE, NULL, 0, buf, cbfunc, NULL))) { ORTE_ERROR_LOG(ret); } goto cleanup; } else { /* load the stop cmd */ opal_dss.pack(buf, &flag, 1, ORCM_TOOL_CMD_T); /* for each app */ for (i=0; NULL != inpt[i]; i++) { opal_dss.pack(buf, &inpt[i], 1, OPAL_STRING); /* pack the replicas to be stopped */ opal_dss.pack(buf, &my_globals.replicas, 1, OPAL_STRING); } opal_argv_free(inpt); if (ORCM_SUCCESS != (ret = orcm_pnp.output_nb(ORCM_PNP_SYS_CHANNEL, NULL, ORCM_PNP_TAG_TOOL, NULL, 0, buf, cbfunc, NULL))) { ORTE_ERROR_LOG(ret); } } /* now wait for ack */ opal_event_dispatch(opal_event_base); /*************** * Cleanup ***************/ cleanup: orcm_finalize(); return ret; }
int orcm_init(orcm_proc_type_t flags) { int ret; char *error; int i, spin; if (NULL != getenv("ORCM_MCA_spin")) { spin = 1; /* spin until a debugger can attach */ while (0 != spin) { ret = 0; while (ret < 10000) { ret++; }; } } if (!orcm_util_initialized) { orcm_init_util(); } /* set the default leader policy */ orcm_default_leader_policy.jobid = ORTE_JOBID_WILDCARD; orcm_default_leader_policy.vpid = ORTE_VPID_WILDCARD; /* get the number of max msgs */ mca_base_param_reg_int_name("orcm", "max_buffered_msgs", "Number of recvd messages to hold in storage from each source", false, false, ORCM_MAX_MSG_RING_SIZE, &orcm_max_msg_ring_size); /* independent mode or not */ mca_base_param_reg_int_name("orcm", "sched_kill_dvm", "Whether or not scheduler kills associated daemons upon termination (default: no)", false, false, (int)false, &ret); orcm_sched_kill_dvm = OPAL_INT_TO_BOOL(ret); /* setup the globals that require initialization */ orcm_triplets = OBJ_NEW(orcm_triplets_array_t); #ifdef HAVE_QSYSTEM_H #ifdef Q_SYSTEM_INTFCS_TO_PROBE_FOR_IP_ADDRESS { char *eth_ifs[] = Q_SYSTEM_INTFCS_TO_PROBE_FOR_IP_ADDRESS; char **adds=NULL, *ifs, *envar; int i, num_ifs; num_ifs = sizeof(eth_ifs) / sizeof(eth_ifs[0]); for (i=0; i < num_ifs; i++) { opal_argv_append_nosize(&adds, eth_ifs[i]); } ifs = opal_argv_join(adds, ','); opal_argv_free(adds); /* push it into the environ so that the rmcast framework can get it */ asprintf(&envar, "OMPI_MCA_rmcast_base_if_include=%s", ifs); putenv(envar); /* cannot release envar as the environ doesn't keep its own copy */ free(ifs); } #endif #endif /* initialize us */ if (ORTE_SUCCESS != (ret = orte_init(NULL, NULL, flags))) { error = "orte_init"; goto error; } if (!ORCM_PROC_IS_TOOL) { opal_set_using_threads(true); } if (!ORCM_PROC_IS_APP) { trap_signals(); } orcm_initialized = true; return ORCM_SUCCESS; error: if (ORCM_ERR_SILENT != ret) { orte_show_help("help-openrcm-runtime.txt", "orcm_init:startup:internal-failure", true, error, ORTE_ERROR_NAME(ret), ret); } return ret; }