Skip to content

Commit 07df1f8

Browse files
committed
reapi: added match options to c bindings
Problem: reapi C bindings only use 2 of the 4 match options for match allocate. Create new functions match and match_satisfy where match is a general purpose match allocate function that can use all 4 match options. match_satisfy and match_allocate both call match with their corresponding match options.
1 parent 58d666a commit 07df1f8

File tree

4 files changed

+176
-12
lines changed

4 files changed

+176
-12
lines changed

resource/reapi/bindings/c/reapi_cli.cpp

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,39 @@ extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph,
9090
return rc;
9191
}
9292

93-
extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
94-
bool orelse_reserve, const char *jobspec,
95-
uint64_t *jobid, bool *reserved,
96-
char **R, int64_t *at, double *ov)
93+
extern "C" int reapi_cli_match (reapi_cli_ctx_t *ctx,
94+
const char *match_op, const char *jobspec,
95+
uint64_t *jobid, bool *reserved,
96+
char **R, int64_t *at, double *ov)
9797
{
9898
int rc = -1;
9999
std::string R_buf = "";
100100
char *R_buf_c = nullptr;
101+
match_op_t op;
101102

102103
if (!ctx || !ctx->rqt) {
103104
errno = EINVAL;
104105
goto out;
105106
}
106107

108+
if (!strcmp (match_op,"allocate"))
109+
op = match_op_t::MATCH_ALLOCATE;
110+
else if (!strcmp (match_op, "allocate_with_satisfiability"))
111+
op = match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY;
112+
else if (!strcmp (match_op, "allocate_orelse_reserve"))
113+
op = match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE;
114+
else if (!strcmp (match_op, "satisfiability"))
115+
op = match_op_t::MATCH_SATISFIABILITY;
116+
else
117+
goto out;
118+
107119
*jobid = ctx->rqt->get_job_counter ();
108-
if ((rc = reapi_cli_t::match_allocate (ctx->rqt, orelse_reserve,
120+
if ((rc = reapi_cli_t::match_allocate (ctx->rqt, op,
109121
jobspec, *jobid, *reserved,
110122
R_buf, *at, *ov)) < 0) {
111123
goto out;
112124
}
125+
113126
if ( !(R_buf_c = strdup (R_buf.c_str ()))) {
114127
ctx->err_msg = __FUNCTION__;
115128
ctx->err_msg += ": ERROR: can't allocate memory\n";
@@ -123,9 +136,44 @@ extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
123136
return rc;
124137
}
125138

139+
extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
140+
bool orelse_reserve, const char *jobspec,
141+
uint64_t *jobid, bool *reserved,
142+
char **R, int64_t *at, double *ov)
143+
{
144+
const char *match_op = orelse_reserve ? "allocate_orelse_reserve" :
145+
"allocate";
146+
147+
return reapi_cli_match (ctx, match_op, jobspec, jobid, reserved,
148+
R, at, ov);
149+
}
150+
151+
extern "C" int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx,
152+
const char *jobspec,
153+
bool *sat, double *ov)
154+
{
155+
const char *match_op = "satisfiability";
156+
uint64_t jobid;
157+
bool reserved;
158+
char *R;
159+
int64_t at;
160+
int ret;
161+
*sat = true;
162+
163+
ret = reapi_cli_match (ctx, match_op, jobspec, &jobid,
164+
&reserved, &R, &at, ov);
165+
166+
// check for satisfiability
167+
if (errno == ENODEV)
168+
*sat = false;
169+
170+
return ret;
171+
}
172+
126173
extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx,
127-
const uint64_t jobid, const char *R, int64_t *at,
128-
double *ov, const char **R_out)
174+
const uint64_t jobid,
175+
const char *R, int64_t *at,
176+
double *ov, const char **R_out)
129177
{
130178
int rc = -1;
131179
std::string R_buf = "";

resource/reapi/bindings/c/reapi_cli.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ void reapi_cli_destroy (reapi_cli_ctx_t *ctx);
4141
int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph,
4242
const char *options);
4343

