/* KVS_Put - we default to PMIX_GLOBAL scope */ PMIX_EXPORT int PMI2_KVS_Put(const char key[], const char value[]) { pmix_status_t rc = PMIX_SUCCESS; pmix_value_t val; PMI2_CHECK(); if ((NULL == key) || (NULL == value)) { return PMI2_ERR_INVALID_ARG; } if (pmi2_singleton) { return PMI2_SUCCESS; } pmix_output_verbose(3, pmix_globals.debug_output, "PMI2_KVS_Put: key=%s value=%s", key, value); val.type = PMIX_STRING; val.data.string = (char*)value; if (PMIX_SUCCESS == (rc = PMIx_Put(PMIX_GLOBAL, key, &val))) { commit_reqd = true; } return convert_err(rc); }
/* KVS_Put - we default to PMIX_GLOBAL scope and ignore the * provided kvsname as we only put into our own nspace */ PMIX_EXPORT int PMI_KVS_Put(const char kvsname[], const char key[], const char value[]) { pmix_status_t rc = PMIX_SUCCESS; pmix_value_t val; PMI_CHECK(); if ((kvsname == NULL) || (strlen(kvsname) > PMI_MAX_KVSNAME_LEN)) { return PMI_ERR_INVALID_KVS; } if ((key == NULL) || (strlen(key) >PMI_MAX_KEY_LEN)) { return PMI_ERR_INVALID_KEY; } if ((value == NULL) || (strlen(value) > PMI_MAX_VAL_LEN)) { return PMI_ERR_INVALID_VAL; } if (pmi_singleton) { return PMI_SUCCESS; } pmix_output_verbose(2, pmix_globals.debug_output, "PMI_KVS_Put: KVS=%s, key=%s value=%s", kvsname, key, value); val.type = PMIX_STRING; val.data.string = (char*)value; rc = PMIx_Put(PMIX_GLOBAL, key, &val); return convert_err(rc); }
int main(int argc, char **argv) { int spawned; int rc; /* init us */ if (PMI_SUCCESS != (rc = PMI_Init(&spawned))) { fprintf(stderr, "PMI_Init failed: %d\n", rc); return rc; } #if 0 key = "local-key"; PMIX_VAL_SET(&value, int, 12345, rc, kvp_error ); if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, key, &value))) { fprintf(stderr, "PMIx_Put failed: %d\n", rc); } key = "remote-key"; char *ptr = "Test string"; PMIX_VAL_SET(&value, string, ptr, rc, kvp_error ); if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, key, &value))) { fprintf(stderr, "PMIx_Put failed: %d\n", rc); } key = "global-key"; PMIX_VAL_SET(&value, float, 10.15, rc, kvp_error ); if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, key, &value))) { fprintf(stderr, "PMIx_Put failed: %d\n", rc); } /* Submit the data */ pmix_range_t range; range.ranks = NULL; range.nranks = 0; if (PMIX_SUCCESS != (rc = PMIx_Fence(NULL, 0))) { fprintf(stderr, "PMIx_Fence failed: %d\n", rc); return rc; } #endif /* finalize us */ if (PMI_SUCCESS != (rc = PMI_Finalize())) { fprintf(stderr, "PMI_Finalize failed: %d\n", rc); } return rc; }
/* push info at the PMIX_LOCAL scope */ int PMI2_Info_PutNodeAttr(const char name[], const char value[]) { pmix_status_t rc; pmix_value_t val; val.type = PMIX_STRING; val.data.string = (char*)value; rc = PMIx_Put(PMIX_LOCAL, name, &val); return convert_err(rc); }
/* KVS_Put - we default to PMIX_GLOBAL scope */ int PMI2_KVS_Put(const char key[], const char value[]) { pmix_status_t rc; pmix_value_t val; val.type = PMIX_STRING; val.data.string = (char*)value; rc = PMIx_Put(PMIX_GLOBAL, key, &val); return convert_err(rc); }
void pmi_put_double(char *key, double v) { pmix_value_t value; int rc; value.type = PMIX_DOUBLE; value.data.dval = v; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, key, &value))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d", this_proc.nspace, this_proc.rank, rc); abort(); } }
static void _put_key(char *key, int *key_val, int key_size, pmix_scope_t scope) { pmix_value_t value; int rc; value.type = PMIX_BYTE_OBJECT; value.data.bo.size = key_size * sizeof(int); value.data.bo.bytes = (char*)key_val; if (PMIX_SUCCESS != (rc = PMIx_Put(scope, key, &value))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d", this_proc.nspace, this_proc.rank, rc); abort(); } }
/* push info at the PMIX_LOCAL scope */ int PMI2_Info_PutNodeAttr(const char name[], const char value[]) { pmix_status_t rc = PMIX_SUCCESS; pmix_value_t val; PMI2_CHECK(); if ((NULL == name) || (NULL == value)) { return PMI2_ERR_INVALID_ARG; } val.type = PMIX_STRING; val.data.string = (char*)value; rc = PMIx_Put(PMIX_LOCAL, name, &val); return convert_err(rc); }
int main(int argc, char **argv) { int rc; pmix_value_t value; pmix_value_t *val = &value; char *tmp; pmix_proc_t proc; uint32_t nprocs, n; pmix_info_t *info; bool flag; volatile int active; pmix_status_t dbg = PMIX_ERR_DEBUGGER_RELEASE; /* init us - note that the call to "init" includes the return of * any job-related info provided by the RM. This includes any * debugger flag instructing us to stop-in-init. If such a directive * is included, then the process will be stopped in this call until * the "debugger release" notification arrives */ if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %d\n", myproc.nspace, myproc.rank, rc); exit(0); } fprintf(stderr, "Client ns %s rank %d: Running\n", myproc.nspace, myproc.rank); /* register our default event handler - again, this isn't strictly * required, but is generally good practice */ active = -1; PMIx_Register_event_handler(NULL, 0, NULL, 0, notification_fn, evhandler_reg_callbk, (void*)&active); while (-1 == active) { sleep(1); } if (0 != active) { fprintf(stderr, "[%s:%d] Default handler registration failed\n", myproc.nspace, myproc.rank); exit(active); } /* job-related info is found in our nspace, assigned to the * wildcard rank as it doesn't relate to a specific rank. Setup * a name to retrieve such values */ PMIX_PROC_CONSTRUCT(&proc); (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; /* check to see if we have been instructed to wait for a debugger * to attach to us. We won't get both a stop-in-init AND a * wait-for-notify directive, so we should never stop twice. This * directive is provided so that something like an MPI implementation * can do some initial setup in MPI_Init prior to pausing for the * debugger */ if (PMIX_SUCCESS == (rc = PMIx_Get(&proc, PMIX_DEBUG_WAIT_FOR_NOTIFY, NULL, 0, &val))) { /* register for debugger release */ active = -1; PMIx_Register_event_handler(&dbg, 1, NULL, 0, release_fn, evhandler_reg_callbk, (void*)&active); /* wait for registration to complete */ while (-1 == active) { sleep(1); } if (0 != active) { fprintf(stderr, "[%s:%d] Debug handler registration failed\n", myproc.nspace, myproc.rank); exit(active); } /* wait for debugger release */ while (waiting_for_debugger) { sleep(1); } } /* get our universe size */ if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get universe size failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } fprintf(stderr, "Client %s:%d universe size %d\n", myproc.nspace, myproc.rank, val->data.uint32); /* get the number of procs in our job - univ size is the total number of allocated * slots, not the number of procs in the job */ if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get job size failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } nprocs = val->data.uint32; PMIX_VALUE_RELEASE(val); fprintf(stderr, "Client %s:%d num procs %d\n", myproc.nspace, myproc.rank, nprocs); /* put a few values */ if (0 > asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank)) { exit(1); } value.type = PMIX_UINT32; value.data.uint32 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Store_internal failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } free(tmp); if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) { exit(1); } value.type = PMIX_UINT64; value.data.uint64 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } free(tmp); if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) { exit(1); } value.type = PMIX_STRING; value.data.string = "1234"; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } free(tmp); /* push the data to our PMIx server */ if (PMIX_SUCCESS != (rc = PMIx_Commit())) { fprintf(stderr, "Client ns %s rank %d: PMIx_Commit failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } /* call fence to synchronize with our peers - instruct * the fence operation to collect and return all "put" * data from our peers */ PMIX_INFO_CREATE(info, 1); flag = true; PMIX_INFO_LOAD(info, PMIX_COLLECT_DATA, &flag, PMIX_BOOL); if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, info, 1))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc); goto done; } PMIX_INFO_FREE(info, 1); /* check the returned data */ for (n=0; n < nprocs; n++) { if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) { exit(1); } if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, tmp, NULL, 0, &val))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, myproc.rank, tmp, rc); goto done; } if (PMIX_UINT64 != val->type) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n", myproc.nspace, myproc.rank, tmp, val->type); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } if (1234 != val->data.uint64) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %d\n", myproc.nspace, myproc.rank, tmp, (int)val->data.uint64); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, myproc.rank, tmp); PMIX_VALUE_RELEASE(val); free(tmp); if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) { exit(1); } if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, tmp, NULL, 0, &val))) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, myproc.rank, tmp, rc); goto done; } if (PMIX_STRING != val->type) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n", myproc.nspace, myproc.rank, tmp, val->type); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } if (0 != strcmp(val->data.string, "1234")) { fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %s\n", myproc.nspace, myproc.rank, tmp, val->data.string); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, myproc.rank, tmp); PMIX_VALUE_RELEASE(val); free(tmp); } done: /* finalize us */ fprintf(stderr, "Client ns %s rank %d: Finalizing\n", myproc.nspace, myproc.rank); if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) { 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); }
int main(int argc, char **argv) { int rc; pmix_value_t value; pmix_value_t *val = &value; char *tmp; pmix_proc_t proc; uint32_t n, num_gets; bool active; /* init us */ if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) { 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 */ (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, 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); /* put a few values */ (void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank); value.type = PMIX_UINT32; value.data.uint32 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Store_internal failed: %d", myproc.nspace, myproc.rank, rc); goto done; } (void)asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank); value.type = PMIX_UINT64; value.data.uint64 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %d", myproc.nspace, myproc.rank, rc); goto done; } (void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank); value.type = PMIX_STRING; value.data.string = "1234"; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %d", myproc.nspace, myproc.rank, rc); goto done; } /* introduce a delay by one rank so we can check what happens * if a "get" is received prior to data being provided */ if (0 == myproc.rank) { sleep(2); } /* commit the data to the server */ if (PMIX_SUCCESS != (rc = PMIx_Commit())) { pmix_output(0, "Client ns %s rank %d: PMIx_Commit failed: %d", myproc.nspace, myproc.rank, rc); goto done; } /* call fence_nb, but don't return any data */ PMIX_PROC_CONSTRUCT(&proc); (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; active = true; if (PMIX_SUCCESS != (rc = PMIx_Fence_nb(&proc, 1, NULL, 0, opcbfunc, &active))) { pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc); goto done; } /* get the committed data - ask for someone who doesn't exist as well */ num_gets = 0; for (n=0; n < nprocs; n++) { (void)asprintf(&tmp, "%s-%d-local", myproc.nspace, n); proc.rank = n; if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp, NULL, 0, valcbfunc, tmp))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s failed: %d", myproc.nspace, n, tmp, rc); goto done; } ++num_gets; (void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, n); if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp, NULL, 0, valcbfunc, tmp))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s failed: %d", myproc.nspace, n, tmp, rc); goto done; } ++num_gets; } /* wait for the first fence to finish */ PMIX_WAIT_FOR_COMPLETION(active); /* wait for all my "get" calls to complete */ while (getcount < num_gets) { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 100000; nanosleep(&ts, NULL); } /* call fence again so everyone waits 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(NULL, 0))) { 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); }
int main(int argc, char **argv) { int rc; pmix_value_t value; pmix_value_t *val = &value; char *tmp; pmix_proc_t proc; uint32_t nprocs, n; int cnt, j; bool doabort = false; volatile bool active; pmix_info_t info, *iptr; size_t ninfo; pmix_status_t code; if (1 < argc) { if (0 == strcmp("-abort", argv[1])) { doabort = true; } } /* init us and declare we are a test programming model */ PMIX_INFO_CREATE(iptr, 2); PMIX_INFO_LOAD(&iptr[0], PMIX_PROGRAMMING_MODEL, "TEST", PMIX_STRING); PMIX_INFO_LOAD(&iptr[1], PMIX_MODEL_LIBRARY_NAME, "PMIX", PMIX_STRING); if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, iptr, 2))) { pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); exit(rc); } PMIX_INFO_FREE(iptr, 2); pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank); /* test something */ (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); exit(rc); } PMIX_VALUE_RELEASE(val); /* test something */ if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, PMIX_SERVER_URI, NULL, 0, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); exit(rc); } pmix_output(0, "CLIENT SERVER URI: %s", val->data.string); PMIX_VALUE_RELEASE(val); /* register a handler specifically for when models declare */ active = true; ninfo = 1; PMIX_INFO_CREATE(iptr, ninfo); PMIX_INFO_LOAD(&iptr[0], PMIX_EVENT_HDLR_NAME, "SIMPCLIENT-MODEL", PMIX_STRING); code = PMIX_MODEL_DECLARED; PMIx_Register_event_handler(&code, 1, iptr, ninfo, model_callback, model_registration_callback, (void*)&active); while (active) { usleep(10); } PMIX_INFO_FREE(iptr, ninfo); /* register our errhandler */ active = true; PMIx_Register_event_handler(NULL, 0, NULL, 0, notification_fn, errhandler_reg_callbk, (void*)&active); while (active) { usleep(10); } /* get our universe size */ (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(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); /* put a few values */ (void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank); value.type = PMIX_UINT32; value.data.uint32 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Store_internal failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); goto done; } for (cnt=0; cnt < MAXCNT; cnt++) { (void)asprintf(&tmp, "%s-%d-local-%d", myproc.nspace, myproc.rank, cnt); value.type = PMIX_UINT64; value.data.uint64 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); goto done; } (void)asprintf(&tmp, "%s-%d-remote-%d", myproc.nspace, myproc.rank, cnt); value.type = PMIX_STRING; value.data.string = "1234"; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); goto done; } if (PMIX_SUCCESS != (rc = PMIx_Commit())) { pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Commit failed: %s", myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc)); goto done; } /* 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 cnt %d: PMIx_Fence failed: %s", myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc)); goto done; } /* check the returned data */ (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN); for (j=0; j <= cnt; j++) { for (n=0; n < nprocs; n++) { proc.rank = n; (void)asprintf(&tmp, "%s-%d-local-%d", myproc.nspace, n, j); if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) { pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s failed: %s", myproc.nspace, myproc.rank, j, tmp, PMIx_Error_string(rc)); continue; } if (NULL == val) { pmix_output(0, "Client ns %s rank %d: NULL value returned", myproc.nspace, myproc.rank); break; } if (PMIX_UINT64 != val->type) { pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned wrong type: %d", myproc.nspace, myproc.rank, j, tmp, val->type); PMIX_VALUE_RELEASE(val); free(tmp); continue; } if (1234 != val->data.uint64) { pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned wrong value: %d", myproc.nspace, myproc.rank, j, tmp, (int)val->data.uint64); PMIX_VALUE_RELEASE(val); free(tmp); continue; } pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned correct", myproc.nspace, myproc.rank, j, tmp); PMIX_VALUE_RELEASE(val); free(tmp); if (n != myproc.rank) { (void)asprintf(&tmp, "%s-%d-remote-%d", proc.nspace, n, j); if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) { /* this data should _not_ be found as we are on the same node * and the data was "put" with a PMIX_REMOTE scope */ pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned correct", myproc.nspace, myproc.rank, j, tmp); continue; } pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned remote data for a local proc", myproc.nspace, myproc.rank, j, tmp); PMIX_VALUE_RELEASE(val); free(tmp); } } } } /* now get the data blob for myself */ pmix_output(0, "Client ns %s rank %d testing internal modex blob", myproc.nspace, myproc.rank); if (PMIX_SUCCESS == (rc = PMIx_Get(&myproc, NULL, NULL, 0, &val))) { if (PMIX_DATA_ARRAY != val->type) { pmix_output(0, "Client ns %s rank %d did not return an array for its internal modex blob", myproc.nspace, myproc.rank); PMIX_VALUE_RELEASE(val); } else if (PMIX_INFO != val->data.darray->type) { pmix_output(0, "Client ns %s rank %d returned an internal modex array of type %s instead of PMIX_INFO", myproc.nspace, myproc.rank, PMIx_Data_type_string(val->data.darray->type)); PMIX_VALUE_RELEASE(val); } else if (0 == val->data.darray->size) { pmix_output(0, "Client ns %s rank %d returned an internal modex array of zero length", myproc.nspace, myproc.rank); PMIX_VALUE_RELEASE(val); } else { pmix_info_t *iptr = (pmix_info_t*)val->data.darray->array; for (n=0; n < val->data.darray->size; n++) { pmix_output(0, "\tKey: %s", iptr[n].key); } PMIX_VALUE_RELEASE(val); } } else { pmix_output(0, "Client ns %s rank %d internal modex blob FAILED with error %s(%d)", myproc.nspace, myproc.rank, PMIx_Error_string(rc), rc); } /* log something */ PMIX_INFO_CONSTRUCT(&info); PMIX_INFO_LOAD(&info, PMIX_LOG_STDERR, "test log msg", PMIX_STRING); active = true; rc = PMIx_Log_nb(&info, 1, NULL, 0, opcbfunc, (void*)&active); if (PMIX_SUCCESS != rc) { pmix_output(0, "Client ns %s rank %d - log_nb returned %s", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); } else { while (active) { usleep(10); } } PMIX_INFO_DESTRUCT(&info); /* if requested and our rank is 0, call abort */ if (doabort) { if (0 == myproc.rank) { PMIx_Abort(PMIX_ERR_PROC_REQUESTED_ABORT, "CALLING ABORT", NULL, 0); } else { while(!completed) { usleep(10); } } } done: /* finalize us */ pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank); if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %s\n", myproc.nspace, myproc.rank, PMIx_Error_string(rc)); } else { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank); } fflush(stderr); return(rc); }
int main(int argc, char **argv) { char nspace[PMIX_MAX_NSLEN+1]; int rank; int rc; pmix_value_t value; pmix_value_t *val = &value; char *tmp; pmix_proc_t proc; uint32_t nprocs, n; /* init us */ if (PMIX_SUCCESS != (rc = PMIx_Init(nspace, &rank))) { pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", nspace, rank, rc); exit(0); } pmix_output(0, "Client ns %s rank %d: Running", nspace, rank); /* get our universe size */ if (PMIX_SUCCESS != (rc = PMIx_Get(nspace, rank, PMIX_UNIV_SIZE, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", nspace, rank, rc); goto done; } nprocs = val->data.uint32; PMIX_VALUE_RELEASE(val); pmix_output(0, "Client %s:%d universe size %d", nspace, rank, nprocs); /* put a few values */ (void)asprintf(&tmp, "%s-%d-internal", nspace, rank); value.type = PMIX_UINT32; value.data.uint32 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Store_internal(nspace, rank, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Store_internal failed: %d", nspace, rank, rc); goto done; } (void)asprintf(&tmp, "%s-%d-local", nspace, rank); value.type = PMIX_UINT64; value.data.uint64 = 1234; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %d", nspace, rank, rc); goto done; } (void)asprintf(&tmp, "%s-%d-remote", nspace, rank); value.type = PMIX_STRING; value.data.string = "1234"; if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) { pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %d", nspace, rank, rc); goto done; } if (PMIX_SUCCESS != (rc = PMIx_Commit())) { pmix_output(0, "Client ns %s rank %d: PMIx_Commit failed: %d", nspace, rank, rc); goto done; } /* call fence to ensure the data is received */ PMIX_PROC_CONSTRUCT(&proc); (void)strncpy(proc.nspace, nspace, PMIX_MAX_NSLEN); proc.rank = PMIX_RANK_WILDCARD; if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, true))) { pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", nspace, rank, rc); goto done; } /* check the returned data */ for (n=0; n < nprocs; n++) { (void)asprintf(&tmp, "%s-%d-local", nspace, n); if (PMIX_SUCCESS != (rc = PMIx_Get(nspace, n, tmp, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s failed: %d", nspace, rank, tmp, rc); goto done; } if (PMIX_UINT64 != val->type) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d", nspace, rank, tmp, val->type); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } if (1234 != val->data.uint64) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %d", nspace, rank, tmp, (int)val->data.uint64); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } pmix_output(0, "Client ns %s rank %d: PMIx_Get %s returned correct", nspace, rank, tmp); PMIX_VALUE_RELEASE(val); free(tmp); (void)asprintf(&tmp, "%s-%d-remote", nspace, n); if (PMIX_SUCCESS != (rc = PMIx_Get(nspace, n, tmp, &val))) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s failed: %d", nspace, rank, tmp, rc); goto done; } if (PMIX_STRING != val->type) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d", nspace, rank, tmp, val->type); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } if (0 != strcmp(val->data.string, "1234")) { pmix_output(0, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %s", nspace, rank, tmp, val->data.string); PMIX_VALUE_RELEASE(val); free(tmp); goto done; } pmix_output(0, "Client ns %s rank %d: PMIx_Get %s returned correct", nspace, rank, tmp); PMIX_VALUE_RELEASE(val); free(tmp); } done: /* finalize us */ pmix_output(0, "Client ns %s rank %d: Finalizing", nspace, rank); if (PMIX_SUCCESS != (rc = PMIx_Finalize())) { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", nspace, rank, rc); } else { fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", nspace, rank); } fflush(stderr); return(0); }
int MPIDU_bc_table_create(int rank, int size, int *nodemap, void *bc, int bc_len, int same_len, int roots_only, void **bc_table, size_t ** bc_indices) { int rc, mpi_errno = MPI_SUCCESS; int start, end, i; char *val = NULL, *val_p; int out_len, val_len, rem, flag; pmix_value_t value, *pvalue; pmix_info_t *info; pmix_proc_t proc; int local_rank, local_leader; size_t my_bc_len = bc_len; MPIR_NODEMAP_get_local_info(rank, size, nodemap, &local_size, &local_rank, &local_leader); /* if business cards can be different length, use the max value length */ if (!same_len) bc_len = VALLEN; mpi_errno = MPIDU_shm_seg_alloc(bc_len * size, (void **) &segment, MPL_MEM_ADDRESS); if (mpi_errno) MPIR_ERR_POP(mpi_errno); mpi_errno = MPIDU_shm_seg_commit(&memory, &barrier, local_size, local_rank, local_leader, rank, MPL_MEM_ADDRESS); if (mpi_errno) MPIR_ERR_POP(mpi_errno); if (size == 1) { memcpy(segment, bc, my_bc_len); goto single; } val = MPL_malloc(VALLEN, MPL_MEM_ADDRESS); memset(val, 0, VALLEN); val_p = val; rem = VALLEN; rc = MPL_str_add_binary_arg(&val_p, &rem, "mpi", (char *) bc, my_bc_len); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**buscard"); MPIR_Assert(rem >= 0); if (!roots_only || rank == local_leader) { value.type = PMIX_STRING; value.data.string = val; rc = PMIx_Put(PMIX_LOCAL, "bc", &value); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**pmix_put"); rc = PMIx_Put(PMIX_REMOTE, "bc", &value); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**pmix_put"); rc = PMIx_Commit(); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**pmix_commit"); } PMIX_INFO_CREATE(info, 1); PMIX_INFO_LOAD(info, PMIX_COLLECT_DATA, &flag, PMIX_BOOL); rc = PMIx_Fence(&MPIR_Process.pmix_wcproc, 1, info, 1); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**pmix_fence"); PMIX_INFO_FREE(info, 1); if (!roots_only) { start = local_rank * (size / local_size); end = start + (size / local_size); if (local_rank == local_size - 1) end += size % local_size; for (i = start; i < end; i++) { PMIX_PROC_CONSTRUCT(&proc); MPL_strncpy(proc.nspace, MPIR_Process.pmix_proc.nspace, PMIX_MAX_NSLEN); proc.rank = i; rc = PMIx_Get(&proc, "bc", NULL, 0, &pvalue); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**pmix_get"); rc = MPL_str_get_binary_arg(val, "mpi", &segment[i * bc_len], bc_len, &out_len); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**argstr_missinghost"); PMIX_VALUE_RELEASE(pvalue); } } else { int num_nodes, *node_roots; MPIR_NODEMAP_get_node_roots(nodemap, size, &node_roots, &num_nodes); start = local_rank * (num_nodes / local_size); end = start + (num_nodes / local_size); if (local_rank == local_size - 1) end += num_nodes % local_size; for (i = start; i < end; i++) { PMIX_PROC_CONSTRUCT(&proc); MPL_strncpy(proc.nspace, MPIR_Process.pmix_proc.nspace, PMIX_MAX_NSLEN); proc.rank = i; rc = PMIx_Get(&proc, "bc", NULL, 0, &pvalue); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**pmix_get"); rc = MPL_str_get_binary_arg(val, "mpi", &segment[i * bc_len], bc_len, &out_len); MPIR_ERR_CHKANDJUMP(rc, mpi_errno, MPI_ERR_OTHER, "**argstr_missinghost"); PMIX_VALUE_RELEASE(pvalue); } } mpi_errno = MPIDU_shm_barrier(barrier, local_size); if (mpi_errno) MPIR_ERR_POP(mpi_errno); single: if (!same_len) { indices = MPL_malloc(size * sizeof(size_t), MPL_MEM_ADDRESS); for (i = 0; i < size; i++) indices[i] = bc_len * i; *bc_indices = indices; } fn_exit: MPL_free(val); *bc_table = segment; return mpi_errno; fn_fail: goto fn_exit; }
int main(int argc, char **argv) { pmix_status_t status; pmix_proc_t proc; sleep(30); status = PMIx_Init(&proc, NULL, 0); CHECK_ERROR(status, "PMIx_Init()"); printf("PMIx_Init() succeeded: nspace '%s' rank %d\n", proc.nspace, proc.rank); if (!PMIx_Initialized()) { printf("PMIx_Initialized() returned false.\n"); return -1; } printf("PMIx_Initialized() returned true.\n"); sleep(2); pmix_value_t val; PMIX_VAL_ASSIGN(&val, string, "My test value"); //PMIX_VAL_SET(&val, string, "My test value"); status = PMIx_Put(PMIX_GLOBAL, "MyStringKey", &val); CHECK_ERROR(status, "PMIx_Put(MyStringKey)"); sleep(2); PMIX_VAL_SET(&val, int, 42); status = PMIx_Put(PMIX_GLOBAL, "MyIntKey", &val); CHECK_ERROR(status, "PMIx_Put(MyIntKey)"); sleep(2); status = PMIx_Commit(); CHECK_ERROR(status, "PMIx_Commit()"); sleep(2); pmix_value_t *retval; status = PMIx_Get(&proc, "MyStringKey", NULL, 0, &retval); CHECK_ERROR(status, "PMIx_Get(MyStringKey)"); if (retval == NULL) { printf("PMIx_Get(MyStringKey) failed: retval == NULL\n"); return -1; } if (retval->type != PMIX_VAL_TYPE_string) { printf("PMIx_Get(MyStringKey) failed: type == %s\n", PMIx_Data_type_string(retval->type)); return -1; } printf("PMIx_Get(MyStringKey) succeeded: value '%s'\n", PMIX_VAL_FIELD_string(retval)); sleep(2); status = PMIx_Get(&proc, "MyIntKey", NULL, 0, &retval); CHECK_ERROR(status, "PMIx_Get(MyIntKey)"); if (retval == NULL) { printf("PMIx_Get(MyIntKey) failed: retval == NULL\n"); return -1; } if (retval->type != PMIX_VAL_TYPE_int) { printf("PMIx_Get(MyIntKey) failed: type == %s\n", PMIx_Data_type_string(retval->type)); return -1; } printf("PMIx_Get(MyIntKey) succeeded: value %d\n", PMIX_VAL_FIELD_int(retval)); sleep(2); status = PMIx_Finalize(NULL, 0); CHECK_ERROR(status, "PMIx_Finalize()"); return 0; }