Skip to content

Commit 48b23a2

Browse files
committed
scr_env: query PMIx for remaining time if YOGRT is not present
1 parent 13e5ee9 commit 48b23a2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/scr_env.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ machine-dependent information.
7373
*/
7474

7575
/* returns the number of seconds remaining in the time allocation */
76+
77+
#ifdef SCR_RESOURCE_MANAGER_PMIX
78+
/* callback for PMIX to query remaining walltime */
79+
static uint32_t seconds_remaining;
80+
static void seconds_remaining_cbfunc(pmix_status_t status, pmix_info_t *info,
81+
size_t ninfo, void *cbdata,
82+
pmix_release_cbfunc_t release_fn,
83+
void *release_cbdata)
84+
{
85+
volatile int *waiting = (volatile int*)cbdata;
86+
/* read time_remaining */
87+
if (info != NULL) {
88+
seconds_remaining = info->value.data.uint32;
89+
}
90+
91+
if (release_fn != NULL) {
92+
release_fn(release_cbdata);
93+
}
94+
*waiting = 0;
95+
}
96+
#endif
97+
7698
long int scr_env_seconds_remaining()
7799
{
78100
/* returning a negative number tells the caller this functionality is disabled */
@@ -84,6 +106,26 @@ long int scr_env_seconds_remaining()
84106
if (secs < 0) {
85107
secs = 0;
86108
}
109+
#elif defined(SCR_RESOURCE_MANAGER_PMIX)
110+
/* query time remaining */
111+
pmix_status_t retval;
112+
pmix_query_t *query;
113+
const int nq = 1;
114+
PMIX_QUERY_CREATE(query, nq);
115+
if (query != NULL) {
116+
PMIX_ARGV_APPEND(retval, query[0].keys, PMIX_TIME_REMAINING);
117+
if (retval == PMIX_SUCCESS) {
118+
volatile int waiting = 1;
119+
retval = PMIx_Query_info_nb(query, nq, seconds_remaining_cbfunc,
120+
(void*)&waiting);
121+
if (retval == PMIX_SUCCESS) {
122+
while (waiting) {
123+
sleep(1);
124+
}
125+
secs = (long int)seconds_remaining;
126+
}
127+
}
128+
}
87129
#else
88130
char* scr_end_time = getenv("SCR_END_TIME");
89131
if (scr_end_time) {

0 commit comments

Comments
 (0)