44+
/*! Match a jobspec to the "best" resources and either allocate
45+
* orelse reserve them. The best resources are determined by
46+
* the selected match policy.
47+
*
48+
* \param ctx reapi_cli_ctx_t context object
49+
* \param match_op const char *: set to specify the specific match option
50+
* from 1 of 4 choices:
51+
* allocate: try to allocate now and fail if resources
52+
* aren't available.
53+
* allocate_orelse_reserve : Try to allocate and reserve if
54+
* resources aren't available now.
55+
* satisfiability: Do a satisfiablity check and do not
56+
* allocate.
57+
* allocate_with_satisfiability: try to allocate and run
58+
* satisfiability check if resources are not available.
59+
* \param jobspec jobspec string.
60+
* \param jobid jobid of the uint64_t type.
61+
* \param reserved Boolean into which to return true if this job has been
62+
* reserved instead of allocated.
63+
* \param R String into which to return the resource set either
64+
* allocated or reserved.
65+
* \param at If allocated, 0 is returned; if reserved, actual time
66+
* at which the job is reserved.
67+
* \param ov Double into which to return performance overhead
68+
* in terms of elapse time needed to complete
69+
* the match operation.
70+
* \return 0 on success; -1 on error.
71+
*/
72+
int reapi_cli_match (reapi_cli_ctx_t *ctx, const char *match_op,
73+
const char *jobspec, uint64_t *jobid,
74+
bool *reserved,
75+
char **R, int64_t *at, double *ov);
76+
4477
/*! Match a jobspec to the "best" resources and either allocate
4578
* orelse reserve them. The best resources are determined by
4679
* the selected match policy.
@@ -67,6 +100,20 @@ int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx, bool orelse_reserve,
67100
bool *reserved,
68101
char **R, int64_t *at, double *ov);
69102

103+
/*! Run Satisfiability check for jobspec.
104+
*
105+
* \param ctx reapi_cli_ctx_t context object
106+
* \param jobspec jobspec string.
107+
* \param sat bool sat into which to return if jobspec is
108+
* satisfiable.
109+
* \param ov Double into which to return performance overhead
110+
* in terms of elapse time needed to complete
111+
* the match operation.
112+
* \return 0 on success; -1 on error.
113+
*/
114+
int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx,
115+
const char *jobspec, bool *sat, double *ov);
116+
70117
/*! Update the resource state with R.
71118
*
72119
* \param ctx reapi_cli_ctx_t context object

resource/reapi/bindings/c/reapi_module.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ extern "C" void reapi_module_destroy (reapi_module_ctx_t *ctx)
4747
free (ctx);
4848
}
4949

50-
extern "C" int reapi_module_match_allocate (reapi_module_ctx_t *ctx,
51-
bool orelse_reserve, const char *jobspec,
52-
const uint64_t jobid, bool *reserved,
53-
char **R, int64_t *at, double *ov)
50+
extern "C" int reapi_module_match (reapi_module_ctx_t *ctx,
51+
const char *match_op, const char *jobspec,
52+
const uint64_t jobid, bool *reserved,
53+
char **R, int64_t *at, double *ov)
5454
{
5555
int rc = -1;
5656
std::string R_buf = "";
@@ -60,7 +60,7 @@ extern "C" int reapi_module_match_allocate (reapi_module_ctx_t *ctx,
6060
errno = EINVAL;
6161
goto out;
6262
}
63-
if ((rc = reapi_module_t::match_allocate (ctx->h, orelse_reserve, jobspec,
63+
if ((rc = reapi_module_t::match_allocate (ctx->h, match_op, jobspec,
6464
jobid, *reserved,
6565
R_buf, *at, *ov)) < 0) {
6666
goto out;
@@ -75,6 +75,31 @@ extern "C" int reapi_module_match_allocate (reapi_module_ctx_t *ctx,
7575
return rc;
7676
}
7777

78+
extern "C" int reapi_module_match_allocate (reapi_module_ctx_t *ctx,
79+
bool orelse_reserve, const char *jobspec,
80+
const uint64_t jobid, bool *reserved,
81+
char **R, int64_t *at, double *ov)
82+
{
83+
const char *match_op = orelse_reserve ? "allocate_orelse_reserve" :
84+
"allocate";
85+
86+
return reapi_module_match (ctx, match_op, jobspec, jobid, reserved,
87+
R, at, ov);
88+
}
89+
90+
extern "C" int reapi_module_match_satisfy (reapi_module_ctx_t *ctx,
91+
const char *jobspec, double *ov)
92+
{
93+
const char *match_op = "satisfiability";
94+
const uint64_t jobid =0;
95+
bool *reserved;
96+
char **R;
97+
int64_t *at;
98+
99+
return reapi_module_match (ctx, match_op, jobspec, jobid,
100+
reserved, R, at, ov);
101+
}
102+
78103
extern "C" int reapi_module_update_allocate (reapi_module_ctx_t *ctx,
79104
const uint64_t jobid, const char *R,
80105
int64_t *at, double *ov,

resource/reapi/bindings/c/reapi_module.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,38 @@ reapi_module_ctx_t *reapi_module_new ();
3232
*/
3333
void reapi_module_destroy (reapi_module_ctx_t *ctx);
3434

