Commit e14c36b3 authored by Jonathan Jenkins's avatar Jonathan Jenkins

incorporated notion of canonical sim entity name indexes and API

this will be used so that LPs can communicate with each other in a more
flexible way without having to pass around strings (notably, the next step will
be for the map context API to take advantage of this)
parent e73a93d9
......@@ -180,6 +180,28 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid);
const config_anno_map_t *
codes_mapping_get_lp_anno_map(const char *lp_name);
/* the following functions are meant to aide in transferring LP mapping
* information across PEs - basically, a canonical mapping of names (group,
* LP, annotations) to indexes. This is separate from the indices returned from
* codes_mapping_get_lp_info, which points directly to configuration entities
*/
/* returns a canonical index (cid) for the group name, or -1 if not found */
int codes_mapping_get_group_cid_by_name(char const * group_name);
int codes_mapping_get_group_cid_by_lpid(tw_lpid id);
char const * codes_mapping_get_group_name_by_cid(int cid);
/* returns a canonical index (cid) for the LP name, or -1 if not found */
int codes_mapping_get_lp_cid_by_name(char const * lp_type_name);
int codes_mapping_get_lp_cid_by_lpid(tw_lpid id);
char const * codes_mapping_get_lp_name_by_cid(int cid);
/* returns a canonical index (cid) for an annotation, or -1 if not found.
* NOTE: a NULL or "\0" annotation corresponds to the lack of an annotation */
int codes_mapping_get_anno_cid_by_name(char const * annotation);
int codes_mapping_get_anno_cid_by_lpid(tw_lpid id);
char const * codes_mapping_get_anno_name_by_cid(int cid);
/*
* Local variables:
* c-indent-level: 4
......
......@@ -19,6 +19,15 @@ static int lps_leftover = 0;
static int mem_factor = 256;
/* canonical group/lp/annotation name-index mappings */
static char const * * group_names;
static char const * * lp_names;
// unannotated is represented by index num_uniq_annos
static char const * * anno_names;
static int num_uniq_groups;
static int num_uniq_lptypes;
static int num_uniq_annos;
static int mini(int a, int b){ return a < b ? a : b; }
// compare passed in annotation strings (NULL or nonempty) against annotation
......@@ -444,12 +453,76 @@ static tw_lp * codes_mapping_to_lp( tw_lpid lpid)
return g_tw_lp[index];
}
/* helper for setting up the canonical name mapping */
static void check_add_uniq_str(
char const *** str_array_ref,
int * num_strs,
int * cap, // buffer capacity for resizing
char const * str)
{
int slen = strlen(str);
for (int i = 0; i < *num_strs; i++) {
char const * b = (*str_array_ref)[i];
int blen = strlen(b);
if (slen == blen && memcmp(b, str, blen) == 0)
return;
}
if (*num_strs == *cap) {
*cap *= 2;
*str_array_ref =
realloc(*str_array_ref, *cap * sizeof(**str_array_ref));
assert(*str_array_ref);
}
(*str_array_ref)[*num_strs] = str;
*num_strs += 1;
}
static void setup_canonical_name_mapping()
{
num_uniq_groups = 0;
num_uniq_lptypes = 0;
num_uniq_annos = 0;
int group_cap = 8;
int lptype_cap = 8;
int anno_cap = 8;
group_names = malloc(group_cap*sizeof(*group_names));
lp_names = malloc(lptype_cap*sizeof(*lp_names));
anno_names = malloc(anno_cap*sizeof(*anno_names));
for (int g = 0; g < lpconf.lpgroups_count; g++) {
const config_lpgroup_t *lpg = &lpconf.lpgroups[g];
check_add_uniq_str(&group_names, &num_uniq_groups, &group_cap,
lpg->name);
for (int l = 0; l < lpg->lptypes_count; l++) {
const config_lptype_t *lpt = &lpg->lptypes[l];
check_add_uniq_str(&lp_names, &num_uniq_lptypes, &lptype_cap,
lpt->name);
// have to treat empty annotations specially
if (lpt->anno[0] != '\0')
check_add_uniq_str(&anno_names, &num_uniq_annos, &anno_cap,
lpt->anno);
}
}
assert(num_uniq_groups);
assert(num_uniq_lptypes);
if (num_uniq_annos == 0) {
free(anno_names);
anno_names = NULL;
}
}
/* This function loads the configuration file and sets up the number of LPs on each PE */
void codes_mapping_setup_with_seed_offset(int offset)
{
int grp, lpt, message_size;
int pes = tw_nnodes();
setup_canonical_name_mapping();
lps_per_pe_floor = 0;
for (grp = 0; grp < lpconf.lpgroups_count; grp++)
{
......@@ -556,6 +629,89 @@ codes_mapping_get_lp_anno_map(const char *lp_name){
return NULL;
}
static int get_cid_by_name(
char const * name,
char const * * names,
int num_names)
{
for (int i = 0; i < num_names; i++)
if (strcmp(name, names[i]) == 0)
return i;
return -1;
}
static char const * get_name_by_cid(
int cid,
char const * * names,
int num_names)
{
if (cid < 0 || cid >= num_names)
return NULL;
else
return names[cid];
}
int codes_mapping_get_group_cid_by_name(char const * group_name)
{
return get_cid_by_name(group_name, group_names, num_uniq_groups);
}
int codes_mapping_get_group_cid_by_lpid(tw_lpid id)
{
char group_name[MAX_NAME_LENGTH];
int ignore;
codes_mapping_get_lp_info(id, group_name, &ignore, NULL, &ignore, NULL,
&ignore, &ignore);
return codes_mapping_get_group_cid_by_name(group_name);
}
char const * codes_mapping_get_group_name_by_cid(int cid)
{
return get_name_by_cid(cid, group_names, num_uniq_groups);
}
int codes_mapping_get_lp_cid_by_name(char const * lp_type_name)
{
return get_cid_by_name(lp_type_name, lp_names, num_uniq_lptypes);
}
int codes_mapping_get_lp_cid_by_lpid(tw_lpid id)
{
char lp_name[MAX_NAME_LENGTH];
int ignore;
codes_mapping_get_lp_info(id, NULL, &ignore, lp_name, &ignore, NULL,
&ignore, &ignore);
return codes_mapping_get_lp_cid_by_name(lp_name);
}
char const * codes_mapping_get_lp_name_by_cid(int cid)
{
return get_name_by_cid(cid, lp_names, num_uniq_lptypes);
}
int codes_mapping_get_anno_cid_by_name(char const * annotation)
{
if (annotation == NULL || annotation[0] == '\0')
return num_uniq_annos;
else
return get_cid_by_name(annotation, anno_names, num_uniq_annos);
}
int codes_mapping_get_anno_cid_by_lpid(tw_lpid id)
{
char anno[MAX_NAME_LENGTH];
int ignore;
codes_mapping_get_lp_info(id, NULL, &ignore, NULL, &ignore, anno,
&ignore, &ignore);
return codes_mapping_get_anno_cid_by_name(anno);
}
char const * codes_mapping_get_anno_name_by_cid(int cid)
{
return get_name_by_cid(cid, anno_names, num_uniq_annos);
}
/*
* Local variables:
* c-indent-level: 4
......
......@@ -113,6 +113,91 @@ tw_lptype c_lp = {
sizeof(state),
};
#define TEST_TO_NM(_expected_nm, _input, _fn_type) \
do { \
char const * _anm = \
codes_mapping_get_ ##_fn_type ##_name_by_cid(_input); \
char const * _enm = \
(_expected_nm) == NULL ? "" : (_expected_nm); \
if ((_expected_nm) == NULL && _anm != NULL) { \
fprintf(stderr, "%s:%d: " \
" cid->name check error (expected NULL, got %s)\n", \
__FILE__, __LINE__, _anm);\
return 1; \
} else if ((_expected_nm) != NULL && strcmp(_enm, _anm) != 0) { \
fprintf(stderr, "%s:%d: " \
" cid->name check error (expected %s, got %s)\n", \
__FILE__, __LINE__, \
(_expected_nm) == NULL ? "null" : (_expected_nm), _anm);\
return 1; \
} \
} while (0);
#define TEST_TO_CID(_expected_cid, _input, _name_type, _fn_type) \
do { \
int _ecid = (_expected_cid); \
int _acid = \
codes_mapping_get_ ##_fn_type ##_cid_by_ ##_name_type (_input); \
if (_ecid != _acid) { \
fprintf(stderr, "%s:%d: " #_name_type \
" name->cid check error (expected %d, got %d)\n", \
__FILE__, __LINE__, _ecid, _acid);\
return 1; \
} \
} while (0);
#define TEST_TO_CID_NM(_expected_cid, _input, _fn_type) \
TEST_TO_CID(_expected_cid, _input, name, _fn_type)
#define TEST_TO_CID_LP(_expected_cid, _input, _fn_type) \
TEST_TO_CID(_expected_cid, _input, lpid, _fn_type)
static int test_cids()
{
TEST_TO_CID_NM(0, "GRP1", group)
TEST_TO_CID_NM(1, "GRP2", group)
TEST_TO_NM("GRP1", 0, group)
TEST_TO_NM("GRP2", 1, group)
TEST_TO_CID_NM(0, "a", lp)
TEST_TO_CID_NM(1, "b", lp)
TEST_TO_CID_NM(2, "c", lp)
TEST_TO_NM("a", 0, lp)
TEST_TO_NM("b", 1, lp)
TEST_TO_NM("c", 2, lp)
TEST_TO_CID_NM(0, "foo", anno)
TEST_TO_CID_NM(1, "bar", anno)
TEST_TO_CID_NM(2, NULL, anno)
TEST_TO_CID_NM(2, "", anno)
TEST_TO_NM("foo", 0, anno)
TEST_TO_NM("bar", 1, anno)
TEST_TO_NM(NULL, 2, anno)
TEST_TO_CID_LP(0, 0, group)
TEST_TO_CID_LP(0, 1, group)
TEST_TO_CID_LP(0, 9, group)
TEST_TO_CID_LP(1, 10, group)
TEST_TO_CID_LP(1, 11, group)
TEST_TO_CID_LP(1, 24, group)
TEST_TO_CID_LP(0, 0, lp)
TEST_TO_CID_LP(1, 1, lp)
TEST_TO_CID_LP(2, 9, lp)
TEST_TO_CID_LP(2, 10, lp)
TEST_TO_CID_LP(1, 11, lp)
TEST_TO_CID_LP(0, 24, lp)
TEST_TO_CID_LP(2, 0, anno)
TEST_TO_CID_LP(2, 1, anno)
TEST_TO_CID_LP(2, 9, anno)
TEST_TO_CID_LP(0, 8, anno)
TEST_TO_CID_LP(1, 10, anno)
TEST_TO_CID_LP(0, 11, anno)
TEST_TO_CID_LP(0, 24, anno)
return 0;
}
static char conf_file_name[128] = {'\0'};
static const tw_optdef app_opt [] =
{
......@@ -169,9 +254,12 @@ int main(int argc, char *argv[])
}
tw_run();
int rc = test_cids();
tw_end();
return 0;
return rc;
}
/*
......
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