Commit 3e632f0b authored by Jonathan Jenkins's avatar Jonathan Jenkins

jobmap interface change, fixes

parent ec142cc9
......@@ -11,9 +11,9 @@
*
* Example:
*
* job 0 1 2
* rank 0 1 2 0 1 0 1 2 3
* ID 0 1 2 3 4 5 6 7 8 (<-- LP relative ID)
* job 0 1 2 (<-- jobmap defined "local" IDs)
* rank 0 1 2 0 1 0 1 2 3 (<-- jobmap defined "local" IDs)
* ID 0 1 2 3 4 5 6 7 8 (<-- LP relative "global" ID)
* LP A B C D E F G H I (<-- provided by codes-mapping)
* */
......@@ -46,10 +46,20 @@ codes_jobmap_configure(enum codes_jobmap_type t, void const * params);
void codes_jobmap_destroy(struct codes_jobmap_ctx *c);
struct codes_jobmap_id codes_jobmap_lookup(
/* main mapping functions - bidirectional mapping is needed:
* - global -> local ID for initialization
* - local -> global ID for communication between local IDs
*
* functions return {-1, -1} and -1, respectively, for invalid id input */
struct codes_jobmap_id codes_jobmap_to_local_id(
int id,
struct codes_jobmap_ctx const * c);
int codes_jobmap_to_global_id(
struct codes_jobmap_id id,
struct codes_jobmap_ctx const * c);
int codes_jobmap_get_num_jobs(struct codes_jobmap_ctx const * c);
#endif
......
......@@ -13,10 +13,11 @@
struct codes_jobmap_impl {
/* returns nonzero on failure (to distinguish between no-state (dummy) and
* failure) */
int (*configure)(void const * params, void ** ctx);
void (*destroy)(void * ctx);
struct codes_jobmap_id (*lookup) (int id, void const * ctx);
int (*get_num_jobs)(void const * ctx);
int (*configure)(void const * params, void ** ctx);
void (*destroy)(void * ctx);
struct codes_jobmap_id (*to_local) (int id, void const * ctx);
int (*to_global) (struct codes_jobmap_id id, void const * ctx);
int (*get_num_jobs)(void const * ctx);
};
struct codes_jobmap_ctx {
......
......@@ -45,11 +45,18 @@ void codes_jobmap_destroy(struct codes_jobmap_ctx *c)
free(c);
}
struct codes_jobmap_id codes_jobmap_lookup(
struct codes_jobmap_id codes_jobmap_to_local_id(
int id,
struct codes_jobmap_ctx const * c)
{
return c->impl->lookup(id, c->ctx);
return c->impl->to_local(id, c->ctx);
}
int codes_jobmap_to_global_id(
struct codes_jobmap_id id,
struct codes_jobmap_ctx const * c)
{
return c->impl->to_global(id, c->ctx);
}
int codes_jobmap_get_num_jobs(struct codes_jobmap_ctx const * c)
......
......@@ -11,9 +11,9 @@
static int jobmap_dummy_configure(void const * params, void ** ctx)
{
int *num_jobs = *ctx;
num_jobs = malloc(sizeof(*num_jobs));
int *num_jobs = malloc(sizeof(*num_jobs));
assert(num_jobs);
*ctx = num_jobs;
struct codes_jobmap_params_dummy const * p = params;
......@@ -27,18 +27,34 @@ static void jobmap_dummy_destroy(void * ctx)
free(ctx);
}
static struct codes_jobmap_id jobmap_dummy_lookup(int id, void const * ctx)
static struct codes_jobmap_id jobmap_dummy_to_local(int id, void const * ctx)
{
int const * num_jobs = ctx;
struct codes_jobmap_id rtn = {-1, -1};
struct codes_jobmap_id rtn;
if (id >= *num_jobs) {
if (id < *num_jobs) {
rtn.job = id;
rtn.rank = 0;
}
else {
rtn.job = -1;
rtn.rank = -1;
}
return rtn;
}
static int jobmap_dummy_to_global(struct codes_jobmap_id id, void const * ctx)
{
int const * num_jobs = ctx;
if (id.job < *num_jobs)
return id.job;
else
return -1;
}
int jobmap_dummy_get_num_jobs(void const * ctx)
{
return *(int const *) ctx;
......@@ -47,7 +63,8 @@ int jobmap_dummy_get_num_jobs(void const * ctx)
struct codes_jobmap_impl jobmap_dummy_impl = {
jobmap_dummy_configure,
jobmap_dummy_destroy,
jobmap_dummy_lookup,
jobmap_dummy_to_local,
jobmap_dummy_to_global,
jobmap_dummy_get_num_jobs
};
......
......@@ -52,7 +52,7 @@ tests_rc_stack_test_SOURCES = tests/rc-stack-test.c
tests_jobmap_test_LDADD = $(testlib) ${ROSS_LIBS}
tests_jobmap_test_LDFLAGS = ${ROSS_LDFLAGS}
tests_jobmap_test_SOURCES = tests/rc-stack-test.c
tests_jobmap_test_SOURCES = tests/jobmap-test.c
tests_workload_codes_workload_test_LDADD = $(testlib) ${ROSS_LIBS}
tests_workload_codes_workload_test_LDFLAGS = ${ROSS_LDFLAGS}
......
......@@ -24,18 +24,22 @@ int main(int argc, char *argv[])
/* initialize */
c = codes_jobmap_configure(CODES_JOBMAP_DUMMY, &p);
if (c) ERR("jobmap configure failure");
if (!c) ERR("jobmap configure failure");
/* successful lookups */
struct codes_jobmap_id id;
for (int i = 0; i < N; i++) {
id = codes_jobmap_lookup(i, c);
id = codes_jobmap_to_local_id(i, c);
if (id.job != i || id.rank != 0)
ERR("lookup failure for %d: expected (%d,%d), got (%d,%d)",
i, i, 0, id.job, id.rank);
else {
id.job = -1;
id.rank = -1;
}
}
/* bad lookup */
id = codes_jobmap_lookup(10, c);
id = codes_jobmap_to_local_id(10, c);
if (id.job != -1 || id.rank != -1)
ERR("lookup expected failure for 10: expected (%d,%d), got (%d,%d)",
-1,-1, id.job,id.rank);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment