int spawn_fn(const pmix_proc_t *proc, const pmix_info_t job_info[], size_t ninfo, const pmix_app_t apps[], size_t napps, pmix_spawn_cbfunc_t cbfunc, void *cbdata) { release_cbdata *cb = malloc(sizeof(release_cbdata)); cb->status = PMIX_SUCCESS; cb->cbfunc = cbfunc; cb->cbdata = cbdata; PMIx_server_register_nspace("foobar", napps, NULL, 0, release_cb, (void*)cb); return PMIX_SUCCESS; }
static void set_namespace(int nprocs, char *ranks, char *name) { size_t ninfo; pmix_info_t *info; ninfo = 8; char *regex, *ppn; PMIX_INFO_CREATE(info, ninfo); (void)strncpy(info[0].key, PMIX_UNIV_SIZE, PMIX_MAX_KEYLEN); info[0].value.type = PMIX_UINT32; info[0].value.data.uint32 = nprocs; (void)strncpy(info[1].key, PMIX_SPAWNED, PMIX_MAX_KEYLEN); info[1].value.type = PMIX_UINT32; info[1].value.data.uint32 = 0; (void)strncpy(info[2].key, PMIX_LOCAL_SIZE, PMIX_MAX_KEYLEN); info[2].value.type = PMIX_UINT32; info[2].value.data.uint32 = nprocs; (void)strncpy(info[3].key, PMIX_LOCAL_PEERS, PMIX_MAX_KEYLEN); info[3].value.type = PMIX_STRING; info[3].value.data.string = strdup(ranks); PMIx_generate_regex(NODE_NAME, ®ex); (void)strncpy(info[4].key, PMIX_NODE_MAP, PMIX_MAX_KEYLEN); info[4].value.type = PMIX_STRING; info[4].value.data.string = regex; PMIx_generate_ppn(ranks, &ppn); (void)strncpy(info[5].key, PMIX_PROC_MAP, PMIX_MAX_KEYLEN); info[5].value.type = PMIX_STRING; info[5].value.data.string = ppn; (void)strncpy(info[6].key, PMIX_JOB_SIZE, PMIX_MAX_KEYLEN); info[6].value.type = PMIX_UINT32; info[6].value.data.uint32 = nprocs; (void)strncpy(info[7].key, PMIX_APPNUM, PMIX_MAX_KEYLEN); info[7].value.type = PMIX_UINT32; info[7].value.data.uint32 = getpid (); int in_progress = 1, rc; if (PMIX_SUCCESS == (rc = PMIx_server_register_nspace(name, nprocs, info, ninfo, release_cb, &in_progress))) { PMIX_WAIT_FOR_COMPLETION(in_progress); } PMIX_INFO_FREE(info, ninfo); }
int pmixp_libpmix_job_set(void) { List lresp; pmix_info_t *info; int ninfo; ListIterator it; pmix_info_t *kvp; int i, rc; uid_t uid = pmixp_info_jobuid(); gid_t gid = pmixp_info_jobgid(); _register_caddy_t *register_caddy; register_caddy = xmalloc(sizeof(_register_caddy_t)*(pmixp_info_tasks_loc()+1)); pmixp_debug_hang(0); /* Use list to safely expand/reduce key-value pairs. */ lresp = list_create(pmixp_xfree_xmalloced); _general_proc_info(lresp); _set_tmpdirs(lresp); _set_procdatas(lresp); _set_sizeinfo(lresp); if (SLURM_SUCCESS != _set_mapsinfo(lresp)) { list_destroy(lresp); PMIXP_ERROR("Can't build nodemap"); return SLURM_ERROR; } _set_localinfo(lresp); ninfo = list_count(lresp); PMIX_INFO_CREATE(info, ninfo); it = list_iterator_create(lresp); i = 0; while (NULL != (kvp = list_next(it))) { info[i] = *kvp; i++; } list_destroy(lresp); register_caddy[0].active = 1; rc = PMIx_server_register_nspace(pmixp_info_namespace(), pmixp_info_tasks_loc(), info, ninfo, _release_cb, ®ister_caddy[0]); if (PMIX_SUCCESS != rc) { PMIXP_ERROR("Cannot register namespace %s, nlocalproc=%d, " "ninfo = %d", pmixp_info_namespace(), pmixp_info_tasks_loc(), ninfo); return SLURM_ERROR; } PMIXP_DEBUG("task initialization"); for (i = 0; i < pmixp_info_tasks_loc(); i++) { pmix_proc_t proc; register_caddy[i+1].active = 1; strncpy(proc.nspace, pmixp_info_namespace(), PMIX_MAX_NSLEN); proc.rank = pmixp_info_taskid(i); rc = PMIx_server_register_client(&proc, uid, gid, NULL, _release_cb, ®ister_caddy[i + 1]); if (PMIX_SUCCESS != rc) { PMIXP_ERROR("Cannot register client %d(%d) in namespace %s", pmixp_info_taskid(i), i, pmixp_info_namespace()); return SLURM_ERROR; } } /* wait for all registration actions to finish */ while( 1 ){ int exit_flag = 1; struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 100; for(i=0; i < pmixp_info_tasks_loc() + 1; i++){ if( register_caddy[i].active ){ exit_flag = 0; } } if( exit_flag ){ break; } nanosleep(&ts, NULL); } PMIX_INFO_FREE(info, ninfo); xfree(register_caddy); return SLURM_SUCCESS; }