int lookup_fn(const pmix_proc_t *proc, char **keys, const pmix_info_t info[], size_t ninfo, pmix_lookup_cbfunc_t cbfunc, void *cbdata) { size_t i, ndata, ret; pmix_pdata_t *pdata; pmix_test_info_t *tinfo; if (NULL == pmix_test_published_list) { return PMIX_ERR_NOT_FOUND; } ndata = pmix_argv_count(keys); PMIX_PDATA_CREATE(pdata, ndata); ret = 0; for (i = 0; i < ndata; i++) { PMIX_LIST_FOREACH(tinfo, pmix_test_published_list, pmix_test_info_t) { if (0 == strcmp(tinfo->data.key, keys[i])) { (void)strncpy(pdata[i].proc.nspace, tinfo->namespace_published, PMIX_MAX_NSLEN); pdata[i].proc.rank = tinfo->rank_published; (void)strncpy(pdata[i].key, keys[i], strlen(keys[i])+1); pmix_value_xfer(&pdata[i].value, &tinfo->data.value); ret++; break; } } } if (NULL != cbfunc) { cbfunc((ret == ndata) ? PMIX_SUCCESS : PMIX_ERR_NOT_FOUND, pdata, ndata, cbdata); } PMIX_PDATA_FREE(pdata, ndata); return PMIX_SUCCESS; }
static void wait_lookup_cbfunc(struct pmix_peer_t *pr, pmix_ptl_hdr_t *hdr, pmix_buffer_t *buf, void *cbdata) { pmix_cb_t *cb = (pmix_cb_t*)cbdata; pmix_status_t rc, ret; int32_t cnt; pmix_pdata_t *pdata; size_t ndata; pmix_output_verbose(2, pmix_globals.debug_output, "pmix:client recv callback activated with %d bytes", (NULL == buf) ? -1 : (int)buf->bytes_used); if (NULL == cb->lookup_cbfunc) { /* nothing we can do with this */ PMIX_RELEASE(cb); return; } /* set the defaults */ pdata = NULL; ndata = 0; /* unpack the returned status */ cnt = 1; if (PMIX_SUCCESS != (rc = pmix_bfrop.unpack(buf, &ret, &cnt, PMIX_STATUS))) { PMIX_ERROR_LOG(rc); ret = rc; } if (PMIX_SUCCESS != ret) { if (NULL != cb->lookup_cbfunc) { cb->lookup_cbfunc(ret, NULL, 0, cb->cbdata); } PMIX_RELEASE(cb); return; } /* unpack the number of returned values */ cnt = 1; if (PMIX_SUCCESS != (rc = pmix_bfrop.unpack(buf, &ndata, &cnt, PMIX_SIZE))) { PMIX_ERROR_LOG(rc); PMIX_RELEASE(cb); return; } if (0 < ndata) { /* create the array storage */ PMIX_PDATA_CREATE(pdata, ndata); cnt = ndata; /* unpack the returned values into the pdata array */ if (PMIX_SUCCESS != (rc = pmix_bfrop.unpack(buf, pdata, &cnt, PMIX_PDATA))) { PMIX_ERROR_LOG(rc); goto cleanup; } } if (NULL != cb->lookup_cbfunc) { cb->lookup_cbfunc(rc, pdata, ndata, cb->cbdata); } cleanup: /* cleanup */ PMIX_PDATA_FREE(pdata, ndata); PMIX_RELEASE(cb); }
/* allocate and return a string containing the current job id */ char* scr_env_jobid() { char* jobid = NULL; char* value; #ifdef SCR_RESOURCE_MANAGER_SLURM /* read $SLURM_JOBID environment variable for jobid string */ if ((value = getenv("SLURM_JOBID")) != NULL) { jobid = strdup(value); if (jobid == NULL) { scr_err("Failed to allocate memory to record jobid (%s) @ %s:%d", value, __FILE__, __LINE__ ); } } #endif #ifdef SCR_RESOURCE_MANAGER_APRUN /* read $PBS_JOBID environment variable for jobid string */ if ((value = getenv("PBS_JOBID")) != NULL) { jobid = strdup(value); if (jobid == NULL) { scr_err("Failed to allocate memory to record jobid (%s) @ %s:%d", value, __FILE__, __LINE__ ); } } #endif #ifdef SCR_RESOURCE_MANAGER_PMIX /* todo: must replace this in the scr_env script as well */ pmix_pdata_t *pmix_query_data = NULL; PMIX_PDATA_CREATE(pmix_query_data, 1); /* todo: pmix_pdata_destroy ?? */ /* specify that we want our jobid from pmix */ strncpy(pmix_query_data[0].key, PMIX_JOBID, PMIX_MAX_KEYLEN); /* query pmix for our job id */ pmix_status_t retval = PMIx_Lookup(pmix_query_data, 1, NULL, 0); if (retval == PMIX_SUCCESS) { /* got it, strdup the value from pmix */ jobid = strdup(pmix_query_data[0].value.data.string); scr_dbg(1, "PMIx_Lookup for jobid success '%s'", jobid); } else { /* failed to get our jobid from pmix, make one up */ char *pmix_hardcoded_id = "pmix_hardcoded_jobid"; jobid = strdup(pmix_hardcoded_id); scr_dbg(1, "PMIx_Lookup for jobid failed: rc=%d, using hardcoded jobid '%s'", retval, jobid ); } /* free pmix query structure */ PMIX_PDATA_FREE(pmix_query_data, 1); #endif #ifdef SCR_RESOURCE_MANAGER_LSF /* read $PBS_JOBID environment variable for jobid string */ if ((value = getenv("LSB_JOBID")) != NULL) { jobid = strdup(value); if (jobid == NULL) { scr_err("Failed to allocate memory to record jobid (%s) @ %s:%d", value, __FILE__, __LINE__ ); } } #endif return jobid; }
int main(int argc, char **argv) { int rc; pmix_value_t value; pmix_value_t *val = &value; pmix_proc_t proc; uint32_t nprocs; pmix_info_t *info; pmix_pdata_t *pdata; pmix_proc_t myproc; /* init us */ if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc))) { pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", myproc.nspace, myproc.rank, rc); exit(0); } pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank); /* get our universe size */ if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, PMIX_UNIV_SIZE, NULL, 0, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc); goto done; } nprocs = val->data.uint32; PMIX_VALUE_RELEASE(val); pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs); /* call fence to ensure the data is received */ PMIX_PROC_CONSTRUCT(&proc); (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) { pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc); goto done; } /* publish something */ if (0 == myproc.rank) { PMIX_INFO_CREATE(info, 2); (void)strncpy(info[0].key, "FOOBAR", PMIX_MAX_KEYLEN); info[0].value.type = PMIX_UINT8; info[0].value.data.uint8 = 1; (void)strncpy(info[1].key, "PANDA", PMIX_MAX_KEYLEN); info[1].value.type = PMIX_SIZE; info[1].value.data.size = 123456; if (PMIX_SUCCESS != (rc = PMIx_Publish(info, 2))) { pmix_output(0, "Client ns %s rank %d: PMIx_Publish failed: %d", myproc.nspace, myproc.rank, rc); goto done; } PMIX_INFO_FREE(info, 2); } /* call fence again so all procs know the data * has been published */ if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) { pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc); goto done; } /* lookup something */ if (0 != myproc.rank) { PMIX_PDATA_CREATE(pdata, 1); (void)strncpy(pdata[0].key, "FOOBAR", PMIX_MAX_KEYLEN); if (PMIX_SUCCESS != (rc = PMIx_Lookup(pdata, 1, NULL, 0))) { pmix_output(0, "Client ns %s rank %d: PMIx_Lookup failed: %d", myproc.nspace, myproc.rank, rc); goto done; } /* check the return for value and source */ if (0 != strncmp(myproc.nspace, pdata[0].proc.nspace, PMIX_MAX_NSLEN)) { pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong nspace: %s", myproc.nspace, myproc.rank, pdata[0].proc.nspace); goto done; } if (0 != pdata[0].proc.rank) { pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong rank: %d", myproc.nspace, myproc.rank, pdata[0].proc.rank); goto done; } if (PMIX_UINT8 != pdata[0].value.type) { pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong type: %d", myproc.nspace, myproc.rank, pdata[0].value.type); goto done; } if (1 != pdata[0].value.data.uint8) { pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong value: %d", myproc.nspace, myproc.rank, (int)pdata[0].value.data.uint8); goto done; } PMIX_PDATA_FREE(pdata, 1); pmix_output(0, "PUBLISH-LOOKUP SUCCEEDED"); } /* call fence again so rank 0 waits before leaving */ if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) { pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc); goto done; } if (0 == myproc.rank) { char **keys = NULL; pmix_argv_append_nosize(&keys, "FOOBAR"); pmix_argv_append_nosize(&keys, "PANDA"); if (PMIX_SUCCESS != (rc = PMIx_Unpublish(keys, NULL, 0))) { pmix_output(0, "Client ns %s rank %d: PMIx_Unpublish failed: %d", myproc.nspace, myproc.rank, rc); goto done; } pmix_output(0, "UNPUBLISH SUCCEEDED"); } /* call fence again so everyone waits for rank 0 before leaving */ proc.rank = PMIX_RANK_WILDCARD; if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) { pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc); goto done; } done: /* finalize us */ pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank); if (PMIX_SUCCESS != (rc = PMIx_Finalize())) { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc); } else { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank); } fflush(stderr); return(0); }
static void wait_lookup_cbfunc(struct pmix_peer_t *pr, pmix_ptl_hdr_t *hdr, pmix_buffer_t *buf, void *cbdata) { pmix_cb_t *cb = (pmix_cb_t*)cbdata; pmix_status_t rc, ret; int32_t cnt; pmix_pdata_t *pdata; size_t ndata; PMIX_ACQUIRE_OBJECT(cb); pmix_output_verbose(2, pmix_globals.debug_output, "pmix:client recv callback activated with %d bytes", (NULL == buf) ? -1 : (int)buf->bytes_used); /* set the defaults */ pdata = NULL; ndata = 0; if (NULL == cb->cbfunc.lookupfn) { /* nothing we can do with this */ PMIX_RELEASE(cb); return; } if (NULL == buf) { rc = PMIX_ERR_BAD_PARAM; goto report; } /* a zero-byte buffer indicates that this recv is being * completed due to a lost connection */ if (PMIX_BUFFER_IS_EMPTY(buf)) { rc = PMIX_ERR_UNREACH; goto report; } /* unpack the returned status */ cnt = 1; PMIX_BFROPS_UNPACK(rc, pmix_client_globals.myserver, buf, &ret, &cnt, PMIX_STATUS); if (PMIX_SUCCESS != rc) { PMIX_ERROR_LOG(rc); ret = rc; } if (PMIX_SUCCESS != ret) { if (NULL != cb->cbfunc.lookupfn) { cb->cbfunc.lookupfn(ret, NULL, 0, cb->cbdata); } PMIX_RELEASE(cb); return; } /* unpack the number of returned values */ cnt = 1; PMIX_BFROPS_UNPACK(rc, pmix_client_globals.myserver, buf, &ndata, &cnt, PMIX_SIZE); if (PMIX_SUCCESS != rc) { PMIX_ERROR_LOG(rc); PMIX_RELEASE(cb); return; } if (0 < ndata) { /* create the array storage */ PMIX_PDATA_CREATE(pdata, ndata); cnt = ndata; /* unpack the returned values into the pdata array */ PMIX_BFROPS_UNPACK(rc, pmix_client_globals.myserver, buf, pdata, &cnt, PMIX_PDATA); if (PMIX_SUCCESS != rc) { PMIX_ERROR_LOG(rc); goto cleanup; } } report: if (NULL != cb->cbfunc.lookupfn) { cb->cbfunc.lookupfn(rc, pdata, ndata, cb->cbdata); } cleanup: /* cleanup */ if (NULL != pdata) { PMIX_PDATA_FREE(pdata, ndata); } PMIX_RELEASE(cb); }