int main(int argc, char **argv) { pmix_status_t rc; pmix_info_t *info, *iptr; pmix_app_t *app; size_t ninfo, napps; char *nspace = NULL; int i; pmix_query_t *query; size_t nq, n; myquery_data_t myquery_data; bool cospawn = false, stop_on_exec = false, cospawn_reqd = false; char cwd[1024]; pmix_status_t code = PMIX_ERR_JOB_TERMINATED; mylock_t mylock; myrel_t myrel, launcher_ready, dbrel; pid_t pid; pmix_envar_t envar; char *launchers[] = { "prun", "mpirun", "mpiexec", "orterun", NULL }; pmix_proc_t proc; bool found; pmix_data_array_t darray; char *tmp; char clientspace[PMIX_MAX_NSLEN+1]; pid = getpid(); /* Process any arguments we were given */ for (i=1; i < argc; i++) { if (0 == strcmp(argv[i], "-h") || 0 == strcmp(argv[i], "--help")) { /* print the usage message and exit */ } if (0 == strcmp(argv[i], "-a") || 0 == strcmp(argv[i], "--attach")) { if (NULL != nspace) { /* can only support one */ fprintf(stderr, "Cannot attach to more than one nspace\n"); exit(1); } /* the next argument must be the nspace */ ++i; if (argc == i) { /* they goofed */ fprintf(stderr, "The %s option requires an <nspace> argument\n", argv[i]); exit(1); } nspace = strdup(argv[i]); } else if (0 == strcmp(argv[i], "-c") || 0 == strcmp(argv[i], "--cospawn")){ cospawn_reqd = true; break; } } info = NULL; ninfo = 0; /* use the system connection first, if available */ PMIX_INFO_CREATE(info, 1); PMIX_INFO_LOAD(&info[0], PMIX_CONNECT_SYSTEM_FIRST, NULL, PMIX_BOOL); /* init as a tool */ if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, info, ninfo))) { fprintf(stderr, "PMIx_tool_init failed: %s(%d)\n", PMIx_Error_string(rc), rc); exit(rc); } PMIX_INFO_FREE(info, ninfo); fprintf(stderr, "Debugger ns %s rank %d pid %lu: Running\n", myproc.nspace, myproc.rank, (unsigned long)pid); /* construct the debugger termination release */ DEBUG_CONSTRUCT_LOCK(&dbrel.lock); /* register a default event handler */ DEBUG_CONSTRUCT_LOCK(&mylock); PMIx_Register_event_handler(NULL, 0, NULL, 0, notification_fn, evhandler_reg_callbk, (void*)&mylock); DEBUG_WAIT_THREAD(&mylock); DEBUG_DESTRUCT_LOCK(&mylock); /* if we are attaching to a running job, then attach to it */ if (NULL != nspace) { if (PMIX_SUCCESS != (rc = attach_to_running_job(nspace))) { fprintf(stderr, "Failed to attach to nspace %s: error code %d\n", nspace, rc); goto done; } } done: DEBUG_DESTRUCT_LOCK(&myrel.lock); DEBUG_DESTRUCT_LOCK(&dbrel.lock); PMIx_tool_finalize(); return(rc); }
int main(int argc, char **argv) { pmix_status_t rc; pmix_proc_t myproc; pmix_info_t *info; pmix_app_t *app; size_t ninfo, napps; /* check for user directives - this would include: * - a flag indicating we want to attach to a specified application * - application info if we are launching a new app */ /* init us - if a PMIx server pid was provided, then pass it along */ if (0 < server_pid) { ninfo = 1; PMIX_INFO_CREATE(info, ninfo); PMIX_INFO_LOAD(&info[0], PMIX_SERVER_PIDINFO, server_pid, PMIX_UINT32); } else { info = NULL; ninfo = 0; } if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, info, ninfo))) { fprintf(stderr, "PMIx_tool_init failed: %d\n", rc); exit(rc); } if (0 < ninfo) { PMIX_INFO_FREE(info, ninfo); } fprintf(stderr, "Tool ns %s rank %d: Running\n", myproc.nspace, myproc.rank); /* if we are attaching to a running job, then attach to it */ if (attach) { ret = attach_to_running_job(argv[1]); } else { /* this is an initial launch - we need to launch the application * plus the debugger daemons, letting the RM know we are debugging * so that it will "pause" the app procs until we are ready */ napps = 2; PMIX_APP_CREATE(app, napps); /* setup the executable */ app[0].cmd = strdup("app"); app[0].argc = 1; app[0].argv = (char**)malloc(2*sizeof(char*)); app[0].argv[0] = strdup("app"); app[0].argv[1] = NULL; /* provide directives so the apps do what the user requested */ ninfo = 2; PMIX_INFO_CREATE(app[0].info, ninfo); PMIX_INFO_LOAD(&app[0].info[0], PMIX_NP, 128, PMIX_UINT64); PMIX_INFO_LOAD(&app[0].info[0], PMIX_MAPBY, "slot", PMIX_STRING); /* setup the name of the daemon executable to launch */ app[1].cmd = strdup("debuggerdaemon"); app[1].argc = 1; app[1].argv = (char**)malloc(2*sizeof(char*)); app[1].argv[0] = strdup("debuggerdaemon"); app[1].argv[1] = NULL; /* provide directives so the daemons go where we want, and * let the RM know these are debugger daemons */ ninfo = 2; PMIX_INFO_CREATE(app[1].info, ninfo); PMIX_INFO_LOAD(&app[1].info[0], PMIX_MAPBY, "ppr:1:node", PMIX_STRING); // instruct the RM to launch one copy of the executable on each node PMIX_INFO_LOAD(&app[1].info[1], PMIX_DEBUGGER_DAEMONS, true, PMIX_BOOL); // these are debugger daemons /* spawn the daemons */ PMIx_Spawn(NULL, 0, app, napps, dspace); /* cleanup */ PMIX_APP_FREE(app, napps); /* this is where a debugger tool would wait until the debug operation is complete */ } done: PMIx_tool_finalize(NULL, 0); return(ret); }