Commit ec142cc9 authored by Jonathan Jenkins's avatar Jonathan Jenkins

interface for mapping per-"job" id space to flat id space

parent d2e03a90
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
/* SUMMARY - namespace support for multiple groups of ids (jobs) with respect to a
* flat namespace. Note that this API is meant for static job creation - a more
* sophisticated method would need to be used to modify job mappings at
* runtime.
*
* 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)
* LP A B C D E F G H I (<-- provided by codes-mapping)
* */
#ifndef CODES_JOBMAP_H
#define CODES_JOBMAP_H
/** type markers and parameter defs for jobmaps **/
enum codes_jobmap_type {
/* the "dummy" jobmap is an example implementation. It simply specifies N
* jobs, with exactly one rank per job, with a trivial mapping */
CODES_JOBMAP_DUMMY
};
struct codes_jobmap_params_dummy {
int num_jobs;
};
/** jobmap interface **/
struct codes_jobmap_ctx;
struct codes_jobmap_id {
int job;
int rank; // relative to job
};
struct codes_jobmap_ctx *
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(
int id,
struct codes_jobmap_ctx const * c);
int codes_jobmap_get_num_jobs(struct codes_jobmap_ctx const * c);
#endif
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
......@@ -57,7 +57,8 @@ nobase_include_HEADERS = \
codes/resource.h \
codes/resource-lp.h \
codes/local-storage-model.h \
codes/rc-stack.h
codes/rc-stack.h \
codes/codes-jobmap.h
#codes/codes-nw-workload.h
......@@ -95,6 +96,9 @@ src_libcodes_base_a_SOURCES = \
src/util/resource.c \
src/util/resource-lp.c \
src/util/local-storage-model.c \
src/util/codes-jobmap-method-impl.h \
src/util/codes-jobmap.c \
src/util/jobmap-impl/jobmap-dummy.c \
src/workload/codes-workload.c \
src/workload/codes-workload-method.h \
src/workload/methods/codes-iolang-wrkld.c \
......
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#ifndef CODES_JOBMAP_METHOD_IMPL
#define CODES_JOBMAP_METHOD_IMPL
#include <stdio.h>
#include "codes/codes-jobmap.h"
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);
};
struct codes_jobmap_ctx {
enum codes_jobmap_type type;
struct codes_jobmap_impl *impl;
void * ctx;
};
#endif
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <assert.h>
#include <stdlib.h>
#include "codes-jobmap-method-impl.h"
#include "codes/codes-jobmap.h"
extern struct codes_jobmap_impl jobmap_dummy_impl;
struct codes_jobmap_ctx *
codes_jobmap_configure(enum codes_jobmap_type t, void const * params)
{
struct codes_jobmap_ctx *c = malloc(sizeof(*c));
assert(c);
int rc;
c->type = t;
switch(t) {
case CODES_JOBMAP_DUMMY:
c->impl = &jobmap_dummy_impl;
break;
default:
free(c);
fprintf(stderr, "ERROR: unknown jobmap type %d\n", t);
return NULL;
}
rc = c->impl->configure(params, &c->ctx);
if (rc) {
fprintf(stderr, "ERROR: failed to configure jobmap type %d\n", t);
free(c);
return NULL;
}
else
return c;
}
void codes_jobmap_destroy(struct codes_jobmap_ctx *c)
{
c->impl->destroy(c->ctx);
free(c);
}
struct codes_jobmap_id codes_jobmap_lookup(
int id,
struct codes_jobmap_ctx const * c)
{
return c->impl->lookup(id, c->ctx);
}
int codes_jobmap_get_num_jobs(struct codes_jobmap_ctx const * c)
{
return c->impl->get_num_jobs(c->ctx);
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <stdlib.h>
#include <assert.h>
#include "src/util/codes-jobmap-method-impl.h"
static int jobmap_dummy_configure(void const * params, void ** ctx)
{
int *num_jobs = *ctx;
num_jobs = malloc(sizeof(*num_jobs));
assert(num_jobs);
struct codes_jobmap_params_dummy const * p = params;
*num_jobs = p->num_jobs;
return 0;
}
static void jobmap_dummy_destroy(void * ctx)
{
free(ctx);
}
static struct codes_jobmap_id jobmap_dummy_lookup(int id, void const * ctx)
{
int const * num_jobs = ctx;
struct codes_jobmap_id rtn = {-1, -1};
if (id >= *num_jobs) {
rtn.job = id;
rtn.rank = 0;
}
return rtn;
}
int jobmap_dummy_get_num_jobs(void const * ctx)
{
return *(int const *) ctx;
}
struct codes_jobmap_impl jobmap_dummy_impl = {
jobmap_dummy_configure,
jobmap_dummy_destroy,
jobmap_dummy_lookup,
jobmap_dummy_get_num_jobs
};
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
......@@ -5,14 +5,16 @@ check_PROGRAMS += tests/lp-io-test \
tests/mapping_test \
tests/lsm-test \
tests/resource-test \
tests/rc-stack-test
tests/rc-stack-test \
tests/jobmap-test
TESTS += tests/lp-io-test.sh \
tests/workload/codes-workload-test.sh \
tests/mapping_test.sh \
tests/lsm-test.sh \
tests/rc-stack-test \
tests/resource-test.sh
tests/resource-test.sh \
tests/jobmap-test
EXTRA_DIST += tests/lp-io-test.sh \
tests/workload/codes-workload-test.sh \
......@@ -48,6 +50,10 @@ tests_rc_stack_test_LDADD = $(testlib) ${ROSS_LIBS}
tests_rc_stack_test_LDFLAGS = ${ROSS_LDFLAGS}
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_workload_codes_workload_test_LDADD = $(testlib) ${ROSS_LIBS}
tests_workload_codes_workload_test_LDFLAGS = ${ROSS_LDFLAGS}
tests_workload_codes_workload_test_SOURCES = \
......
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <stdio.h>
#include "codes/codes-jobmap.h"
const int N = 10;
int main(int argc, char *argv[])
{
struct codes_jobmap_ctx *c;
struct codes_jobmap_params_dummy p;
p.num_jobs = N;
#define ERR(str, ...) \
do { \
fprintf(stderr, "ERROR: " str "\n", ##__VA_ARGS__); \
return 1; \
} while(0)
/* initialize */
c = codes_jobmap_configure(CODES_JOBMAP_DUMMY, &p);
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);
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);
}
/* bad lookup */
id = codes_jobmap_lookup(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);
/* cleanup */
codes_jobmap_destroy(c);
#undef ERR
return 0;
}
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