Commit 0a31ef96 authored by Jonathan Jenkins's avatar Jonathan Jenkins

new functions for codes-mapping

For a particular LP type:
- get the global number of LPs of that type
- get the relative ID w.r.t. LPs of the same type
parent 1ab4ea24
......@@ -26,10 +26,16 @@ int codes_mapping_get_group_reps(char* grp_name);
/* Takes the group name and lp type name, returns the count for that lp type */
int codes_mapping_get_lp_count(char* grp_name, char* lp_type_name);
/* Gets the total lp type count across all groups */
int codes_mapping_get_global_lp_count(char* lp_type_name);
/* Takes the group name , type name, rep ID and offset (for that lp type + repetition) and then returns the global LP ID. */
void codes_mapping_get_lp_id(char* grp_name, char* lp_type_name, int rep_id, int offset, tw_lpid* gid);
/* Takes the LP ID and returns its logical ID across LPs of the same type in
* all groups */
int codes_mapping_get_lp_global_rel_id(tw_lpid gid);
/* takes the LP ID and returns its grp name and index, lp type name and ID, repetition ID and the offset of the LP
* (for multiple LPs in a repetition). */
void codes_mapping_get_lp_info(tw_lpid gid, char* grp_name, int* grp_id, int* lp_type_id, char* lp_type_name, int* grp_rep_id, int* offset);
......
......@@ -79,6 +79,24 @@ int codes_mapping_get_lp_count(char* grp_name, char* lp_type_name)
}
return -1;
}
int codes_mapping_get_global_lp_count(char* lp_type_name){
int total_ct = 0;
int grp;
for (grp = 0; grp < lpconf.lpgroups_count; grp++){
int lpt;
int lp_types_count = lpconf.lpgroups[grp].lptypes_count;
int reps = lpconf.lpgroups[grp].repetitions;
config_lptype_t *c = lpconf.lpgroups[grp].lptypes;
for (lpt = 0; lpt < lp_types_count; lpt++){
if(strcmp(c[lpt].name, lp_type_name) == 0){
total_ct += c[lpt].count * reps;
}
}
}
return total_ct;
}
/* This function takes the group ID , type ID and rep ID then returns the global LP ID */
/* TODO: Add string based search for LP group and type names */
void codes_mapping_get_lp_id(char* grp_name, char* lp_type_name, int rep_id, int offset, tw_lpid* gid)
......@@ -131,6 +149,36 @@ void codes_mapping_get_lp_id(char* grp_name, char* lp_type_name, int rep_id, int
*gid = lpcount + offset;
}
int codes_mapping_get_lp_global_rel_id(tw_lpid gid){
/* use mapping function to get our starting point */
char grp_name[MAX_NAME_LENGTH];
char lp_type_name[MAX_NAME_LENGTH];
int grp_id, lp_type_id, grp_rep_id, offset;
codes_mapping_get_lp_info(gid, grp_name, &grp_id, &lp_type_id, lp_type_name,
&grp_rep_id, &offset);
/* now, go through the groups that occurred before and count up the lps of
* the same name */
int grp;
int total_lp_count = 0;
for (grp = 0; grp < grp_id; grp++){
int rep = lpconf.lpgroups[grp].repetitions;
int l;
/* get the total number of LPs in this group */
for (l = 0; l < lpconf.lpgroups[grp].lptypes_count; l++){
if (strcmp(lp_type_name, lpconf.lpgroups[grp].lptypes[l].name) == 0){
total_lp_count += rep * lpconf.lpgroups[grp].lptypes[l].count;
}
}
}
/* the global relative lp id is my relative position within the group +
* the number of lps that came before */
int nlp_per_rep = lpconf.lpgroups[grp_id].lptypes[lp_type_id].count;
return total_lp_count + (grp_rep_id * nlp_per_rep) + offset;
}
/* This function takes the LP ID and returns its grp index, lp type ID and repetition ID */
void codes_mapping_get_lp_info(tw_lpid gid, char* grp_name, int* grp_id, int* lp_type_id, char* lp_type_name, int* grp_rep_id, int* offset)
{
......
check_PROGRAMS += tests/lp-io-test \
tests/workload/codes-workload-test \
tests/workload/codes-workload-mpi-replay
tests/workload/codes-workload-mpi-replay \
tests/mapping_test
TESTS += tests/lp-io-test.sh \
tests/workload/codes-workload-test.sh
tests/workload/codes-workload-test.sh \
tests/mapping_test.sh
EXTRA_DIST += tests/lp-io-test.sh \
tests/workload/codes-workload-test.sh
tests/workload/codes-workload-test.sh \
tests/mapping_test.sh
testlib = src/libcodes-base.a
......@@ -15,6 +18,10 @@ tests_lp_io_test_LDADD = $(testlib) ${ROSS_LIBS}
tests_lp_io_test_LDFLAGS = ${ROSS_LDFLAGS}
tests_lp_io_test_SOURCES = tests/lp-io-test.c
tests_mapping_test_LDADD = $(testlib) ${ROSS_LIBS}
tests_mapping_test_LDFLAGS = ${ROSS_LDFLAGS}
tests_mapping_test_SOURCES = tests/mapping_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 = \
......
TEST1 2 a
TEST1 3 c
TEST1 7 b
TEST2 0 0 a
TEST2 1 0 b
TEST2 2 1 b
TEST2 3 1 a
TEST2 4 2 b
TEST2 5 3 b
TEST2 6 0 c
TEST2 7 4 b
TEST2 8 1 c
TEST2 9 5 b
TEST2 10 2 c
TEST2 11 6 b
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <ross.h>
#include "codes/configuration.h"
#include "codes/codes_mapping.h"
#include "codes/codes.h"
/* define three types of lps for mapping test */
typedef struct a_state_s{
int id;
} a_state;
typedef a_state b_state;
typedef a_state c_state;
static void a_init(a_state *ns, tw_lp *lp){
ns->id = codes_mapping_get_lp_global_rel_id(lp->gid);
}
static void b_init(b_state *ns, tw_lp *lp){ a_init(ns,lp); }
static void c_init(c_state *ns, tw_lp *lp){ a_init(ns,lp); }
static void a_finalize(a_state *ns, tw_lp *lp){
printf("TEST2 %lu %d a\n", lp->gid, ns->id);
}
static void b_finalize(b_state *ns, tw_lp *lp){
printf("TEST2 %lu %d b\n", lp->gid, ns->id);
}
static void c_finalize(c_state *ns, tw_lp *lp){
printf("TEST2 %lu %d c\n", lp->gid, ns->id);
}
tw_lptype a_lp = {
(init_f) a_init,
(event_f) NULL,
(revent_f) NULL,
(final_f) a_finalize,
(map_f) codes_mapping,
sizeof(a_state),
};
tw_lptype b_lp = {
(init_f) b_init,
(event_f) NULL,
(revent_f) NULL,
(final_f) b_finalize,
(map_f) codes_mapping,
sizeof(b_state),
};
tw_lptype c_lp = {
(init_f) c_init,
(event_f) NULL,
(revent_f) NULL,
(final_f) c_finalize,
(map_f) codes_mapping,
sizeof(c_state),
};
static char conf_file_name[128] = {'\0'};
static const tw_optdef app_opt [] =
{
TWOPT_GROUP("codes-mapping test case" ),
TWOPT_CHAR("codes-config", conf_file_name, "name of codes configuration file"),
TWOPT_END()
};
int main(int argc, char *argv[])
{
tw_opt_add(app_opt);
tw_init(&argc, &argv);
if (!conf_file_name[0]){
fprintf(stderr, "Expected \"codes-config\" option, please see --help.\n");
MPI_Finalize();
return 1;
}
if (configuration_load(conf_file_name, MPI_COMM_WORLD, &config)){
fprintf(stderr, "Error loading config file %s.\n", conf_file_name);
MPI_Finalize();
return 1;
}
lp_type_register("a", &a_lp);
lp_type_register("b", &b_lp);
lp_type_register("c", &c_lp);
codes_mapping_setup();
printf("TEST1 %d a\n", codes_mapping_get_global_lp_count("a"));
printf("TEST1 %d b\n", codes_mapping_get_global_lp_count("b"));
printf("TEST1 %d c\n", codes_mapping_get_global_lp_count("c"));
tw_run();
tw_end();
return 0;
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
*/
#!/bin/bash
tst=$srcdir/tests
set -e
tests/mapping_test --sync=1 --codes-config=$tst/conf/mapping_test.conf | \
grep TEST | sort -s -k 1d,1d -k 2n,2n > mapping_test.out
diff $tst/expected/mapping_test.out mapping_test.out
err=$?
if [ "$err" -eq 0 ]; then
rm mapping_test.out
fi
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