35+
/*! Match a jobspec to the "best" resources and either allocate
36+
* orelse reserve them. The best resources are determined by
37+
* the selected match policy.
38+
*
39+
* \param ctx reapi_module_ctx_t context object
40+
* \param match_op const char *: set to specify the specific match option
41+
* from 1 of 4 choices:
42+
* allocate: try to allocate now and fail if resources
43+
* aren't available.
44+
* allocate_orelse_reserve: Try to allocate and resever if
45+
* resources aren't available now.
46+
* satisfiability: Do a satisfiablity check and do not
47+
* allocate.
48+
* allocate_with_satisfiability: try to allocate and run
49+
* satisfiability check if resources are not available.
50+
* \param jobspec jobspec string.
51+
* \param jobid jobid of the uint64_t type.
52+
* \param reserved Boolean into which to return true if this job has been
53+
* reserved instead of allocated.
54+
* \param R String into which to return the resource set either
55+
* allocated or reserved.
56+
* \param at If allocated, 0 is returned; if reserved, actual time
57+
* at which the job is reserved.
58+
* \param ov Double into which to return performance overhead
59+
* in terms of elapse time needed to complete
60+
* the match operation.
61+
* \return 0 on success; -1 on error.
62+
*/
63+
int reapi_module_match (reapi_module_ctx_t *ctx, const char *match_op,
64+
const char *jobspec, const uint64_t jobid,
65+
bool *reserved, char **R, int64_t *at, double *ov);
66+
3567
/*! Match a jobspec to the "best" resources and either allocate
3668
* orelse reserve them. The best resources are determined by
3769
* the selected match policy.
@@ -58,6 +90,18 @@ int reapi_module_match_allocate (reapi_module_ctx_t *ctx, bool orelse_reserve,
5890
bool *reserved,
5991
char **R, int64_t *at, double *ov);
6092

93+
/*! Run Satisfiability check for jobspec.
94+
*
95+
* \param ctx reapi_module_ctx_t context object
96+
* \param jobspec jobspec string.
97+
* \param ov Double into which to return performance overhead
98+
* in terms of elapse time needed to complete
99+
* the match operation.
100+
* \return 0 on success; -1 on error.
101+
*/
102+
int reapi_module_match_satisfy (reapi_module_ctx_t *ctx,
103+
const char *jobspec, double *ov);
104+
61105
/*! Update the resource state with R.
62106
*
63107
* \param ctx reapi_module_ctx_t context object

0 commit comments

Comments
 (0)