static void _store_hosts (flux_t h) { char *key; long cores = sysconf(_SC_NPROCESSORS_ONLN); long pagesize = sysconf(_SC_PAGE_SIZE); long pages = sysconf(_SC_PHYS_PAGES); long memMB = pages * pagesize / 1024 / 1024; if ((asprintf (&key, "resrc.rank.%d.cores", flux_rank (h)) < 0) || kvs_put_int64 (h, key, cores)) { err ("resrc: kvs_put_int64 %d %lu failed", flux_rank (h), cores); } free (key); if ((asprintf (&key, "resrc.rank.%d.alloc.cores", flux_rank (h)) < 0) || kvs_put_int64 (h, key, 0)) { err ("resrc: kvs_put_int64 %d %d failed", flux_rank (h), 0); } free (key); if ((asprintf (&key, "resrc.rank.%d.mem", flux_rank (h)) < 0) || kvs_put_int64 (h, key, memMB)) { err ("resrc: kvs_put_int64 %d %lu failed", flux_rank (h), memMB); } free (key); kvs_commit(h); }
static int update_rdesc (flux_t h, int64_t j, JSON o) { int rc = -1; int64_t nnodes = 0; int64_t ntasks = 0; char key1[20] = {'\0'}; char key2[20] = {'\0'}; if (!Jget_int64 (o, JSC_RDESC_NNODES, &nnodes)) return -1; if (!Jget_int64 (o, JSC_RDESC_NTASKS, &ntasks)) return -1; if ((nnodes < 0) || (ntasks < 0)) return -1; snprintf (key1, 20, "lwj.%ld.nnodes", j); snprintf (key2, 20, "lwj.%ld.ntasks", j); if (kvs_put_int64 (h, key1, nnodes) < 0) flux_log (h, LOG_ERR, "update %s: %s", key1, strerror (errno)); else if (kvs_put_int64 (h, key2, ntasks) < 0) flux_log (h, LOG_ERR, "update %s: %s", key2, strerror (errno)); else if (kvs_commit (h) < 0) flux_log (h, LOG_ERR, "commit failed"); else { flux_log (h, LOG_DEBUG, "job (%ld) assigned new resources.", j); rc = 0; } return rc; }
/* * Set a new value for lwj.next-id and commit */ static int set_next_jobid (flux_t h, unsigned long jobid) { int rc; if ((rc = kvs_put_int64 (h, "lwj.next-id", jobid)) < 0) { err ("kvs_put: %s", strerror (errno)); return -1; } return kvs_commit (h); }
static int update_rdesc (flux_t h, int64_t j, JSON o) { int rc = -1; int64_t nnodes = 0; int64_t ntasks = 0; int64_t walltime = 0; char *key1; char *key2; char *key3; if (!Jget_int64 (o, JSC_RDESC_NNODES, &nnodes)) return -1; if (!Jget_int64 (o, JSC_RDESC_NTASKS, &ntasks)) return -1; if (!Jget_int64 (o, JSC_RDESC_WALLTIME, &walltime)) return -1; if ((nnodes < 0) || (ntasks < 0) || (walltime < 0)) return -1; key1 = xasprintf ("lwj.%"PRId64".nnodes", j); key2 = xasprintf ("lwj.%"PRId64".ntasks", j); key3 = xasprintf ("lwj.%"PRId64".walltime", j); if (kvs_put_int64 (h, key1, nnodes) < 0) flux_log_error (h, "update %s", key1); else if (kvs_put_int64 (h, key2, ntasks) < 0) flux_log_error (h, "update %s", key2); else if (kvs_put_int64 (h, key3, walltime) < 0) flux_log_error (h, "update %s", key3); else if (kvs_commit (h) < 0) flux_log_error (h, "commit failed"); else { flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new resources.", j); rc = 0; } free (key1); free (key2); return rc; }
static int update_1ra (flux_t h, int r, int64_t j, JSON o) { int rc = 0; int64_t ncores = 0; char key[20] = {'\0'}; JSON c = NULL; if (!Jget_obj (o, JSC_RDL_ALLOC_CONTAINED, &c)) return -1; if (!Jget_int64 (c, JSC_RDL_ALLOC_CONTAINED_NCORES, &ncores)) return -1; snprintf (key, 20, "lwj.%ld.rank.%d.cores", j, r); if ( (rc = kvs_put_int64 (h, key, ncores)) < 0) { flux_log (h, LOG_ERR, "put %s: %s", key, strerror (errno)); } return rc; }
static int update_rdl_alloc (flux_t h, int64_t j, JSON o) { int i = 0; int rc = -1; int size = 0; JSON ra_e = NULL; const char *key = NULL; zhash_t *rtab = NULL; int64_t *ncores = NULL; if (!(rtab = zhash_new ())) oom (); if (!Jget_ar_len (o, &size)) goto done; for (i=0; i < (int) size; ++i) { if (!Jget_ar_obj (o, i, &ra_e)) goto done; /* 'o' represents an array of per-node core count to use. * However, becasue the same rank can appear multiple times * in this array in emulation mode, update_hash_1ra is * used to determine the total core count per rank. */ if ( (rc = update_hash_1ra (h, j, ra_e, rtab)) < 0) goto done; } FOREACH_ZHASH (rtab, key, ncores) { if ( (rc = kvs_put_int64 (h, key, *ncores)) < 0) { flux_log_error (h, "put %s", key); goto done; } } if (kvs_commit (h) < 0) { flux_log (h, LOG_ERR, "update_pdesc commit failed"); goto done; } rc = 0; done: zhash_destroy (&rtab); return rc; }