Commit 166c3ced authored by Jonathan Jenkins's avatar Jonathan Jenkins

move canonical naming order to config - need earlier initialization

parent e14c36b3
......@@ -51,10 +51,20 @@ typedef struct config_anno_map_s
typedef struct config_lpgroups_s
{
uint64_t lpgroups_count;
// counts for the underlying structures, not the number of string entities
int lpgroups_count;
int lpannos_count;
config_lpgroup_t lpgroups[CONFIGURATION_MAX_GROUPS];
uint64_t lpannos_count;
config_anno_map_t lpannos[CONFIGURATION_MAX_TYPES];
int num_uniq_lptypes;
int num_uniq_annos;
// ptrs into the name buffers
char const ** group_names;
char const ** lp_names;
char const ** anno_names;
char * group_names_buf;
char * lp_names_buf;
char * anno_names_buf;
} config_lpgroups_t;
typedef struct ConfigVTable * ConfigHandle;
......
......@@ -332,6 +332,44 @@ static void check_add_lp_type_anno(
}
}
#define REALLOC_IF(_cap_var, _len_exp, _buf_var) \
do { \
while ((_cap_var) <= (_len_exp)) { \
_cap_var *= 2; \
_buf_var = realloc(_buf_var, (_cap_var) * sizeof(*_buf_var)); \
assert(_buf_var); \
} \
} while (0)
/* helper for setting up the canonical name mapping */
static void check_add_uniq_str(
char const *** str_array_ref,
char ** str_buf,
int * num_strs,
int * str_array_cap, // buffer capacity for resizing
int * str_buf_len,
int * str_buf_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;
}
REALLOC_IF(*str_array_cap, *num_strs, *str_array_ref);
REALLOC_IF(*str_buf_cap, *str_buf_len + slen + 1, *str_buf);
// include null char
memcpy(*str_buf + *str_buf_len, str, slen+1);
(*str_array_ref)[*num_strs] = *str_buf + *str_buf_len;
*num_strs += 1;
*str_buf_len += slen+1;
}
int configuration_get_lpgroups (ConfigHandle *handle,
const char *section_name,
config_lpgroups_t *lpgroups)
......@@ -344,9 +382,38 @@ int configuration_get_lpgroups (ConfigHandle *handle,
size_t subse_count = 10;
int i, j, lpt;
char data[256];
int num_uniq_group_names = 0;
int group_names_buf_len = 0;
int lp_names_buf_len = 0;
int anno_names_buf_len = 0;
int group_names_cap = 1;
int lp_names_cap = 1;
int anno_names_cap = 1;
int group_names_buf_cap = 1;
int lp_names_buf_cap = 1;
int anno_names_buf_cap = 1;
memset (lpgroups, 0, sizeof(*lpgroups));
lpgroups->group_names =
malloc(sizeof(*lpgroups->group_names) * group_names_cap);
lpgroups->lp_names =
malloc(sizeof(*lpgroups->lp_names) * lp_names_cap);
lpgroups->anno_names =
malloc(sizeof(*lpgroups->anno_names) * anno_names_cap);
lpgroups->group_names_buf =
malloc(sizeof(*lpgroups->group_names_buf) * group_names_buf_cap);
lpgroups->lp_names_buf =
malloc(sizeof(*lpgroups->lp_names_buf) * lp_names_buf_cap);
lpgroups->anno_names_buf =
malloc(sizeof(*lpgroups->anno_names_buf) * anno_names_buf_cap);
assert(lpgroups->group_names != NULL);
assert(lpgroups->lp_names != NULL);
assert(lpgroups->anno_names != NULL);
assert(lpgroups->group_names_buf != NULL);
assert(lpgroups->lp_names_buf != NULL);
assert(lpgroups->anno_names_buf != NULL);
int ret = cf_openSection(*handle, ROOT_SECTION, section_name, &sh);
if (ret == -1)
return -1;
......@@ -371,10 +438,18 @@ int configuration_get_lpgroups (ConfigHandle *handle,
subse_count = 10;
cf_openSection(*handle, sh, se[i].name, &subsh);
cf_listSection(*handle, subsh, subse, &subse_count);
check_add_uniq_str(&lpgroups->group_names,
&lpgroups->group_names_buf, &num_uniq_group_names,
&group_names_cap, &group_names_buf_len,
&group_names_buf_cap, se[i].name);
strncpy(lpgroups->lpgroups[i].name, se[i].name,
CONFIGURATION_MAX_NAME);
lpgroups->lpgroups[i].repetitions = 1;
lpgroups->lpgroups_count++;
if (num_uniq_group_names != lpgroups->lpgroups_count)
tw_error(TW_LOC,
"config error: non-unique group names detected\n");
for (j = 0, lpt = 0; j < subse_count; j++)
{
if (subse[j].type == SE_KEY)
......@@ -400,10 +475,28 @@ int configuration_get_lpgroups (ConfigHandle *handle,
if (c) {
strcpy(anno, c+1);
*c = '\0';
check_add_uniq_str(
&lpgroups->anno_names,
&lpgroups->anno_names_buf,
&lpgroups->num_uniq_annos,
&anno_names_cap,
&anno_names_buf_len,
&anno_names_buf_cap,
c+1);
}
else {
anno[0] = '\0';
}
check_add_uniq_str(
&lpgroups->lp_names,
&lpgroups->lp_names_buf,
&lpgroups->num_uniq_lptypes,
&lp_names_cap,
&lp_names_buf_len,
&lp_names_buf_cap,
nm);
// add to anno map
check_add_lp_type_anno(nm, anno, lpgroups);
CHECKED_STRTOL(lpgroups->lpgroups[i].lptypes[lpt].count,
......@@ -417,6 +510,13 @@ int configuration_get_lpgroups (ConfigHandle *handle,
}
}
if (lpgroups->lpannos_count == 0) {
free(lpgroups->anno_names);
free(lpgroups->anno_names_buf);
lpgroups->anno_names = NULL;
lpgroups->anno_names_buf = NULL;
}
cf_closeSection(*handle, sh);
return 0;
......
......@@ -19,15 +19,6 @@ 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
......@@ -453,76 +444,12 @@ 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++)
{
......@@ -654,7 +581,8 @@ static char const * get_name_by_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);
return get_cid_by_name(group_name, lpconf.group_names,
lpconf.lpgroups_count);
}
int codes_mapping_get_group_cid_by_lpid(tw_lpid id)
......@@ -668,12 +596,13 @@ int codes_mapping_get_group_cid_by_lpid(tw_lpid id)
char const * codes_mapping_get_group_name_by_cid(int cid)
{
return get_name_by_cid(cid, group_names, num_uniq_groups);
return get_name_by_cid(cid, lpconf.group_names, lpconf.lpgroups_count);
}
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);
return get_cid_by_name(lp_type_name, lpconf.lp_names,
lpconf.num_uniq_lptypes);
}
int codes_mapping_get_lp_cid_by_lpid(tw_lpid id)
......@@ -687,15 +616,16 @@ int codes_mapping_get_lp_cid_by_lpid(tw_lpid id)
char const * codes_mapping_get_lp_name_by_cid(int cid)
{
return get_name_by_cid(cid, lp_names, num_uniq_lptypes);
return get_name_by_cid(cid, lpconf.lp_names, lpconf.num_uniq_lptypes);
}
int codes_mapping_get_anno_cid_by_name(char const * annotation)
{
if (annotation == NULL || annotation[0] == '\0')
return num_uniq_annos;
return lpconf.num_uniq_annos;
else
return get_cid_by_name(annotation, anno_names, num_uniq_annos);
return get_cid_by_name(annotation, lpconf.anno_names,
lpconf.num_uniq_annos);
}
int codes_mapping_get_anno_cid_by_lpid(tw_lpid id)
......@@ -709,7 +639,7 @@ int codes_mapping_get_anno_cid_by_lpid(tw_lpid id)
char const * codes_mapping_get_anno_name_by_cid(int cid)
{
return get_name_by_cid(cid, anno_names, num_uniq_annos);
return get_name_by_cid(cid, lpconf.anno_names, lpconf.num_uniq_annos);
}
/*
......
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