From 5a518276699a34601274368f20896cfef50cb9d2 Mon Sep 17 00:00:00 2001 From: John Jenkins Date: Tue, 4 Aug 2015 11:12:13 -0500 Subject: [PATCH] map-ctx: add annotation getter, modify lpid mapper --- codes/codes-mapping-context.h | 11 ++++- src/util/codes-mapping-context.c | 40 ++++++++++++++-- src/util/resource-lp.c | 2 +- tests/map-ctx-test.c | 81 ++++++++++++++++++++++---------- 4 files changed, 102 insertions(+), 32 deletions(-) diff --git a/codes/codes-mapping-context.h b/codes/codes-mapping-context.h index 2ed1e17..c00b7db 100644 --- a/codes/codes-mapping-context.h +++ b/codes/codes-mapping-context.h @@ -83,11 +83,18 @@ struct codes_mctx codes_mctx_set_group_direct( /* helper function to do a codes mapping - this function is subject to change * based on what types of ctx exist - * NOTE: in GLOBAL_DIRECT mode, dest_lp_name and sender are ignored */ + * NOTE: in GLOBAL_DIRECT mode, dest_lp_name and sender_gid are ignored */ tw_lpid codes_mctx_to_lpid( struct codes_mctx const * ctx, char const * dest_lp_name, - tw_lp const * sender); + tw_lpid sender_gid); + +/* helper function to extract which annotation a various map context maps to. + * annotation is allocated or NULL if unused */ +char const * codes_mctx_get_annotation( + struct codes_mctx const *ctx, + char const * dest_lp_name, + tw_lpid sender_id); #endif /* end of include guard: CODES_MAPPING_CONTEXT_H */ diff --git a/src/util/codes-mapping-context.c b/src/util/codes-mapping-context.c index b392fdd..5099036 100644 --- a/src/util/codes-mapping-context.c +++ b/src/util/codes-mapping-context.c @@ -56,7 +56,7 @@ struct codes_mctx codes_mctx_set_group_direct( tw_lpid codes_mctx_to_lpid( struct codes_mctx const * ctx, char const * dest_lp_name, - tw_lp const * sender) + tw_lpid sender_gid) { struct codes_mctx_annotation const *anno; // short circuit for direct mappings @@ -77,7 +77,7 @@ tw_lpid codes_mctx_to_lpid( int unused, rep_id, offset; // get sender info - codes_mapping_get_lp_info(sender->gid, sender_group, &unused, NULL, &unused, + codes_mapping_get_lp_info(sender_gid, sender_group, &unused, NULL, &unused, NULL, &rep_id, &offset); int dest_offset; @@ -88,7 +88,7 @@ tw_lpid codes_mctx_to_lpid( tw_error(TW_LOC, "ERROR: Found no LPs of type %s in group %s " "(source lpid %lu) with annotation: %s\n", - dest_lp_name, sender_group, sender->gid, + dest_lp_name, sender_group, sender_gid, anno->ignore_annotations ? "ignored" : (anno->annotation ? anno->annotation : "none")); @@ -106,6 +106,40 @@ tw_lpid codes_mctx_to_lpid( return rtn; } +char const * codes_mctx_get_annotation( + struct codes_mctx const *ctx, + char const * dest_lp_name, + tw_lpid sender_id) +{ + switch(ctx->type) { + case CODES_MCTX_GLOBAL_DIRECT: + return codes_mapping_get_annotation_by_lpid(sender_id); + case CODES_MCTX_GROUP_MODULO: + // if not ignoring the annotation, just return what's in the + // context + if (!ctx->u.group_modulo.anno.ignore_annotations) + return ctx->u.group_modulo.anno.annotation; + break; + case CODES_MCTX_GROUP_DIRECT: + if (!ctx->u.group_direct.anno.ignore_annotations) + return ctx->u.group_direct.anno.annotation; + break; + default: + tw_error(TW_LOC, "unrecognized or uninitialized context type: %d", + ctx->type); + return NULL; + } + // at this point, we must be a group-wise mapping ignoring annotations + + char group[MAX_NAME_LENGTH]; + int dummy; + // only need the group name + codes_mapping_get_lp_info(sender_id, group, &dummy, NULL, &dummy, NULL, + &dummy, &dummy); + + return codes_mapping_get_annotation_by_name(group, dest_lp_name); +} + /* * Local variables: * c-indent-level: 4 diff --git a/src/util/resource-lp.c b/src/util/resource-lp.c index bd5cc77..9b0fcb1 100644 --- a/src/util/resource-lp.c +++ b/src/util/resource-lp.c @@ -467,7 +467,7 @@ static void resource_lp_issue_event_base( SANITY_CHECK_CB(cb, resource_return); tw_lpid resource_lpid = - codes_mctx_to_lpid(map_ctx, RESOURCE_LP_NM, sender); + codes_mctx_to_lpid(map_ctx, RESOURCE_LP_NM, sender->gid); tw_event *e = tw_event_new(resource_lpid, codes_local_latency(sender), sender); diff --git a/tests/map-ctx-test.c b/tests/map-ctx-test.c index 903d95b..188f7ee 100644 --- a/tests/map-ctx-test.c +++ b/tests/map-ctx-test.c @@ -33,39 +33,68 @@ int main(int argc, char *argv[]) group_modulo_anno = codes_mctx_set_group_modulo("baz", false); group_direct_anno = codes_mctx_set_group_direct(1, "baz", false); - tw_lp mock_lp; - tw_lpid rtn; + tw_lpid in; + tw_lpid rtn_id; + char const * rtn_anno; - rtn = codes_mctx_to_lpid(&direct, NULL, NULL); - if (12ul != rtn) - ERR("global_direct mapping: expected %lu, got %lu", 12ul, rtn); + rtn_id = codes_mctx_to_lpid(&direct, NULL, 0); + if (12ul != rtn_id) + ERR("global_direct mapping: expected %lu, got %lu", + 12ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(&direct, NULL, 0); + if (rtn_anno) + ERR("global_direct mapping: expected NULL anno, got %s", rtn_anno); - mock_lp.gid = 8ul; - rtn = codes_mctx_to_lpid(&group_modulo, "bar", &mock_lp); - if (rtn != 9ul) - ERR("group_modulo mapping: expected %lu, got %lu", 9ul, rtn); + in = 8ul; + rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in); + if (rtn_id != 9ul) + ERR("group_modulo mapping: expected %lu, got %lu", + 9ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in); + if (rtn_anno) + ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno); - mock_lp.gid = 12ul; - rtn = codes_mctx_to_lpid(&group_modulo, "bar", &mock_lp); - if (rtn != 13ul) - ERR("group_modulo mapping: expected %lu, got %lu", 13ul, rtn); + in = 12ul; + rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in); + if (rtn_id != 13ul) + ERR("group_modulo mapping: expected %lu, got %lu", + 13ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in); + if (rtn_anno) + ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno); - rtn = codes_mctx_to_lpid(CODES_MCTX_DEFAULT, "bar", &mock_lp); - if (rtn != 13ul) - ERR("group_modulo mapping (default): expected %lu, got %lu", 13ul, rtn); + rtn_id = codes_mctx_to_lpid(CODES_MCTX_DEFAULT, "bar", in); + if (rtn_id != 13ul) + ERR("group_modulo mapping (default): expected %lu, got %lu", + 13ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(CODES_MCTX_DEFAULT, "bar", in); + if (rtn_anno) + ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno); - rtn = codes_mctx_to_lpid(&group_modulo_anno, "bar", &mock_lp); - if (rtn != 15ul) - ERR("group_modulo annotated mapping: expected %lu, got %lu", 15ul, rtn); + rtn_id = codes_mctx_to_lpid(&group_modulo_anno, "bar", in); + if (rtn_id != 15ul) + ERR("group_modulo annotated mapping: expected %lu, got %lu", + 15ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(&group_modulo_anno, "bar", in); + if (strcmp(rtn_anno,"baz") != 0) + ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno); - mock_lp.gid = 10ul; - rtn = codes_mctx_to_lpid(&group_direct, "bar", &mock_lp); - if (rtn != 14ul) - ERR("group_direct mapping (default): expected %lu, got %lu", 14ul, rtn); + in = 10ul; + rtn_id = codes_mctx_to_lpid(&group_direct, "bar", in); + if (rtn_id != 14ul) + ERR("group_direct mapping (default): expected %lu, got %lu", + 14ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(&group_direct, "bar", in); + if (rtn_anno) + ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno); - rtn = codes_mctx_to_lpid(&group_direct_anno, "bar", &mock_lp); - if (rtn != 16ul) - ERR("group_direct mapping (default): expected %lu, got %lu", 16ul, rtn); + rtn_id = codes_mctx_to_lpid(&group_direct_anno, "bar", in); + if (rtn_id != 16ul) + ERR("group_direct mapping (default): expected %lu, got %lu", + 16ul, rtn_id); + rtn_anno = codes_mctx_get_annotation(&group_direct_anno, "bar", in); + if (strcmp(rtn_anno,"baz") != 0) + ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno); return 0; } -- 2.26.2